コード例 #1
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);
 }
コード例 #2
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());
  }
コード例 #3
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);
  }
コード例 #4
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());
  }
コード例 #5
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());
  }
コード例 #6
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));
  }
コード例 #7
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());
  }
コード例 #8
0
  @Test
  public void addFragment_shouldSetTheFragmentsTag() throws Exception {
    manager.addFragment(View.NO_ID, "expected tag", fragment, false);

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

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

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

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