@Test public void shouldCreateFragmentProxyWhenTestSubjectIsFragment() { when(testCase.getTestSubjectClassType()).thenReturn(RoboFragment.class); when(reflectionUtils.classIsOfAssignableForm(RoboFragment.class, RoboFragment.class)) .thenReturn(true); when(reflectionUtils.createObjectProxy(RoboFragment.class, testFieldInjector)) .thenReturn(fragment); testFieldInjector.setupTestCase(); verify(reflectionUtils).createObjectProxy(RoboFragment.class, testFieldInjector); }
@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 shouldUseFragmentTransactionToAddFragmentToDummyActivityIfSubjectIsAnFragment() { when(testCase.getTestSubjectClassType()).thenReturn(RoboFragment.class); when(reflectionUtils.classIsOfAssignableForm(RoboFragment.class, RoboFragment.class)) .thenReturn(true); when(reflectionUtils.createObjectProxy(RoboFragment.class, testFieldInjector)) .thenReturn(fragment); when(reflectionUtils.objectIsOfAnyType(fragment, RoboFragment.class)).thenReturn(true); testFieldInjector.setupTestCase(); TestFragmentManager fragmentManager = (TestFragmentManager) shadowOf((FragmentActivity) testFieldInjector.getCurrentContextForTest()) .getSupportFragmentManager(); assertThat(fragmentManager.getCommittedTransactions().size(), is(1)); assertThat( (RoboFragment) fragmentManager.getCommittedTransactions().get(0).getFragment(), is(fragment)); }