org.robolectric.shadows.support.v4.SupportFragmentTestUtil Java Examples

The following examples show how to use org.robolectric.shadows.support.v4.SupportFragmentTestUtil. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DeviceListFragmentTest.java    From openwebnet-android with MIT License 6 votes vote down vote up
private void setupFragment(int environment) {
    List<EnvironmentModel> environments = Lists.newArrayList(
        newEnvironmentModel(123, "A-environment"),
        newEnvironmentModel(environment, "B-environment"),
        newEnvironmentModel(10, "C-environment"),
        newEnvironmentModel(789, "D-environment"));

    when(environmentService.findAll()).thenReturn(Observable.just(environments));

    DeviceListFragment fragment = new DeviceListFragment();
    Bundle args = new Bundle();
    args.putInt(ARG_ENVIRONMENT, environment);
    fragment.setArguments(args);
    SupportFragmentTestUtil.startFragment(fragment);
    assertNotNull("should not be null", fragment);
}
 
Example #2
Source File: MvvmDialogFragmentTest.java    From android-mvvm with Apache License 2.0 6 votes vote down vote up
@Test
public void testRemoveOnPropertyChangedCallbacksOnActivityDestroy() {
    final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
    final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
    fragment.setViewModel(fragment.createViewModel());
    fragment.addOnPropertyChangedCallback(firstCallback);
    fragment.addOnPropertyChangedCallback(secondCallback);

    SupportFragmentTestUtil.startFragment(fragment);
    fragment.onDestroy();
    verify(fragment.getViewModel()).removeOnPropertyChangedCallback(firstCallback);
    verify(fragment.getViewModel()).removeOnPropertyChangedCallback(secondCallback);
}
 
Example #3
Source File: CourseTabsDashboardFragmentTest.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Testing initialization
 */
@Test
public void initializeTest() {
    CourseTabsDashboardFragment fragment = CourseTabsDashboardFragment.newInstance(getCourseData(), "testsCourseId", Screen.COURSE_DASHBOARD);
    SupportFragmentTestUtil.startVisibleFragment(fragment, RoboFragmentActivity.class, android.R.id.content);
    View view = fragment.getView();
    assertNotNull(view);

    View viewPager = view.findViewById(R.id.viewPager);
    assertNotNull(viewPager);
    assertThat(viewPager).isInstanceOf(ViewPager.class);
}
 
Example #4
Source File: BaseCourseUnitVideoFragmentTest.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Testing orientation changes
 */
@Test
public void orientationChangeTest() {
    final BaseCourseUnitVideoFragment fragment = getCourseUnitPlayerFragmentInstance();
    SupportFragmentTestUtil.startVisibleFragment(fragment, FragmentUtilActivity.class, 1);
    assertNotEquals(Configuration.ORIENTATION_LANDSCAPE,
            fragment.getResources().getConfiguration().orientation);

    testOrientationChange(fragment, Configuration.ORIENTATION_LANDSCAPE);
    testOrientationChange(fragment, Configuration.ORIENTATION_PORTRAIT);
}
 
Example #5
Source File: BaseCourseUnitVideoFragmentTest.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Testing initialization
 */
@Test
public void initializeTest() {
    final BaseCourseUnitVideoFragment fragment = CourseUnitVideoPlayerFragment.newInstance(getVideoUnit(), false, false);
    SupportFragmentTestUtil.startVisibleFragment(fragment, FragmentUtilActivity.class, 1);
    assertTrue(fragment.getRetainInstance());

    final View view = fragment.getView();
    assertNotNull(view);
    final View messageContainer = view.findViewById(R.id.message_container);
    assertNotNull(messageContainer);
}
 
Example #6
Source File: PresenterFragmentTest.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
protected void startFragment(@NonNull final FragmentT fragment) {
    this.presenter = mock(getPresenterType());
    fragment.presenter = presenter;
    SupportFragmentTestUtil.startVisibleFragment(fragment, HostActivity.class, android.R.id.content);
    this.fragment = fragment;
    this.view = fragment.view;
}
 
Example #7
Source File: CourseUnitWebViewFragmentTest.java    From edx-app-android with Apache License 2.0 5 votes vote down vote up
/**
 * Testing initialization
 */
@Test
public void initializeTest() throws CourseContentNotValidException {
    CourseUnitWebViewFragment fragment = CourseUnitWebViewFragment.newInstance(getHtmlUnit());
    SupportFragmentTestUtil.startVisibleFragment(fragment, PreLoadingListenerActivity.class, android.R.id.content);
    View view = fragment.getView();
    assertNotNull(view);

    View courseUnitWebView = view.findViewById(R.id.webview);
    assertNotNull(courseUnitWebView);
    assertThat(courseUnitWebView).isInstanceOf(WebView.class);
    WebView webView = (WebView) courseUnitWebView;
    assertTrue(webView.getSettings().getJavaScriptEnabled());
}
 
Example #8
Source File: FragmentMvpDelegateUiLessMvpFragmentTest.java    From mosby with Apache License 2.0 5 votes vote down vote up
@Test() public void uiLessShouldFail() {
  try {
    SupportFragmentTestUtil.startVisibleFragment(new UiLessFragment());
    Assert.fail("Exception expected");
  } catch (IllegalStateException e) {
    Assert.assertEquals(
        "It seems that you are using "+UiLessFragment.class.getCanonicalName()+" as headless (UI less) fragment (because onViewCreated() has not been called or maybe delegation misses that part). Having a Presenter without a View (UI) doesn't make sense. Simply use an usual fragment instead of an MvpFragment if you want to use a UI less Fragment",
        e.getMessage());
  }
}
 
Example #9
Source File: MvvmDialogFragmentTest.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnSaveInstanceStateDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    final Bundle testBundle = new Bundle();
    fragment.onSaveInstanceState(testBundle);
    verify(fragment.getMvvmDelegate()).onSaveInstanceState(testBundle);
}
 
Example #10
Source File: MvvmFragmentTest.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@Test
public void testRemoveOnPropertyChangedCallbacksOnActivityDestroy() {
    final Observable.OnPropertyChangedCallback firstCallback = mock(Observable.OnPropertyChangedCallback.class);
    final Observable.OnPropertyChangedCallback secondCallback = mock(Observable.OnPropertyChangedCallback.class);
    fragment.setViewModel(fragment.createViewModel());
    fragment.addOnPropertyChangedCallback(firstCallback);
    fragment.addOnPropertyChangedCallback(secondCallback);

    SupportFragmentTestUtil.startFragment(fragment);
    fragment.onDestroy();
    verify(fragment.getViewModel()).removeOnPropertyChangedCallback(firstCallback);
    verify(fragment.getViewModel()).removeOnPropertyChangedCallback(secondCallback);
}
 
Example #11
Source File: MvvmFragmentTest.java    From android-mvvm with Apache License 2.0 5 votes vote down vote up
@Test
public void testOnSaveInstanceStateDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    final Bundle testBundle = new Bundle();
    fragment.onSaveInstanceState(testBundle);
    verify(fragment.getMvvmDelegate()).onSaveInstanceState(testBundle);
}
 
Example #12
Source File: MvvmDialogFragmentTest.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
@Test
public void testOnDestroyDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    fragment.onDestroy();
    verify(fragment.getMvvmDelegate()).onDestroy();
}
 
Example #13
Source File: MvvmDialogFragmentTest.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
@Test
public void testOnPauseDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    fragment.onPause();
    verify(fragment.getMvvmDelegate()).onPause();
}
 
Example #14
Source File: FragmentMvpDelegateUiLessMvpFragmentTest.java    From mosby with Apache License 2.0 4 votes vote down vote up
@Test public void correctUi() {
  SupportFragmentTestUtil.startVisibleFragment(new CorrectUiFragment());
}
 
Example #15
Source File: MvvmDialogFragmentTest.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
@Test
public void testStartMethodsDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    verify(fragment.getMvvmDelegate()).onCreate(null);
    verify(fragment.getMvvmDelegate()).onResume();
}
 
Example #16
Source File: MvvmFragmentTest.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
@Test
public void testOnDestroyDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    fragment.onDestroy();
    verify(fragment.getMvvmDelegate()).onDestroy();
}
 
Example #17
Source File: MvvmFragmentTest.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
@Test
public void testOnPauseDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    fragment.onPause();
    verify(fragment.getMvvmDelegate()).onPause();
}
 
Example #18
Source File: MvvmFragmentTest.java    From android-mvvm with Apache License 2.0 4 votes vote down vote up
@Test
public void testStartMethodsDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    verify(fragment.getMvvmDelegate()).onCreate(null);
    verify(fragment.getMvvmDelegate()).onResume();
}