@Test public void shouldStartIntentWithCorrectUriWhenUriNotEncoded() throws UnsupportedEncodingException { createFilterTestRule.launchActivity(new Intent(Intent.ACTION_MAIN)); String filterName = "MyTestFilter-" + UUID.randomUUID(); clickAddFilter(); setFilterData(filterName, "http://daverix.net/test/@uri", "@uri", ""); closeSoftKeyboard(); clickEncodeCheckbox(); saveUsingIdlingResource(getApplication()); Intent intent = new Intent(Intent.ACTION_SEND); intent.putExtra(Intent.EXTRA_TEXT, "http://example2.com"); testRule.launchActivity(intent); onData(withLinkFilter(filterName)).perform(click()); intended(allOf(IntentMatchers.hasAction(Intent.ACTION_VIEW), IntentMatchers.hasData("http://daverix.net/test/http://example2.com"))); }
@Test public void speakerImage_WhenClicked_IntentFired() { Intent resultData = new Intent(); resultData.putExtras(new Bundle()); // Create the ActivityResult with the Intent. Intents.intending(CoreMatchers.not(IntentMatchers.isInternal())).respondWith( new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData)); // When clicking on speaker image onView(withId(R.id.session_detail_frag)).perform(swipeUp()); onView(withId(R.id.speaker_image)).perform(click()); // Then the intent to display the speaker url is fired Uri expectedSpeakerUri = Uri.parse(SpeakersMockCursor.FAKE_SPEAKER_URL); intended(CoreMatchers.allOf( hasAction(IsEqual.equalTo(Intent.ACTION_VIEW)), hasData(expectedSpeakerUri))); }
@Test public void youTubeVideo_WhenClicked_IntentFired() { Intent resultData = new Intent(); resultData.putExtras(new Bundle()); // Create the ActivityResult with the Intent. Intents.intending(CoreMatchers.not(IntentMatchers.isInternal())).respondWith( new Instrumentation.ActivityResult(Activity.RESULT_OK, resultData)); // When clicking on video onView(withId(R.id.watch)).perform(click()); // Then the intent to play the video is fired IntentUtils.checkVideoIntentIsFired(SessionsMockCursor.FAKE_YOUTUBE_URL, mActivityRule.getActivity(), false); }
@Test public void testContactPickerStubWithExtraMatcher() { Uri dummyContactDataUri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, CONTACT_ID); EspContactStub.register(dummyContactDataUri, Activity.RESULT_OK, IntentMatchers.hasExtraWithKey("MyKey")); Intent contactPickerIntent = createContactPickerIntent(); contactPickerIntent.putExtra("MyKey", "myValue"); activity.startForResult(contactPickerIntent, REQUEST_CODE); requestCodeTextView.assertTextIs(String.valueOf(REQUEST_CODE)); resultCodeTextView.assertTextIs(String.valueOf(Activity.RESULT_OK)); dataTextView.assertTextIs(dummyContactDataUri.toString()); }
@Test @Ignore("result will be delivered in tear down, after all checks are done") public void testWhenNotMatchingExtraMatcher() { Uri dummyContactDataUri = ContentUris.withAppendedId(ContactsContract.Data.CONTENT_URI, CONTACT_ID); EspContactStub.register(dummyContactDataUri, Activity.RESULT_OK, IntentMatchers.hasExtraWithKey("MyKey")); activity.startForResult(createContactPickerIntent(), REQUEST_CODE); requestCodeTextView.assertTextIs(""); resultCodeTextView.assertTextIs(""); dataTextView.assertTextIs(""); }
@Test public void testRecipeAnalysis() { when(repository.getRecipeAnalysisData(ArgumentMatchers.<RecipeAnalysisParams>any())) .thenReturn(Single.just(AssetUtils.getRecipeAnalysisResult(context))); rule.launchActivity(new Intent()); selectTab(); inputFields(); onView(withId(R.id.btn_analyze)).perform(click()); Intents.intended(IntentMatchers.hasComponent(RecipeAnalysisDetailsActivity.class.getName())); }
@Override protected boolean checkShareWentOK() { intended(allOf( hasAction(Intent.ACTION_SEND), IntentMatchers.hasExtra(Intent.EXTRA_SUBJECT, mActivityRule.getActivity().getString(R.string.share_title)))); return true; }
@Override public void testThatDefaultBehaviorIsWorking() throws Exception { Instrumentation.ActivityResult dummyResult = new Instrumentation.ActivityResult(0, null); Intents.intending(allOf( hasAction(Intent.ACTION_SEND), IntentMatchers.hasExtra(Intent.EXTRA_SUBJECT, mActivityRule.getActivity().getString(R.string.share_title)))) .respondWith(dummyResult); super.testThatDefaultBehaviorIsWorking(); }
@Test public void showLoginActivity_if_not_signIn() { Mockito.when(accountDaemon.hasAccount()).thenReturn(false); activityRule.launchActivity(new Intent()); intended(IntentMatchers.hasComponent(LoginActivity.class.getName())); }