Is anyone able to take a look at my question from ...
# koin
b
Is anyone able to take a look at my question from dec 18th? I'm really stuck on what to do, and can't get feedback anywhere? I'm left thinking I'm either doing something wrong, or it's not possible to verify mocks not passed in through the constructor?
n
Try moving your
declareMock
to the top of the test method, to ensure that the mocked instance is prepared before any other method requests the type.
b
That doesn't seem to work either. I added this to the file
Copy code
lateinit var someMock: DirectorySavedFilterBinder
And initialized the mock immediately after initializing Koin in @Before
Copy code
startKoin {
            modules(rowBindingsModule)
        }

        someMock = declareMock<DirectorySavedFilterBinder>()
Then the verify at the bottom of my test still failed
Copy code
verify(someMock).bind(any())
n
Shouldn't this line:
Copy code
whenever(rowsToDisplay[1]).thenReturn(row)
Be included within the
declareMock
call? As in
whenever(rowsToDisplay.get(eq(1)).thenReturn(row)
b
rowsToDisplay is passed in through the constructor and isn't part of Koin
n
Hmm. I've never used the
verify
method so I'm a bit out of my league here. I'll keep looking to see if I notice anything
b
Thanks, much appreciated. Verify is part of mockito, but my understanding is the two play nice together. The best documentation I've found so far is this https://github.com/InsertKoinIO/koin/issues/298 But I'm not sure if that's still up to date... you can see they verify on the heater in there though. I actually missed that they have the initializing up top with the by inject() so I just tried that in the test as well and it didn't work either...
The difference is though that that coffee maker is made within the test, and it takes a heater. My binder is created within the method... so it's not quite the same
For example, this test does pass
Copy code
@Test
fun `binder binds`() {
    someMock.bind(mock())

    verify(someMock).bind(any())
}
Which is why I'm so confused since my "working" code that is a workaround with the given/true part, works... so it seems like it should all work somehow