Java Code Examples for org.robolectric.shadows.support.v4.SupportFragmentTestUtil#startVisibleFragment()

The following examples show how to use org.robolectric.shadows.support.v4.SupportFragmentTestUtil#startVisibleFragment() . 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: 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 2
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 3
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 4
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 5
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 6
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 7
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());
}