I have a data that I want to mock out that takes val arguments in the constructor.
class DeviceProxy(val context: Context, val name: String) {
...
}
Parts of my code check the name to make sure it's what is expected but I can't figure out how to pass a name in when I create the mock and I can't figure out how to mock access to the name property.
I tried:
deviceMock = mock(DeviceProxy::class.java)
whenever(deviceMock.name).thenReturn(TEST_DEVICE_NAME)
but that gives me this error:
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
So then I started looking into mockConstructor
but I don't know if what I was finding is old or what but none of the examples I saw compiled for me.
I would be happy doing it either way if someone could walk me through making one of these approaches work.