@Test public void shouldInjectActivityIntoTestCaseMarkedAsSubject() throws NoSuchFieldException, IllegalAccessException { when(testCase.getTestSubjectClassType()).thenReturn(Activity.class); when(testCase.getTestSubjectField()).thenReturn(getSampleField()); when(testCase.getTestCaseInstance()).thenReturn(testCaseInstance); when(injector.getInstance(Activity.class)).thenReturn(activity); testFieldInjector.setupTestCase(); verify(reflectionUtils).forceSetValueOnField(getSampleField(), testCaseInstance, activity); }
@Test public void shouldInjectFragmentIntoTestCaseMarkedAsSubject() throws NoSuchFieldException, IllegalAccessException { when(testCase.getTestSubjectClassType()).thenReturn(RoboFragment.class); when(testCase.getTestSubjectField()).thenReturn(getSampleField()); when(testCase.getTestCaseInstance()).thenReturn(testCaseInstance); when(reflectionUtils.classIsOfAssignableForm(RoboFragment.class, RoboFragment.class)) .thenReturn(true); when(reflectionUtils.createObjectProxy(RoboFragment.class, testFieldInjector)) .thenReturn(fragment); testFieldInjector.setupTestCase(); verify(reflectionUtils).forceSetValueOnField(getSampleField(), testCaseInstance, fragment); }
@Test public void shouldSetMocksIntoTestCase() throws NoSuchFieldException, IllegalAccessException { Object mockOne = mock(Object.class); Object mockTwo = mock(Object.class); when(testCase.getTestCaseInstance()).thenReturn(testCaseInstance); when(testCase.getFieldsMarkedWithMock()) .thenReturn(Lists.newArrayList(getSampleField(), getSecondSampleField())); when(injector.getInstance(getSampleField().getType())).thenReturn(mockOne); when(injector.getInstance(getSecondSampleField().getType())).thenReturn(mockTwo); testFieldInjector.setupTestCase(); verify(reflectionUtils).forceSetValueOnField(getSampleField(), testCaseInstance, mockOne); verify(reflectionUtils).forceSetValueOnField(getSecondSampleField(), testCaseInstance, mockTwo); }