コード例 #1
0
  @Test
  public void startFragment_shouldPassSavedInstanceStateToOnCreateMethodOfFragment()
      throws Exception {
    shadowOf(fragment).setSavedInstanceState(new Bundle());
    manager.addFragment(CONTAINER_VIEW_ID, null, fragment, true);
    manager.startFragment(fragment);

    assertTrue(fragment.onActivityCreated_savedInstanceState != null);
  }
コード例 #2
0
  @Test
  public void getFragment_whenBundleSavedByShadowFragmentActivity_shouldGetFragmentByTagFromBundle()
      throws Exception {
    manager.addFragment(CONTAINER_VIEW_ID, "fragment tag", fragment, true);

    Bundle outState = new Bundle();
    shadowOf(activity).onSaveInstanceState(outState);

    Fragment retrievedFragment = manager.getFragment(outState, "fragment tag");
    assertEquals(TestFragment.class, retrievedFragment.getClass());
  }
コード例 #3
0
  @Test
  public void startFragment_shouldInsertTheFragmentViewIntoTheContainerView() throws Exception {
    manager.addFragment(CONTAINER_VIEW_ID, null, fragment, false);
    manager.startFragment(fragment);

    View fragmentViewParent =
        (View) activity.findViewById(TestFragment.FRAGMENT_VIEW_ID).getParent();
    assertThat(
        activity.findViewById(TestFragment.FRAGMENT_VIEW_ID),
        sameInstance(fragment.onCreateViewReturnValue));
    assertThat(fragmentViewParent, sameInstance((View) containerView));
  }
コード例 #4
0
  @Test
  public void startFragment_shouldCallLifecycleMethods() throws Exception {
    manager.addFragment(View.NO_ID, null, fragment, false);
    fragment.transcript.clear();
    manager.startFragment(fragment);

    fragment.transcript.assertEventsSoFar(
        "onCreateView", "onViewCreated", "onActivityCreated", "onStart");

    assertEquals(fragment.onCreateViewInflater, activity.getLayoutInflater());
    assertNotNull(fragment.getView());
  }
コード例 #5
0
 @Test
 public void addFragment_shouldPassTheSavedInstanceStateToOnCreate() throws Exception {
   Bundle bundle = new Bundle();
   shadowOf(fragment).setSavedInstanceState(bundle);
   manager.addFragment(0, null, fragment, false);
   assertSame(bundle, fragment.onCreateSavedInstanceState);
 }
コード例 #6
0
  @Test
  public void addFragment_shouldCallLifecycleMethods() throws Exception {
    manager.addFragment(View.NO_ID, null, fragment, false);

    fragment.transcript.assertEventsSoFar("onAttach", "onCreate");

    assertSame(activity, fragment.onAttachActivity);
    assertSame(activity, fragment.getActivity());
  }
コード例 #7
0
  @Test
  public void addFragmentWithReplace_shouldEmptyTheContainer() throws Exception {
    containerView.addView(new Button(activity));
    assertEquals(1, containerView.getChildCount());

    manager.addFragment(CONTAINER_VIEW_ID, null, fragment, true);

    assertEquals(1, containerView.getChildCount());
  }
コード例 #8
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));
 }
コード例 #9
0
  @Test
  public void getCommittedTransactions_shouldReturnListOfOnlyCommittedTransactions()
      throws Exception {
    assertTrue(manager.getCommittedTransactions().isEmpty());

    FragmentTransaction transaction = manager.beginTransaction();
    assertTrue(manager.getCommittedTransactions().isEmpty());

    transaction.add(new Fragment(), "tag");
    transaction.commit();
    assertEquals(1, manager.getCommittedTransactions().size());
    assertSame(transaction, manager.getCommittedTransactions().get(0));

    FragmentTransaction anotherTransaction = manager.beginTransaction();
    anotherTransaction.add(new Fragment(), "tag");
    anotherTransaction.commit();
    assertEquals(2, manager.getCommittedTransactions().size());
    assertSame(anotherTransaction, manager.getCommittedTransactions().get(1));
  }
コード例 #10
0
  @Test
  public void addFragment_shouldSetTheFragmentsTag() throws Exception {
    manager.addFragment(View.NO_ID, "expected tag", fragment, false);

    assertThat(fragment.getTag(), equalTo("expected tag"));
  }
コード例 #11
0
  @Test
  public void addFragment_shouldSetTheFragmentsView() throws Exception {
    manager.addFragment(View.NO_ID, null, fragment, false);

    assertThat(fragment.getView(), sameInstance(fragment.onCreateViewReturnValue));
  }
コード例 #12
0
  @Test
  public void shouldFindFragmentByTag() throws Exception {
    manager.addFragment(CONTAINER_VIEW_ID, "tag1", fragment, false);

    assertThat(manager.findFragmentByTag("tag1"), sameInstance((Fragment) fragment));
  }
コード例 #13
0
  @Test
  public void addFragment_shouldSetFragmentsActivity() throws Exception {
    manager.addFragment(0, null, fragment, false);

    assertSame(activity, fragment.getActivity());
  }
コード例 #14
0
 @Test
 public void addFragmentWithReplace_withNoContainer_shouldNotThrow() throws Exception {
   manager.addFragment(0, null, fragment, true);
   // pass
 }