Hi, I'm having troubles using Koin to do some uni...
# koin
b
Hi, I'm having troubles using Koin to do some unit tests. I'm on Koin 2.0.1. I've encountered this same problem a couple of times now and just not sure what I'm doing wrong? I tried asking on stack but never got an answer. I want to unit test that this Bind method was called (there are some parameters passed in normally, but for simplicity I removed them as they aren't relevant)
Copy code
override fun bindItemRow(position: Int, viewRow: DisplayableListRecyclerContract.Content) {
        val binder = get<DirectoryListContentBinder>() 
        binder.bind(rowsToDisplay[position])
 }
I want to write a test like this
Copy code
@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
Copy code
@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?