I have a situation where I need to test one object which is created inside public method and I don't have access to it so I am trying to use ArgumentCaptor. The problem is I'm always getting null.
Here is my code so it would be maybe more visible what I'm doing wrong:
class ActivityStarterClass(val c: Context) {
public void startActivity() {
val intent = createSomeIntent()
c.startActivity(intent)
}
}
class ActivityStarterClassTest() {
val c = mock<Context>()
@Test
fun testActivityStart() {
val activityStarter = ActivityStarterClass(c)
argumentCaptor<Intent>().apply {
verify(context).startActivity(capture())
System.out.println("captured intent: " + firstValue)
}
}
}