org.robolectric.Robolectric Java Examples
The following examples show how to use
org.robolectric.Robolectric.
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: RedirectUriReceiverActivityTest.java From AppAuth-Android with Apache License 2.0 | 6 votes |
@Test public void testForwardsRedirectToManagementActivity() { Uri redirectUri = Uri.parse("https://www.example.com/oauth2redirect"); Intent redirectIntent = new Intent(); redirectIntent.setData(redirectUri); ActivityController redirectController = Robolectric.buildActivity(RedirectUriReceiverActivity.class, redirectIntent) .create(); RedirectUriReceiverActivity redirectActivity = (RedirectUriReceiverActivity) redirectController.get(); Intent nextIntent = shadowOf(redirectActivity).getNextStartedActivity(); assertThat(nextIntent).hasData(redirectUri); assertThat(redirectActivity).isFinishing(); }
Example #2
Source File: SiberiUnitTest.java From siberi-android with MIT License | 6 votes |
@Test public void testClearExperimentTest() throws InterruptedException, JSONException { siberiStorage.insert("test_001_change_button_color", 2, createMetaData()); final ExperimentContent result = new ExperimentContent("test"); Siberi.clearExperimentContent(); Thread.sleep(500); //wait for clear content task to end Siberi.ExperimentRunner runner = new Siberi.ExperimentRunner() { @Override public void run(ExperimentContent content) { result.setTestName(content.testName); result.setVariant(content.variant); result.setMetaData(content.metaData); } }; Siberi.runTest("test_001_change_button_color", runner); Thread.sleep(500); //wait for run test action to be finished Robolectric.flushForegroundThreadScheduler(); Thread.sleep(500); //wait for applying test result assertThat(result.getTestName(),is("test_001_change_button_color")); assertFalse(result.containsVariant()); }
Example #3
Source File: PrebidServerAdapterTest.java From prebid-mobile-android with Apache License 2.0 | 6 votes |
@Test public void testUpdateTimeoutMillis() { PrebidMobile.setPrebidServerHost(Host.APPNEXUS); assertEquals(2000, PrebidMobile.getTimeoutMillis()); assertFalse(PrebidMobile.timeoutMillisUpdated); PrebidMobile.setPrebidServerAccountId("b7adad2c-e042-4126-8ca1-b3caac7d3e5c"); PrebidMobile.setShareGeoLocation(true); PrebidMobile.setApplicationContext(activity.getApplicationContext()); DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class); PrebidServerAdapter adapter = new PrebidServerAdapter(); HashSet<AdSize> sizes = new HashSet<>(); sizes.add(new AdSize(300, 250)); RequestParams requestParams = new RequestParams("e2edc23f-0b3b-4203-81b5-7cc97132f418", AdType.BANNER, sizes); String uuid = UUID.randomUUID().toString(); adapter.requestDemand(requestParams, mockListener, uuid); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); verify(mockListener).onDemandFailed(ResultCode.NO_BIDS, uuid); assertTrue("Actual Prebid Mobile timeout is " + PrebidMobile.getTimeoutMillis(), PrebidMobile.getTimeoutMillis() <= 2000 && PrebidMobile.getTimeoutMillis() > 700); assertTrue(PrebidMobile.timeoutMillisUpdated); }
Example #4
Source File: ThreadPreviewActivityTest.java From materialistic with Apache License 2.0 | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); TestApplication.applicationGraph.inject(this); reset(itemManager); reset(keyDelegate); controller = Robolectric.buildActivity(ThreadPreviewActivity.class, new Intent().putExtra(ThreadPreviewActivity.EXTRA_ITEM, new TestHnItem(2L) { @Override public String getBy() { return "username"; } })); activity = controller .create().start().resume().visible().get(); }
Example #5
Source File: TestANClickThroughAction.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testInterstitialANClickThroughActionSDKBrowser() { interstitialAdView.setClickThroughAction(ANClickThroughAction.OPEN_SDK_BROWSER); server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.noFillCSM_RTBInterstitial())); executeInterstitialRequest(); waitUntilExecuted(); waitForTasks(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); waitForTasks(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); assertTrue(adClicked); assertFalse(adClickedWithUrl); }
Example #6
Source File: MainActivityTest.java From openwebnet-android with MIT License | 6 votes |
@Test public void shouldVerifyInstance_stateTitle() { when(environmentService.findAll()).thenReturn(Observable.empty()); ActivityController<MainActivity> controller = Robolectric.buildActivity(MainActivity.class); activity = controller .create() .start() .resume() .visible() .get(); ButterKnife.bind(this, activity); assertEquals("wrong title", labelAppName, activity.getSupportActionBar().getTitle()); String CUSTOM_TITLE = "myNewTitle"; activity.getSupportActionBar().setTitle(CUSTOM_TITLE); activity = controller .stop() .resume() .visible() .get(); assertEquals("wrong title", CUSTOM_TITLE, activity.getSupportActionBar().getTitle()); }
Example #7
Source File: OktaManagementActivityTest.java From okta-sdk-appauth-android with Apache License 2.0 | 6 votes |
@Test public void testOnStartShouldSignOutIfConfigurationHasChanged() throws CanceledException, JSONException { // Create new configuration to change the hash Context context = RuntimeEnvironment.application.getApplicationContext(); new OAuthClientConfiguration( context, context.getSharedPreferences(OAuthClientConfiguration.PREFS_NAME, MODE_PRIVATE), ConfigurationStreams.getOtherConfiguration() ); doNothing().when(mCancelIntent).send(); OktaManagementActivity activity = Robolectric.buildActivity( OktaManagementActivity.class ).newIntent(createStartIntent()).create().start().get(); assertThat(activity.isFinishing()).isTrue(); }
Example #8
Source File: BaseFragmentActivityTest.java From edx-app-android with Apache License 2.0 | 6 votes |
/** * Testing show info method */ @Test public void showInfoMessageTest() { final BaseFragmentActivity activity = Robolectric.buildActivity(getActivityClass(), getIntent()).setup().get(); TextView messageView = new TextView(activity); messageView.setId(R.id.flying_message); messageView.setVisibility(View.GONE); activity.addContentView(messageView, new ViewGroup.LayoutParams( ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT)); assertThat(messageView).hasText(""); final String message = "test"; assertShowInfoMessage(activity, message, new Runnable() { @Override public void run() { assumeTrue(activity.showInfoMessage(message)); } }); }
Example #9
Source File: ANOMIDNativeViewabilityTests.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testOmidNativeRendererJSEvents() { server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.anNativeRenderer())); adRequest.loadAd(); Lock.pause(1000); waitForTasks(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); waitForTasks(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.getForegroundThreadScheduler().runOneTask(); assertAdLoaded(true); assertVerificationScriptResourceNativeRenderer(); assertANOMIDAdSessionPresent(); attachNativeAdToViewAndRegisterTracking(); assertOMIDSessionStartRenderer(); NativeAdSDK.unRegisterTracking(dummyNativeView); Lock.pause(1000); waitForTasks(); Robolectric.getForegroundThreadScheduler().advanceToLastPostedRunnable(); assertOMIDSessionFinish(); }
Example #10
Source File: ResultCodeTest.java From prebid-mobile-android with Apache License 2.0 | 6 votes |
@Test public void testTimeOut() throws Exception { PrebidMobile.setPrebidServerHost(Host.APPNEXUS); PrebidMobile.setTimeoutMillis(30); PrebidMobile.setPrebidServerAccountId("b7adad2c-e042-4126-8ca1-b3caac7d3e5c"); PrebidMobile.setShareGeoLocation(true); PrebidMobile.setApplicationContext(activity.getApplicationContext()); DemandAdapter.DemandAdapterListener mockListener = mock(DemandAdapter.DemandAdapterListener.class); PrebidServerAdapter adapter = new PrebidServerAdapter(); HashSet<AdSize> sizes = new HashSet<>(); sizes.add(new AdSize(0, 250)); RequestParams requestParams = new RequestParams("e2edc23f-0b3b-4203-81b5-7cc97132f418", AdType.BANNER, sizes); String uuid = UUID.randomUUID().toString(); adapter.requestDemand(requestParams, mockListener, uuid); @SuppressWarnings("unchecked") ArrayList<PrebidServerAdapter.ServerConnector> connectors = (ArrayList<PrebidServerAdapter.ServerConnector>) FieldUtils.readDeclaredField(adapter, "serverConnectors", true); PrebidServerAdapter.ServerConnector connector = connectors.get(0); PrebidServerAdapter.ServerConnector.TimeoutCountDownTimer timeoutCountDownTimer = (PrebidServerAdapter.ServerConnector.TimeoutCountDownTimer) FieldUtils.readDeclaredField(connector, "timeoutCountDownTimer", true); shadowOf(timeoutCountDownTimer).invokeFinish(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); verify(mockListener).onDemandFailed(ResultCode.TIMEOUT, uuid); }
Example #11
Source File: DrawPathTaskTest.java From open with GNU General Public License v3.0 | 6 votes |
@Before public void setup() throws Exception { application = (TestMapzenApplication) Robolectric.application; application.inject(this); TestHelper.initBaseActivity(); TestMap testMap = (TestMap) mapController.getMap(); viewController = Mockito.mock(ViewController.class); testMap.setViewport(viewController); task = new DrawPathTask(application); box = Mockito.mock(BoundingBox.class); stub(viewController.getBBox()).toReturn(box); outsideBefore1 = new Location("f"); outsideBefore1.setLatitude(1); outsideBefore2 = new Location("f"); outsideBefore2.setLatitude(2); inside1 = new Location("f"); inside1.setLatitude(3); inside2 = new Location("f"); inside2.setLatitude(4); outSideAfter1 = new Location("f"); outSideAfter1.setLatitude(5); outSideAfter2 = new Location("f"); outSideAfter2.setLatitude(6); }
Example #12
Source File: AdListenerTest.java From mobile-sdk-android with Apache License 2.0 | 6 votes |
@Test public void testLazyBannerAdLoadedFailureAndLoadAgainSuccess() { server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.invalidBanner())); bannerAdView.enableLazyLoad(); assertFalse(bannerAdView.getChildAt(0) instanceof WebView); executeBannerRequest(); assertLazyLoadCallbackInProgress(); bannerAdView.loadLazyAd(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); assertLazyLoadCallbackFailure(); adLoaded = false; adFailed = false; adLazyLoaded = false; restartServer(); server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.banner())); executeBannerRequest(); assertLazyLoadCallbackInProgress(); assertFalse(bannerAdView.getChildAt(0) instanceof WebView); bannerAdView.loadLazyAd(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); assertLazyLoadCallbackSuccess(); }
Example #13
Source File: AnimatorUtilityTests.java From scene with Apache License 2.0 | 6 votes |
@Test public void testResetViewStatus() { ActivityController<NavigationSourceUtility.TestActivity> controller = Robolectric.buildActivity(NavigationSourceUtility.TestActivity.class).create().start().resume(); NavigationSourceUtility.TestActivity testActivity = controller.get(); View view = new View(testActivity); view.setTranslationX(1); view.setTranslationY(1); view.setScaleX(2.0f); view.setScaleY(2.0f); view.setRotation(1.0f); view.setRotationX(1.0f); view.setRotationY(1.0f); view.setAlpha(0.5f); view.startAnimation(new AlphaAnimation(0.0f, 1.0f)); AnimatorUtility.resetViewStatus(view); assertEquals(0.0f, view.getTranslationX(), 0.0f); assertEquals(0.0f, view.getTranslationY(), 0.0f); assertEquals(1.0f, view.getScaleX(), 0.0f); assertEquals(1.0f, view.getScaleY(), 0.0f); assertEquals(0.0f, view.getRotation(), 0.0f); assertEquals(0.0f, view.getRotationX(), 0.0f); assertEquals(0.0f, view.getRotationY(), 0.0f); assertEquals(1.0f, view.getAlpha(), 0.0f); assertNull(view.getAnimation()); }
Example #14
Source File: IterableCursorWrapperTest.java From cursor-utils with MIT License | 6 votes |
@Test public void merging() { TestDb db0 = new TestDb(Robolectric.application); TestDb db1 = new TestDb(Robolectric.application); db0.insertRow(0, 0l, 0f, 0d, (short) 0, true, new byte[]{0, 0}, "0"); db0.insertRow(1, 1l, 1f, 1d, (short) 1, true, new byte[]{1, 1}, "1"); db1.insertRow(2, 2l, 2f, 2d, (short) 2, true, new byte[]{2, 2}, "2"); db1.insertRow(3, 3l, 3f, 3d, (short) 3, true, new byte[]{3, 3}, "3"); IterableCursor<Pojo> cursor = new IterableMergeCursor<Pojo>( new PojoCursor(db0.query()), new PojoCursor(db1.query())); Pojo[] samples = new Pojo[]{ new Pojo(0, 0l, 0f, 0d, (short) 0, true, new byte[]{0, 0}, "0"), new Pojo(1, 1l, 1f, 1d, (short) 1, true, new byte[]{1, 1}, "1"), new Pojo(2, 2l, 2f, 2d, (short) 2, true, new byte[]{2, 2}, "2"), new Pojo(3, 3l, 3f, 3d, (short) 3, true, new byte[]{3, 3}, "3") }; iterationHelper(cursor, samples); }
Example #15
Source File: AddCardActivityUnitTest.java From braintree-android-drop-in with MIT License | 6 votes |
private void triggerConfigurationChange(BraintreeUnitTestHttpClient httpClient) { Bundle bundle = new Bundle(); mActivityController.saveInstanceState(bundle) .pause() .stop() .destroy(); mActivityController = Robolectric.buildActivity(AddCardUnitTestActivity.class); mActivity = (AddCardUnitTestActivity) mActivityController.get(); mShadowActivity = shadowOf(mActivity); mActivity.httpClient = httpClient; mActivityController.setup(bundle); mActivity.braintreeFragment.onAttach(mActivity); mActivity.braintreeFragment.onResume(); setupViews(); }
Example #16
Source File: ClickGuardTest.java From clickguard with Apache License 2.0 | 6 votes |
@Test public void guardMultipleViews() { CountClickListener listener = new CountClickListener() { @Override public void onClick(View v) { super.onClick(v); assertEquals(1, getClickedCount()); } }; View view1 = new View(Robolectric.application); view1.setOnClickListener(listener); View view2 = new View(Robolectric.application); view2.setOnClickListener(listener); View view3 = new View(Robolectric.application); view3.setOnClickListener(listener); ClickGuard.guard(view1, view2, view3); clickViews(view1, view2, view3); }
Example #17
Source File: AuthProviderTest.java From Auth0.Android with MIT License | 6 votes |
@Test public void shouldFailWithDialogWhenPermissionsAreNotGranted() { when(handler.parseRequestResult(PERMISSION_REQUEST_CODE, PROVIDER_PERMISSIONS, PERMISSIONS_GRANTED)).thenReturn(Arrays.asList("some", "values")); Activity activity = Robolectric.buildActivity(Activity.class).create().resume().get(); provider.start(activity, callback, PERMISSION_REQUEST_CODE, AUTHENTICATION_REQUEST_CODE); provider.onRequestPermissionsResult(activity, PERMISSION_REQUEST_CODE, PROVIDER_PERMISSIONS, PERMISSIONS_GRANTED); ArgumentCaptor<Dialog> dialogCaptor = ArgumentCaptor.forClass(Dialog.class); verify(callback).onFailure(dialogCaptor.capture()); final Dialog dialog = dialogCaptor.getValue(); assertThat(dialog, is(instanceOf(Dialog.class))); assertThat(dialog, is(notNullValue())); dialog.show(); //Load the layout TextView messageTV = dialog.findViewById(android.R.id.message); assertThat(messageTV.getText().toString(), containsString("Some permissions required by this provider were not granted. You can try to authenticate again or go to " + "the application's permission screen in the phone settings and grant them. The missing permissions are:\n" + "[some, values]")); }
Example #18
Source File: WebFragmentLocalTest.java From materialistic with Apache License 2.0 | 6 votes |
@Before public void setUp() { MockitoAnnotations.initMocks(this); TestApplication.applicationGraph.inject(this); reset(itemManager); controller = Robolectric.buildActivity(WebActivity.class); activity = controller.get(); PreferenceManager.getDefaultSharedPreferences(activity) .edit() .putBoolean(activity.getString(R.string.pref_lazy_load), false) .apply(); shadowOf((ConnectivityManager) RuntimeEnvironment.application .getSystemService(Context.CONNECTIVITY_SERVICE)) .setActiveNetworkInfo(ShadowNetworkInfo.newInstance(null, ConnectivityManager.TYPE_WIFI, 0, true, NetworkInfo.State.CONNECTED)); }
Example #19
Source File: SubmitActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testDeriveEmptyTitle() { controller.pause().stop().destroy(); controller = Robolectric.buildActivity(SubmitActivity.class, new Intent().putExtra(Intent.EXTRA_TEXT, " : http://example.com")); activity = controller .create().start().resume().visible().get(); assertThat((EditText) activity.findViewById(R.id.edittext_title)).isEmpty(); assertThat((EditText) activity.findViewById(R.id.edittext_content)).hasTextString("http://example.com"); }
Example #20
Source File: SubmitActivityTest.java From materialistic with Apache License 2.0 | 5 votes |
@Test public void testDeriveTitle() { controller.pause().stop().destroy(); controller = Robolectric.buildActivity(SubmitActivity.class, new Intent().putExtra(Intent.EXTRA_TEXT, "http://example.com")); activity = controller .create().start().resume().visible().get(); assertEquals("http://example.com", ShadowWebView.getLastGlobalLoadedUrl()); }
Example #21
Source File: LynxActivityTest.java From Lynx with Apache License 2.0 | 5 votes |
@Test public void shouldConfigureLynxViewWithTheDefaultLynxConfigIfUsesGetIntentMethod() { Intent intent = LynxActivity.getIntent(RuntimeEnvironment.application); LynxActivity lynxActivity = Robolectric.buildActivity(LynxActivity.class).withIntent(intent).create().resume().get(); LynxView lynxView = (LynxView) lynxActivity.findViewById(R.id.lynx_view); assertEquals(new LynxConfig(), lynxView.getLynxConfig()); }
Example #22
Source File: LeanplumMessageTemplatesTest.java From Leanplum-Android-SDK with Apache License 2.0 | 5 votes |
@Test public void testWebInterstitial() throws Exception { LeanplumTestActivity activity = Robolectric.buildActivity(LeanplumTestActivity.class). create().start().resume().visible().get(); setActivityVisibility(activity); Leanplum.setApplicationContext(activity); HashMap<String, Object> map = new HashMap<>(); map.put(MessageTemplates.Args.TITLE_TEXT, "text"); map.put(MessageTemplates.Args.TITLE_COLOR, 100); map.put(MessageTemplates.Args.MESSAGE_TEXT, "message_text"); map.put(MessageTemplates.Args.MESSAGE_COLOR, 1200); map.put(MessageTemplates.Args.BACKGROUND_COLOR, 123); map.put(MessageTemplates.Args.ACCEPT_BUTTON_TEXT, "button_text"); map.put(MessageTemplates.Args.ACCEPT_BUTTON_BACKGROUND_COLOR, 123); map.put(MessageTemplates.Args.ACCEPT_BUTTON_TEXT_COLOR, 123); map.put(MessageTemplates.Args.LAYOUT_WIDTH, 128); map.put(MessageTemplates.Args.LAYOUT_HEIGHT, 128); map.put(MessageTemplates.Args.CLOSE_URL, "www.google.com"); map.put(MessageTemplates.Args.OPEN_URL, "www.google.com"); map.put(MessageTemplates.Args.TRACK_URL, "www.google.com"); map.put(MessageTemplates.Args.ACTION_URL, "www.google.com"); map.put(MessageTemplates.Args.TRACK_ACTION_URL, "www.google.com"); map.put(MessageTemplates.Args.HTML_ALIGN, "top"); map.put(MessageTemplates.Args.HTML_HEIGHT, 100); map.put(MessageTemplates.Args.URL, "www.google.com"); map.put(MessageTemplates.Args.HAS_DISMISS_BUTTON, true); map.put(MessageTemplates.Args.CLOSE_URL, "www.leanplum.com"); ActionContext actionContext = new ActionContext("center_popup", map, "message_id"); WebInterstitialOptions options = new WebInterstitialOptions(actionContext); WebInterstitial interstitial = new WebInterstitial(activity, options); assertNotNull(interstitial); assertEquals(options, interstitial.webOptions); }
Example #23
Source File: MediatedBannerAdViewControllerTest.java From mobile-sdk-android with Apache License 2.0 | 5 votes |
@Test public void test8StandardThenMediated() { server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.banner())); server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.mediatedSuccessfulBanner())); server.enqueue(new MockResponse().setResponseCode(200).setBody(TestResponsesUT.blank())); // load a standard ad requestManager.execute(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); Lock.pause(ShadowSettings.MEDIATED_NETWORK_TIMEOUT); View view = bannerAdView.getChildAt(0); assertTrue(view instanceof AdWebView); assertCallbacks(true); adLoaded = false; // load a mediated ad requestManager = new AdViewRequestManager(bannerAdView); requestManager.execute(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); Robolectric.getBackgroundThreadScheduler().advanceToLastPostedRunnable(); Robolectric.flushBackgroundThreadScheduler(); Robolectric.flushForegroundThreadScheduler(); Lock.pause(ShadowSettings.MEDIATED_NETWORK_TIMEOUT); assertResponseURL(3, SUCCESS, CHECK_LATENCY_TRUE); View mediatedView = bannerAdView.getChildAt(0); assertNotNull(mediatedView); assertEquals(DummyView.dummyView, mediatedView); assertCallbacks(true); }
Example #24
Source File: FragmentsSelectTest.java From itag with GNU General Public License v3.0 | 5 votes |
@Test public void bleDisabled_shouldReturnDisabledBLEFragment() { mockBluetoothAdapter = Mockito.mock(BluetoothAdapter.class); when(mockBluetoothAdapter.isEnabled()).thenReturn(false); when(mockBluetoothManager.getAdapter()).thenReturn(mockBluetoothAdapter); MainActivity mainActivity = Robolectric.setupActivity(MainActivity.class); final FragmentManager fragmentManager = mainActivity.getSupportFragmentManager(); Fragment fragment = fragmentManager.findFragmentById(R.id.content); Assert.assertTrue(fragment instanceof DisabledBLEFragment); }
Example #25
Source File: DiscoveryManagerTest.java From Connect-SDK-Android-Core with Apache License 2.0 | 5 votes |
@Test public void testUnregisterDeviceServiceWithWrongServiceID() { discovery.discoveryProviders.add(new SSDPDiscoveryProvider(Robolectric.application)); discovery.deviceClasses.put(DLNAService.ID, DIALService.class); Assert.assertEquals(1, discovery.discoveryProviders.size()); Assert.assertEquals(1, discovery.deviceClasses.size()); discovery.unregisterDeviceService(DIALService.class, SSDPDiscoveryProvider.class); Assert.assertEquals(1, discovery.deviceClasses.size()); Assert.assertEquals(1, discovery.discoveryProviders.size()); }
Example #26
Source File: DeserializerEndpointTest.java From RoboZombie with Apache License 2.0 | 5 votes |
/** * <p>Test for {@link Deserializers#JSON} with a generic type.</p> * * @since 1.3.3 */ @Test public final void testDeserializeJsonToGenericType() { Robolectric.getFakeHttpLayer().interceptHttpRequests(false); String subpath = "/jsonarray"; User user1 = new User(0, "Tenzen0", "Yakushiji0", 300, true); User user2 = new User(1, "Tenzen1", "Yakushiji1", 300, true); stubFor(get(urlEqualTo(subpath)) .willReturn(aResponse() .withStatus(200) .withBody(new Gson().toJson(Arrays.asList(user1, user2))))); List<User> deserializedUsers = deserializerEndpoint.deserializeJsonToGenericType(); verify(getRequestedFor(urlEqualTo(subpath))); for (int i = 0; i < deserializedUsers.size(); i++) { User user = deserializedUsers.get(i); assertEquals(i, user.getId()); assertEquals("Tenzen" + String.valueOf(i), user.getFirstName()); assertEquals("Yakushiji" + String.valueOf(i), user.getLastName()); assertEquals(300, user.getAge()); assertEquals(true, user.isImmortal()); } }
Example #27
Source File: SettingsActivityTest.java From budget-watch with GNU General Public License v3.0 | 5 votes |
@Test public void testAvailableSettings() { ActivityController activityController = Robolectric.buildActivity(SettingsActivity.class).create(); Activity activity = (Activity)activityController.get(); activityController.start(); activityController.resume(); activityController.visible(); ListView list = (ListView)activity.findViewById(android.R.id.list); shadowOf(list).populateItems(); List<String> settingTitles = new LinkedList<> (Arrays.asList( "Receipt Quality" )); assertEquals(settingTitles.size(), list.getCount()); for(int index = 0; index < list.getCount(); index++) { ListPreference preference = (ListPreference)list.getItemAtPosition(0); String title = preference.getTitle().toString(); assertTrue(settingTitles.remove(title)); } assertTrue(settingTitles.isEmpty()); }
Example #28
Source File: NavigationSceneCompatUtility_SetupWithFragment_Tests.java From scene with Apache License 2.0 | 5 votes |
@Test public void testSetupInFragmentLifecycleMethods_Fragment_Added_In_Activity_OnCreate() { ActivityController<TestAppCompatActivity> controller = Robolectric.buildActivity(TestAppCompatActivity.class).create(); TestAppCompatActivity activity = controller.get(); TestNormalFragment_Add_In_Activity_OnCreate testFragment = new TestNormalFragment_Add_In_Activity_OnCreate(); activity.getSupportFragmentManager().beginTransaction().add(activity.mFrameLayout.getId(), testFragment).commitNowAllowingStateLoss(); controller.start(); controller.resume(); controller.pause(); controller.stop(); controller.destroy(); assertEquals(6, testFragment.mMethodInvokedCount); }
Example #29
Source File: RouteFragmentTest.java From open with GNU General Public License v3.0 | 5 votes |
@Test public void setRoute_shouldShowRouteFooterAfterReroute() throws Exception { loadAceHotelMockRoute(); fragment.onRecalculate(getTestLocation(111.0, 111.0)); Route route = new Route(MOCK_ACE_HOTEL); fragment.setRoute(route); Robolectric.runUiThreadTasks(); assertThat(fragment.footerWrapper).isVisible(); }
Example #30
Source File: MainActivityTest.java From budget-watch with GNU General Public License v3.0 | 5 votes |
@Test public void testClickSettings() { ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create(); Activity activity = (Activity)activityController.get(); activityController.start(); activityController.resume(); activityController.visible(); shadowOf(activity).clickMenuItem(R.id.action_settings); testNextStartedActivity(activity, "protect.budgetwatch/.SettingsActivity"); }