@Test public void shouldSetCallBack() { SimpleDialogFragment fragment = SimpleDialogFragment.newInstance( "title", "message", "btn_positive", "btn_negative", "onBackPressed"); SimpleDialogFragment.MsgDialogCallBack dialogCallBack = mock(SimpleDialogFragment.MsgDialogCallBack.class); fragment.setCallBackListener(dialogCallBack); FragmentTestUtil.startFragment(fragment); Dialog dialog = fragment.getDialog(); (((AlertDialog) dialog).getButton(AlertDialog.BUTTON_POSITIVE)).performClick(); verify(dialogCallBack).positiveClick(anyString()); }
private void testLifecycle(LifecycleProvider<FragmentEvent> provider) { Fragment fragment = (Fragment) provider; FragmentTestUtil.startFragment(fragment); TestObserver<FragmentEvent> testObserver = provider.lifecycle().skip(1).test(); fragment.onAttach(null); fragment.onCreate(null); fragment.onViewCreated(null, null); fragment.onStart(); fragment.onResume(); fragment.onPause(); fragment.onStop(); fragment.onDestroyView(); fragment.onDestroy(); fragment.onDetach(); testObserver.assertValues( FragmentEvent.ATTACH, FragmentEvent.CREATE, FragmentEvent.CREATE_VIEW, FragmentEvent.START, FragmentEvent.RESUME, FragmentEvent.PAUSE, FragmentEvent.STOP, FragmentEvent.DESTROY_VIEW, FragmentEvent.DESTROY, FragmentEvent.DETACH ); }
@Before public void setUp() throws Exception { mockStockCardPresenter = mock(StockCardPresenter.class); RoboGuice.overrideApplicationInjector(RuntimeEnvironment.application, new AbstractModule() { @Override protected void configure() { bind(StockCardPresenter.class).toInstance(mockStockCardPresenter); } }); fragment = new KitStockCardListFragment(); FragmentTestUtil.startFragment(fragment); }
@Before public void setUp() throws Exception { presenter = mock(SyncErrorsPresenter.class); RoboGuice.overrideApplicationInjector(RuntimeEnvironment.application, new AbstractModule() { @Override protected void configure() { bind(SyncErrorsPresenter.class).toInstance(presenter); } }); fragment = new SyncDateBottomSheet(); fragment.setArguments(SyncDateBottomSheet.getArgumentsToMe(1, 1)); FragmentTestUtil.startFragment(fragment); }
private void setupDialog() { when(utilityService.isBlankText(any(TextView.class))).thenCallRealMethod(); when(utilityService.sanitizedText(any(TextView.class))).thenCallRealMethod(); SettingsFragment settingsFragment = new SettingsFragment(); FragmentTestUtil.startVisibleFragment(settingsFragment); assertNotNull("fragment is null", settingsFragment); PreferenceScreen preferenceScreen = settingsFragment.getPreferenceScreen(); initGatewayEditTextPreference(preferenceScreen); // TODO //gatewayEditTextPreference.onClick(); assertTrue("should be visible", gatewayEditTextPreference.getDialog().isShowing()); }
private PreferenceFragment setUpPreferenceFragment(Class<? extends PreferenceFragment> clazz) { PreferenceFragment instance; try { instance = clazz.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e); } FragmentTestUtil.startVisibleFragment(instance); return instance; }
@Test public void showProgress_shouldDisableMap() throws Exception { FragmentTestUtil.startFragment(mapFragment); mapFragment.getView().findViewById(R.id.map).setClickable(true); mapFragment.showProgress(); assertThat(mapFragment.getView().findViewById(R.id.map)).isNotClickable(); }
@Test public void hideProgress_shouldHideProgressView() throws Exception { FragmentTestUtil.startFragment(mapFragment); mapFragment.showProgress(); mapFragment.hideProgress(); assertThat(mapFragment.getView().findViewById(R.id.progress)).isNotVisible(); }
@Test public void hideProgress_shouldEnableMap() throws Exception { FragmentTestUtil.startFragment(mapFragment); mapFragment.getView().findViewById(R.id.map).setClickable(false); mapFragment.hideProgress(); assertThat(mapFragment.getView().findViewById(R.id.map)).isClickable(); }
@Test public void findMe_shouldNotResetZoomAndPointNorthAfterMapPositionEvent() throws Exception { FragmentTestUtil.startFragment(mapFragment); mapFragment.findMe(); MapPosition mapPosition = new MapPosition(); mapPosition.setZoomLevel(10); activity.getMap().events.fire(Map.POSITION_EVENT, mapPosition); mapFragment.findMe(); assertThat(mapFragment.mapController.getZoomLevel()).isEqualTo(10); }
private TestFragment startFragment() { TestFragment testFragment = new TestFragment(); FragmentTestUtil.startFragment(testFragment, FakeActivity.class); return testFragment; }
@Test public void showProgress_shouldShowProgressView() throws Exception { FragmentTestUtil.startFragment(mapFragment); mapFragment.showProgress(); assertThat(mapFragment.getView().findViewById(R.id.progress)).isVisible(); }
@Test public void onActivityCreated_shouldDoStylesheetDownload() throws Exception { FragmentTestUtil.startFragment(mapFragment); Mockito.verify(styleDownLoader).download(); }
private void loadAceHotelMockRoute() { fragment.success(new Route(MOCK_ACE_HOTEL)); FragmentTestUtil.startFragment(fragment); fragment.onResume(); }