Mockito creates a proxy instance when some thing is spied on. Now, is there any way to forward setters that are then executed on that proxy instance to the real instance tha
android Test Support library's SingleActivityFactory, ActivityTestRule and Mockito's spy()
dependencies {
androidTestImplementation 'com.android.support.test:runner:1.0.2'
androidTestImplementation 'com.android.support.test:rules:1.0.2'
androidTestImplementation 'org.mockito:mockito-android:2.21.0'
}
inject the spied instance inside SingleActivityFactory's implementation
public class MainActivityTest {
MainActivity subject;
SingleActivityFactory activityFactory = new SingleActivityFactory(MainActivity.class) {
@Override
protected MainActivity create(Intent intent) {
subject = spy(getActivityClassToIntercept());
return subject;
}
};
@Rule
public ActivityTestRule testRule = new ActivityTestRule<>(activityFactory, true, true);
@Test
public void activity_isBeingSpied() {
verify(subject).setContentView(R.layout.activity_main);
}
}