Java 类org.robolectric.shadows.support.v4.SupportFragmentTestUtil 实例源码

项目:materialistic    文件:ItemFragmentSinglePageTest.java   
@Test
public void testPendingItem() {
    Bundle args = new Bundle();
    args.putParcelable(ItemFragment.EXTRA_ITEM, new TestItem() {
        @Override
        public Item[] getKidItems() {
            return new Item[]{new TestItem() {
                @Override
                public int getLocalRevision() {
                    return -1;
                }
            }};
        }

        @Override
        public int getKidCount() {
            return 1;
        }
    });
    Fragment fragment = Fragment.instantiate(RuntimeEnvironment.application,
            ItemFragment.class.getName(), args);
    SupportFragmentTestUtil.startVisibleFragment(fragment, ItemFragmentMultiPageTest.TestItemActivity.class,
            R.id.content_frame);
    recyclerView = (RecyclerView) fragment.getView().findViewById(R.id.recycler_view);
    adapter = (SinglePageItemRecyclerViewAdapter) recyclerView.getAdapter();
}
项目:AluShare    文件:ChatTabPresenterTest.java   
@Before
public void setUp() throws Exception {
    DummyDataSet.copyDataSet("ASDB_Tabs.db");
    helper = new SQLChatHelper(context);
    cHelper = new SQLContactHelper(context);
    fragment = ChatTabFragment.createInstance();
    SupportFragmentTestUtil.startFragment(fragment);
    adapter = new ChatTabRecyclerAdapter(fragment);
    presenter = new ChatTabPresenter(fragment, adapter);



    Contact c1 = new Contact("kontakt1");
    Contact c2 = new Contact("kontakt2");
    List<Contact> cList = new ArrayList<>();
    cList.add(c1);
    cList.add(c2);
    Chat chat = new Chat("TestChat", "1", cList);
    helper.insert(chat);
}
项目:openwebnet-android    文件:DeviceListFragmentTest.java   
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);
}
项目:edx-app-android    文件:NavigationFragmentTest.java   
@Test
public void testProfileImageUpdation_onGlobalAccountEvent() {
    final NavigationFragment fragment = new NavigationFragment();
    SupportFragmentTestUtil.startVisibleFragment(fragment);
    final View view = fragment.getView();
    assertNotNull(view);

    final ImageView profileImage = (ImageView) view.findViewById(R.id.profile_image);
    assertNotNull(profileImage);

    // Assert: Profile pic not updated when a non-logged in user's account object is broadcasted
    Drawable previousDrawable = profileImage.getDrawable();
    Account account = configureMockAccount("not_logged_in_user");
    EventBus.getDefault().post(new AccountDataLoadedEvent(account));
    assertEquals(previousDrawable, profileImage.getDrawable());

    // Assert: Profile pic is updated when a logged-in user's account object is broadcasted
    UserPrefs userPrefs = RoboGuice.getInjector(context).getInstance(UserPrefs.class);
    final String loggedInUser = userPrefs.getProfile().username;
    account = configureMockAccount(loggedInUser);
    EventBus.getDefault().post(new AccountDataLoadedEvent(account));
    assertNotEquals(previousDrawable, profileImage.getDrawable());
}
项目:GitHub    文件:FragmentMvpDelegateUiLessMvpFragmentTest.java   
@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());
  }
}
项目:GitHub    文件:FragmentMvpDelegateUiLessMvpFragmentTest.java   
@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());
  }
}
项目:sample-code-posts    文件:PostsFragmentTest.java   
private void setUpFragment() {
    postsFragment = new PostsFragment();
    SupportFragmentTestUtil.startFragment(postsFragment);
    postsFragment.setPresenter(postsPresenterMock);
    postsFragment.postsRecyclerView = postsRecyclerViewMock;
    postsFragment.postRecyclerViewAdapter = postRecyclerViewAdapterMock;
    postsFragment.progressDialog = progressDialogMock;
}
项目:android-mvvm    文件:MvvmFragmentTest.java   
@Test
public void testOnSaveInstanceStateDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    final Bundle testBundle = new Bundle();
    fragment.onSaveInstanceState(testBundle);
    verify(fragment.getMvvmDelegate()).onSaveInstanceState(testBundle);
}
项目:android-mvvm    文件:MvvmFragmentTest.java   
@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);
}
项目:android-mvvm    文件:MvvmDialogFragmentTest.java   
@Test
public void testOnSaveInstanceStateDelegated() {
    SupportFragmentTestUtil.startFragment(fragment);
    final Bundle testBundle = new Bundle();
    fragment.onSaveInstanceState(testBundle);
    verify(fragment.getMvvmDelegate()).onSaveInstanceState(testBundle);
}
项目:android-mvvm    文件:MvvmDialogFragmentTest.java   
@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);
}
项目:AoDispor-Android    文件:CardFragmentTest.java   
@Test
public void testSwipeCardOrder3() {

    CardFragmentTestClass fragment = new CardFragmentTestClass();
    SupportFragmentTestUtil.startFragment(fragment, EmptyActivity.class);

    ArrayList<Professional> test_data_set = new ArrayList<Professional>(128);
    for (int i = 0; i < 128; ++i)
        test_data_set.add(ProfessionalTestClass.testProfessional("" + Integer.toString(i), "" + Integer.toString(i)));
    fragment.setTestData(test_data_set, CardFragmentTestClass.Test.mix);
    //SearchQueryResult cardSet;
    //    cardSet = fragment.getCurrentSet();

    ShadowLog.stream = System.out;
    ShadowLog.i("", "\n- - - - - - - - - - - - - - - - - - - - - - - - -\n");

    iterator = 50;

    ShadowLog.i("testSwipeCardOrder3", "forward and backward iterations inside same set");
    assert1ForwardIteration(fragment, test_data_set);
    assert1ForwardIteration(fragment, test_data_set);
    assert1BackwardIteration(fragment, test_data_set);
    assert1ForwardIteration(fragment, test_data_set);
    assert1ForwardIteration(fragment, test_data_set);
    assert1ForwardIteration(fragment, test_data_set);
    assert1BackwardIteration(fragment, test_data_set);
    assert1BackwardIteration(fragment, test_data_set);

    ShadowLog.i("testSwipeCardOrder3", "forward and backward iterations alternating sets");
    //iterator=52
    for (int i = 0; i < 30; ++i) assert1ForwardIteration(fragment, test_data_set);
    for (int i = 0; i < 30; ++i) assert1BackwardIteration(fragment, test_data_set);
    for (int i = 0; i < 30; ++i) assert1ForwardIteration(fragment, test_data_set);
    for (int i = 0; i < 30; ++i) assert1BackwardIteration(fragment, test_data_set);

}
项目:mosby    文件:FragmentMvpDelegateUiLessMvpFragmentTest.java   
@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());
  }
}
项目:AluShare    文件:ContactTabAdapterViewholderTest.java   
@Before
public void setUp() {
    DummyDataSet.copyDataSet("ASDB_Tabs.db");
    chatHelper = HelperFactory.getChatHelper(context);
    contactHelper = HelperFactory.getContacHelper(context);
    contacts = contactHelper.getContacts();

    fragment = TestFragment.createInstance(TestFragment.TYPE_CONTACT_TAB);
    SupportFragmentTestUtil.startVisibleFragment(fragment);
    adapter = (ContactTabRecyclerAdapter) fragment.getAdapter();
    manager = fragment.getLayoutManager();
    recyclerView = fragment.getRecyclerView();
}
项目:AluShare    文件:FileTabAdapterViewholderTest.java   
@Before
public void setUp() throws Exception {
    DummyDataSet.copyDataSet("ASDB_Tabs.db");
    helper = HelperFactory.getFileHelper(context);
    files = helper.getFiles();

    fragment = TestFragment.createInstance(TestFragment.TYPE_FILE_TAB);
    SupportFragmentTestUtil.startVisibleFragment(fragment);

    adapter = (FileTabRecyclerAdapter) fragment.getAdapter();
    manager = fragment.getLayoutManager();
    recyclerView = fragment.getRecyclerView();


}
项目:AluShare    文件:ChatTabAdapterViewholderTest.java   
@Before
public void setUp() {
    DummyDataSet.copyDataSet("ASDB_Tabs.db");
    contactHelper = HelperFactory.getContacHelper(context);
    chatHelper = HelperFactory.getChatHelper(context);
    dataHelper = HelperFactory.getDataHelper(context);
    chats = chatHelper.getChats();

    fragment = TestFragment.createInstance(TestFragment.TYPE_CHAT_TAB);
    SupportFragmentTestUtil.startVisibleFragment(fragment);

    adapter = (ChatTabRecyclerAdapter) fragment.getAdapter();
    manager = fragment.getLayoutManager();
    recyclerView = fragment.getRecyclerView();
}
项目:AluShare    文件:ContactTabPresenterTest.java   
@Before
public void setUp() throws Exception {
    DummyDataSet.copyDataSet("ASDB_Tabs.db");
    fragment = ContactTabFragment.createInstance();
    SupportFragmentTestUtil.startFragment(fragment);
    adapter = new ContactTabRecyclerAdapter(fragment);
    presenter = new ContactTabPresenter(fragment, adapter);

    contactHelper = HelperFactory.getContacHelper(context);
    chatHelper = HelperFactory.getChatHelper(context);
}
项目:AluShare    文件:FileTabPresenterTest.java   
@Before
public void setUp() throws Exception {
    DummyDataSet.copyDataSet("ASDB_Tabs.db");
    ShadowLog.stream = System.out;
    fileHelper = new SQLFileHelper(context);
    chatHelper = new SQLChatHelper(context);
    dataHelper = new SQLDataHelper(context);
    fragment = FileTabFragment.createInstance();
    SupportFragmentTestUtil.startFragment(fragment);
    adapter = new FileTabRecyclerAdapter(fragment);
    presenter = new FileTabPresenter(fragment, adapter);


}
项目:CCDroid    文件:ProjectListFragmentRoboTest.java   
@Test public void updateProjects_SetsAdapter() throws Exception {
    fragment = ProjectListFragment.newInstance();
    SupportFragmentTestUtil.startFragment(fragment);

    fragment.updateProjects(getProjects());

    //assertThat(fragment.recyclerView).hasAdapter();
    RecyclerView.Adapter adapter = fragment.recyclerView.getAdapter();
    assertThat(adapter).isNotNull();
    assertThat(adapter.getItemCount()).isEqualTo(2);
}
项目:edx-app-android    文件:CourseUnitWebViewFragmentTest.java   
/**
 * Testing initialization
 */
@Test
public void initializeTest() {
    CourseUnitWebViewFragment fragment = CourseUnitWebViewFragment.newInstance(getHtmlUnit());
    SupportFragmentTestUtil.startVisibleFragment(fragment);
    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());
}
项目:edx-app-android    文件:CourseUnitVideoFragmentTest.java   
/**
 * Testing initialization
 */
@Test
public void initializeTest() {
    CourseUnitVideoFragment fragment = CourseUnitVideoFragment.newInstance(getVideoUnit(), false, false);
    SupportFragmentTestUtil.startVisibleFragment(fragment, FragmentUtilActivity.class, 1);
    assertTrue(fragment.getRetainInstance());

    View view = fragment.getView();
    assertNotNull(view);
    View messageContainer = view.findViewById(R.id.message_container);
    assertNotNull(messageContainer);
}
项目:edx-app-android    文件:CourseUnitVideoFragmentTest.java   
/**
 * Testing orientation changes
 */
@Test
public void orientationChangeTest() {
    CourseUnitVideoFragment fragment = CourseUnitVideoFragment.newInstance(getVideoUnit(), false, false);
    SupportFragmentTestUtil.startVisibleFragment(fragment, FragmentUtilActivity.class, 1);
    assertNotEquals(Configuration.ORIENTATION_LANDSCAPE,
            fragment.getResources().getConfiguration().orientation);

    testOrientationChange(fragment, Configuration.ORIENTATION_LANDSCAPE);
    testOrientationChange(fragment, Configuration.ORIENTATION_PORTRAIT);
}
项目:edx-app-android    文件:PresenterFragmentTest.java   
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;
}
项目:WiFiAnalyzer    文件:ChannelGraphFragmentTest.java   
@Test
public void testOnCreateView() throws Exception {
    // execute
    SupportFragmentTestUtil.startFragment(fixture);
    // validate
    assertNotNull(fixture);
    verify(scanner).update();
    verify(scanner).register(fixture.getChannelGraphAdapter());
}
项目:WiFiAnalyzer    文件:ChannelGraphFragmentTest.java   
@Test
public void testOnResume() throws Exception {
    // setup
    SupportFragmentTestUtil.startFragment(fixture);
    // execute
    fixture.onResume();
    // validate
    verify(scanner, times(2)).update();
}
项目:WiFiAnalyzer    文件:ChannelGraphFragmentTest.java   
@Test
public void testOnDestroy() throws Exception {
    // setup
    SupportFragmentTestUtil.startFragment(fixture);
    // execute
    fixture.onDestroy();
    // validate
    verify(scanner).unregister(fixture.getChannelGraphAdapter());
}
项目:WiFiAnalyzer    文件:ChannelRatingFragmentTest.java   
@Test
public void testOnCreateView() throws Exception {
    // execute
    SupportFragmentTestUtil.startFragment(fixture);
    // validate
    assertNotNull(fixture);
    verify(scanner).update();
    verify(scanner).register(fixture.getChannelRatingAdapter());
}
项目:WiFiAnalyzer    文件:ChannelRatingFragmentTest.java   
@Test
public void testOnResume() throws Exception {
    // setup
    SupportFragmentTestUtil.startFragment(fixture);
    // execute
    fixture.onResume();
    // validate
    verify(scanner, times(2)).update();
}
项目:WiFiAnalyzer    文件:ChannelRatingFragmentTest.java   
@Test
public void testOnDestroy() throws Exception {
    // setup
    SupportFragmentTestUtil.startFragment(fixture);
    // execute
    fixture.onDestroy();
    // validate
    verify(scanner).unregister(fixture.getChannelRatingAdapter());
}
项目:WiFiAnalyzer    文件:AccessPointsFragmentTest.java   
@Test
public void testOnCreateView() throws Exception {
    // execute
    SupportFragmentTestUtil.startFragment(fixture);
    // validate
    assertNotNull(fixture);
    verify(scanner).update();
    verify(scanner).register(fixture.getAccessPointsAdapter());
}
项目:WiFiAnalyzer    文件:AccessPointsFragmentTest.java   
@Test
public void testOnResume() throws Exception {
    // setup
    SupportFragmentTestUtil.startFragment(fixture);
    // execute
    fixture.onResume();
    // validate
    verify(scanner, times(2)).update();
}
项目:WiFiAnalyzer    文件:AccessPointsFragmentTest.java   
@Test
public void testOnDestroy() throws Exception {
    // setup
    SupportFragmentTestUtil.startFragment(fixture);
    // execute
    fixture.onDestroy();
    // validate
    verify(scanner).unregister(fixture.getAccessPointsAdapter());
}
项目:WiFiAnalyzer    文件:TimeGraphFragmentTest.java   
@Test
public void testOnCreateView() throws Exception {
    // execute
    SupportFragmentTestUtil.startFragment(fixture);
    // validate
    assertNotNull(fixture);
    verify(scanner).update();
    verify(scanner).register(fixture.getTimeGraphAdapter());
}
项目:WiFiAnalyzer    文件:TimeGraphFragmentTest.java   
@Test
public void testOnResume() throws Exception {
    // setup
    SupportFragmentTestUtil.startFragment(fixture);
    // execute
    fixture.onResume();
    // validate
    verify(scanner, times(2)).update();
}
项目:WiFiAnalyzer    文件:TimeGraphFragmentTest.java   
@Test
public void testOnDestroy() throws Exception {
    // setup
    SupportFragmentTestUtil.startFragment(fixture);
    // execute
    fixture.onDestroy();
    // validate
    verify(scanner).unregister(fixture.getTimeGraphAdapter());
}
项目:WiFiAnalyzer    文件:ChannelAvailableFragmentTest.java   
@Test
public void testOnCreateView() throws Exception {
    // execute
    SupportFragmentTestUtil.startFragment(fixture);
    // validate
    assertNotNull(fixture);
}
项目:WiFiAnalyzer    文件:VendorFragmentTest.java   
@Test
public void testOnCreateView() throws Exception {
    // setup
    when(vendorService.findVendors()).thenReturn(Collections.<String>emptyList());
    // execute
    SupportFragmentTestUtil.startFragment(fixture);
    // validate
    assertNotNull(fixture);
    verify(vendorService).findVendors();
}
项目:GitHub    文件:FragmentMvpDelegateUiLessMvpFragmentTest.java   
@Test public void correctUi() {
  SupportFragmentTestUtil.startVisibleFragment(new CorrectUiFragment());
}
项目:GitHub    文件:FragmentMvpDelegateUiLessMvpFragmentTest.java   
@Test public void correctUi() {
  SupportFragmentTestUtil.startVisibleFragment(new CorrectUiFragment());
}
项目:device-info    文件:ScreenInfoFragmentUnitTest.java   
@Before
public void setUp() throws Exception {
    mFragment = new ScreenInfoFragmentForTest();
    SupportFragmentTestUtil.startFragment(mFragment);
    mFragment.mComponent.inject(this);
}