コード例 #1
0
 @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);
 }
コード例 #2
0
 @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);
 }
コード例 #3
0
 @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));
 }
コード例 #4
0
 @Test
 public void shouldNotListenToContentChangesIfTestSubjectIsNotAnActivity() {
   Date testSubject = new Date();
   when(testCase.getTestSubjectClassType()).thenReturn(Date.class);
   when(injector.getInstance(Date.class)).thenReturn(testSubject);
   when(reflectionUtils.objectIsOfAnyType(testSubject, Activity.class)).thenReturn(false);
   testFieldInjector.setupTestCase();
   verify(injector, never()).getInstance(EventManager.class);
 }
コード例 #5
0
 @Test
 public void shouldListenToContentChangesIfTestSubjectIsAnActivity() {
   when(testCase.getTestSubjectClassType()).thenReturn(RoboActivity.class);
   when(injector.getInstance(RoboActivity.class)).thenReturn(activity);
   when(reflectionUtils.objectIsOfAnyType(activity, RoboActivity.class)).thenReturn(true);
   testFieldInjector.setupTestCase();
   verify(injector).getInstance(EventManager.class);
   verify(eventManager)
       .registerObserver(eq(OnContentChangedEvent.class), isA(ContentChangedListener.class));
 }
コード例 #6
0
  @Test
  public void shouldEnterIntoTestSubjectContextIfTestSubjectIsAContext() {
    when(testCase.getTestSubjectClassType()).thenReturn(Activity.class);
    when(injector.getInstance(Activity.class)).thenReturn(activity);
    when(reflectionUtils.objectIsOfAnyType(activity, Context.class)).thenReturn(true);
    when(roboUtils.getInjector(activity)).thenReturn(injector);

    testFieldInjector.setupTestCase();
    verify(roboUtils).enterContext(activity);
  }
コード例 #7
0
  @Test
  public void shouldGetTheInjectorForTheCurrentContextOnlyAfterEnteringCurrentContext() {
    when(testCase.getTestSubjectClassType()).thenReturn(Activity.class);
    when(injector.getInstance(Activity.class)).thenReturn(activity);
    when(reflectionUtils.objectIsOfAnyType(activity, Context.class)).thenReturn(true);
    when(roboUtils.getInjector(activity)).thenReturn(injector);

    testFieldInjector.setupTestCase();
    InOrder inOrder = inOrder(roboUtils);
    inOrder.verify(roboUtils).enterContext(activity);
    inOrder.verify(roboUtils).getInjector(activity);
  }
コード例 #8
0
 @Test
 public void shouldEnterIntoDummyContextIfTestSubjectIsNotAContext() {
   when(reflectionUtils.objectIsOfAnyType(any(), eq(Context.class))).thenReturn(false);
   testFieldInjector.setupTestCase();
   verify(roboUtils, times(2)).enterContext(any(FragmentActivity.class));
 }