Ben Abramovitch
12/18/2019, 6:30 PMoverride fun bindItemRow(position: Int, viewRow: DisplayableListRecyclerContract.Content) {
val binder = get<DirectoryListContentBinder>()
binder.bind(rowsToDisplay[position])
}
I want to write a test like this
@Test
fun `bindItemRow for content calls Binder bind the row data from position 1`() {
val savedFilter: SavedFilter = mock()
val row = DisplayableRowType.SavedFilters(savedFilter)
whenever(rowsToDisplay[1]).thenReturn(row)
val viewRow: DisplayableListRecyclerContract.SavedFiltersContent = mock()
val binder = declareMock<DirectorySavedFilterBinder>()
presenter.bindItemRow(1, viewRow)
verify(binder).bind(row)
}
But when I do this, it says the bind method was never called on my mock.
However, when I write a test like this, it works
@Test
fun `bindItemRow for content calls Binder bind the row data from position 1`() {
var didBind = false
val savedFilter: SavedFilter = mock()
val row = DisplayableRowType.SavedFilters(savedFilter)
whenever(rowsToDisplay[1]).thenReturn(row)
val viewRow: DisplayableListRecyclerContract.SavedFiltersContent = mock()
declareMock<DirectorySavedFilterBinder> {
given(bind(row)).will {
didBind = true
true
}
}
presenter.bindItemRow(1, viewRow)
assert(didBind)
}
So I know my mock is working since the given method is triggering properly, I just can't figure out how to test it properly?
I've tried sifting through the documentation and github but haven't been able to figure it out. I feel like I'm missing something really simple but not obvious?