Java 类org.robolectric.shadows.ShadowIntent 实例源码

项目:grocery-reminder    文件:RemindersActivityTest.java   
@Test
public void givenTheLoaderIsFinishedWhenTheShareButtonIsPressedThenTheLoadedListOfRemindersIsShared() {
    Reminder reminder = new Reminder(0, "test");
    Reminder reminder2 = new Reminder(0, "test2");
    Cursor mockCursor = mock(Cursor.class);
    when(mockCursor.moveToNext()).thenReturn(true).thenReturn(true).thenReturn(false);
    when(mockCursor.getLong(0)).thenReturn(reminder.getId()).thenReturn(reminder2.getId());
    when(mockCursor.getString(1)).thenReturn(reminder.getText()).thenReturn(reminder2.getText());
    ShadowCursorWrapper wrapper = new ShadowCursorWrapper();
    wrapper.__constructor__(mockCursor);

    CursorLoader cursorLoader = (CursorLoader)activity.onCreateLoader(0, null);
    activity.onLoadFinished(cursorLoader, wrapper);

    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    shadowActivity.clickMenuItem(R.id.action_share);

    ShadowIntent shadowIntent = Shadows.shadowOf(shadowActivity.peekNextStartedActivity());
    assertEquals(Intent.ACTION_CHOOSER, shadowIntent.getAction());
    ShadowIntent shareIntent = Shadows.shadowOf((Intent) shadowIntent.getParcelableExtra("android.intent.extra.INTENT"));
    assertEquals("text/plain", shareIntent.getType());
    assertEquals("test\ntest2\n", shareIntent.getExtras().getString(Intent.EXTRA_TEXT));
}
项目:grocery-reminder    文件:GroceryStoreListViewHolderTest.java   
@Test
public void givenAStoreIsBoundWhenTheStoreViewHolderIsClickedThenTheMapApplicationIsLaunched() {
    RecyclerView recyclerView = getRecyclerView();
    Context context = recyclerView.getContext();
    View view = LayoutInflater.from(context).inflate(R.layout.store_viewholder, recyclerView, false);
    double latitude = 0.0;
    double longitude = 1.0;
    GroceryStore store = new GroceryStore(ARBITRARY_STORE_NAME, 2414.02, latitude, longitude);

    GroceryStoreListViewHolder viewHolder = new GroceryStoreListViewHolder(view);
    viewHolder.bind(store);

    viewHolder.onClick(view);

    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    ShadowIntent shadowIntent = Shadows.shadowOf(shadowActivity.peekNextStartedActivity());
    assertTrue(shadowIntent.getData().toString().contains("geo:" + latitude + "," + longitude));
}
项目:grocery-reminder    文件:GroceryStoresActivityTest.java   
@Test
public void givenStoresAreLoadedWhenAStoreIsClickedThenTheMapApplicationIsLaunched() {
    ShadowCursorWrapper wrapper = createCursorWithDefaultReminder();

    GroceryStoreManagerInterface groceryStoreManagerMock = getTestReminderModule().getGroceryStoreManager();
    when(groceryStoreManagerMock.getCurrentLocation()).thenReturn(new Location(LocationManager.PASSIVE_PROVIDER));

    CursorLoader cursorLoader = (CursorLoader)activity.onCreateLoader(0, null);
    activity.onLoadFinished(cursorLoader, wrapper);
    GroceryStoreListFragment groceryStoreListFragment = getGroceryStoreListFragment();
    assertNotNull(groceryStoreListFragment);

    RecyclerView listView = getRecyclerView(groceryStoreListFragment, R.id.stores_recycler_view);
    listView.findViewHolderForAdapterPosition(0).itemView.performClick();

    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    ShadowIntent shadowIntent = Shadows.shadowOf(shadowActivity.peekNextStartedActivity());
    assertEquals("geo:0.0,1.0?q=0.0,1.0(test)", shadowIntent.getData().toString());
}
项目:lmis-moz-mobile    文件:RnRFormListActivityTest.java   
@Test
public void shouldGotoEmergencyPage() throws Exception {
    LMISTestApp.getInstance().setCurrentTimeMillis(DateUtil.parseString("2015-05-17 17:30:00", DateUtil.DATE_TIME_FORMAT).getTime());

    Observable<Boolean> value = Observable.create(new Observable.OnSubscribe<Boolean>() {
        @Override
        public void call(Subscriber<? super Boolean> subscriber) {
            subscriber.onNext(false);
        }
    });
    when(mockedPresenter.hasMissedPeriod()).thenReturn(value);

    rnRFormListActivity.checkAndGotoEmergencyPage();

    ShadowActivity shadowActivity = shadowOf(rnRFormListActivity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    MatcherAssert.assertThat(shadowIntent.getComponent().getClassName(), equalTo(SelectEmergencyProductsActivity.class.getName()));
}
项目:CCDroid    文件:ListViewItemClickListenerTest.java   
@Ignore
    @Test public void testShouldOpenUrl() throws Exception {
        Activity activity = Robolectric.buildActivity(MainActivity.class).create().get();

//        listener.onItemClick(mock(AdapterView.class), mock(View.class), position, 1);
        clickOnOpenButton();

        ShadowActivity shadowActivity = Shadows.shadowOf(activity);
        Intent startedIntent = shadowActivity.getNextStartedActivity();
        ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent);
        assertThat(shadowIntent.getAction(), is(Intent.ACTION_VIEW));
        assertThat(shadowIntent.getData(), is(Uri.parse(url)));
//        ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
//        verify(context).startActivity(argumentCaptor.capture());
//        Intent intent = argumentCaptor.getValue();
    }
项目:Oleaster    文件:MainActivityTestNormal.java   
@Test
public void buttonClick_startNextActivity() {
    button.performClick();
    ShadowActivity shadowActivity = Shadows.shadowOf(mainActivity);
    Intent intent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = Shadows.shadowOf(intent);
    Assert.assertEquals(SecondActivity.class, shadowIntent.getIntentClass());
}
项目:MobileAppForPatient    文件:DashboardActivityTest.java   
@Test
public void testDeviceClick() {
    btnDeviceConnect.performClick();
    Intent startedIntent = Shadows.shadowOf(activity).getNextStartedActivity();
    ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent);
    junit.framework.Assert.assertEquals("deviceList has not been launched",DeviceListActivity2.class, shadowIntent.getIntentClass());
}
项目:MobileAppForPatient    文件:DashboardActivityTest.java   
@Test
public void testReportClick() {
    btnGetReport.performClick();
    Intent startedIntent = Shadows.shadowOf(activity).getNextStartedActivity();
    ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent);
    Assert.assertEquals( "reportList activity ",ReportsActivity.class, shadowIntent.getIntentClass());
}
项目:MobileAppForPatient    文件:LoginActivityTest.java   
@Test
public  void testsignUp(){
    activity.signUp(null);
    Intent startedIntent = Shadows.shadowOf(activity).getNextStartedActivity();
    ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent);
    Assert.assertEquals("register user has not been launched",RegisterUser.class, shadowIntent.getIntentClass());
}
项目:MobileAppForPatient    文件:LoginActivityTest.java   
@Test
public void testaboutApp(){
    activity.forgotPassword(null);
    Intent startedIntent = Shadows.shadowOf(activity).getNextStartedActivity();
    ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent);
    Assert.assertEquals("forgot password has not been launched",ForgotPasswordActivity.class, shadowIntent.getIntentClass());
}
项目:device-info    文件:DashboardActivityUnitTest.java   
@Test
public void testOnOptionsItemSelectedAboutClicked() throws Exception {
    MenuItem item = mockMenuItem(R.id.about);

    mActivity.onOptionsItemSelected(item);

    ShadowActivity shadowActivity = shadowOf(mActivity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName()).isEqualTo(AboutActivity.class.getName());
    verify(mAnalytics).reportAboutTap();
    verify(mFabricAnalytics).reportAboutTap();
}
项目:device-info    文件:AboutActivityUnitTest.java   
@Test
public void testOnAttributionsClicked() throws Exception {
    mActivity.onAttributionsClicked();
    ShadowActivity shadowActivity = shadowOf(mActivity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName()).isEqualTo(AttributionsActivity.class.getName());
    verify(mAnalytics).reportAttributionsTap();
    verify(mFabricAnalytics).reportAttributionsTap();
}
项目:bblfr-android    文件:NavigationDrawerActivityTest.java   
@Test
public void should_start_baggers_list_activity_if_drawer_is_not_visible_on_back_pressed_and_current_activity_is_not_a_baggers_list_activity() {
    // Given
    when(drawer.isDrawerVisible(GravityCompat.START)).thenReturn(false);

    // When
    activity.onBackPressed();

    // Then
    ShadowActivity shadowActivity = Shadows.shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent);
    Truth.assertThat(shadowIntent.getIntentClass().getName()).isEqualTo(BaggersListActivity.class.getName());
}
项目:grocery-reminder    文件:GroceryStoreManagerTest.java   
@Test
public void whenProximityAlertIsAddedThenTheStorePendingIntentIsSet() {
    Place place = createDefaultGooglePlace();
    List<Place> places = new ArrayList<Place>();
    places.add(place);

    groceryStoreManager.addProximityAlerts(places);

    com.groceryreminder.shadows.ShadowLocationManager.ProximityAlert proximityAlert = shadowLocationManager.getProximityAlert(place.getLatitude(), place.getLongitude());
    ShadowPendingIntent shadowPendingIntent = Shadows.shadowOf(proximityAlert.getPendingIntent());
    ShadowIntent shadowIntent = Shadows.shadowOf(shadowPendingIntent.getSavedIntent());

    assertEquals(GroceryReminderConstants.ACTION_STORE_PROXIMITY_EVENT, shadowIntent.getAction());
}
项目:grocery-reminder    文件:GroceryStoreNotificationManagerTest.java   
@Test
public void givenANotificationIsSentWhenTheNotificationIsActedOnThenTheRemindersActivityIsLaunched() {
    groceryStoreNotificationManager.sendNotification(buildIntentToListenFor());

    ShadowNotificationManager shadowNotificationManager = getShadowNotificationManager();
    ShadowNotification notification = Shadows.shadowOf(shadowNotificationManager.getNotification(GroceryReminderConstants.NOTIFICATION_PROXIMITY_ALERT));
    ShadowPendingIntent shadowPendingIntent = Shadows.shadowOf(notification.getRealNotification().contentIntent);
    ShadowIntent shadowIntent = Shadows.shadowOf(shadowPendingIntent.getSavedIntent());

    assertEquals(RemindersActivity.class.getName(), shadowIntent.getComponent().getClassName());
}
项目:whereat-android    文件:LocServicesAlertFragmentTest.java   
@Test
public void clickingPositiveButton_should_startProcessOfEnablingLocServices(){
    ShadowApplication app = ShadowApplication.getInstance();
    mAlert.getButton(BUTTON_POSITIVE).performClick();

    ShadowIntent si = shadowOf(app.getNextStartedActivity());
    assertThat(si.getAction()).isEqualTo(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
}
项目:unitTestingWithAndroidStudio    文件:LaunchActivityTest.java   
@Test
public void checkIntentLaunched() {
    Button mLaunchCalculatorBtn = (Button) mLaunchActivity.findViewById(R.id.launch_calculator_btn);
    mLaunchCalculatorBtn.performClick();

    ShadowActivity shadowActivity = Shadows.shadowOf(mLaunchActivity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent);

    assertThat(shadowIntent.getComponent())
            .isEqualTo(new ComponentName(mLaunchActivity, MainActivity.class));

}
项目:android-gradle-test    文件:MainActivityRobolectricTest.java   
@Test
public void testNewActivity() throws Exception {
    newActivityButton.performClick();
    ShadowActivity shadow = shadowOf(activity);
    Intent nextActivity = shadow.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(nextActivity);
    assertEquals(MyListActivity.class.getName(), shadowIntent.getComponent().getClassName());
}
项目:robolectric-ant-sample    文件:HomeActivityTest.java   
@Test
public void pressingTheButtonShouldStartTheListActivity() throws Exception {
    pressMeButton.performClick();

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName(), equalTo(NamesActivity.class.getName()));
}
项目:robolectric-ant-sample    文件:HomeActivityTest.java   
@Test
public void pressingTheButtonShouldStartTheSignInActivity() throws Exception {
    trackerRecentActivityButton.performClick();

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);

    assertThat(shadowIntent.getComponent().getClassName(), equalTo(RecentActivityActivity.class.getName()));
}
项目:robolectric-ant-sample    文件:HomeActivityTest.java   
@Test
public void shouldLaunchInjectedActivity() throws Exception {
    clickOn(injectedActivityButton);

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertNotNull(startedIntent);
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName(), equalTo(InjectedActivity.class.getName()));
}
项目:SmsRadar    文件:SmsRadarServiceTest.java   
@Test
public void shouldRestartServiceUsingAlarmManagerWhenTaskRemoved() {
    when(mockedTimeProvider.getDate()).thenReturn(new Date(ANY_TIME));

    startSmsInterceptorService();
    smsRadarService.onTaskRemoved(ANY_INTENT);

    ArgumentCaptor<PendingIntent> pendingIntentArgumentCaptor = ArgumentCaptor.forClass(PendingIntent.class);
    verify(mockedAlarmManager).set(eq(AlarmManager.RTC_WAKEUP), eq(ANY_TIME + ONE_SECOND),
            pendingIntentArgumentCaptor.capture());
    PendingIntent capturedPendingIntent = pendingIntentArgumentCaptor.getValue();
    ShadowPendingIntent pendingIntent = Robolectric.shadowOf(capturedPendingIntent);
    ShadowIntent intent = Robolectric.shadowOf(pendingIntent.getSavedIntent());
    assertEquals(SmsRadarService.class, intent.getIntentClass());
}
项目:logback-examples    文件:HomeActivityTest.java   
@Test
public void pressingTheButtonShouldStartTheListActivity() throws Exception {
    // This calls HomeActivity.onClick(), which invokes an SLF4J log
    // call, causing logback to write to target/logback/.../log.txt
    pressMeButton.performClick();

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName(), equalTo(NamesActivity.class.getName()));
}
项目:open    文件:BaseActivityTest.java   
@Test
public void onOptionsItemSelected_shouldOpenAboutPage() throws Exception {
    MenuItem menuItem = menu.findItem(R.id.about);
    activity.onOptionsItemSelected(menuItem);
    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getAction()).isEqualTo(Intent.ACTION_VIEW);
    assertThat(shadowIntent.getData()).isEqualTo(Uri.parse("https://mapzen.com/open/about"));
}
项目:Inside_Android_Testing    文件:HomeActivityTest.java   
@Test
public void pressingTheButtonShouldStartTheListActivity() throws Exception {
    pressMeButton.performClick();

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName(), equalTo(NamesActivity.class.getName()));
}
项目:Inside_Android_Testing    文件:HomeActivityTest.java   
@Test
public void pressingTheButtonShouldStartTheSignInActivity() throws Exception {
    trackerRecentActivityButton.performClick();

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);

    assertThat(shadowIntent.getComponent().getClassName(), equalTo(RecentActivityActivity.class.getName()));
}
项目:Inside_Android_Testing    文件:HomeActivityTest.java   
@Test
public void shouldLaunchInjectedActivity() throws Exception {
    clickOn(injectedActivityButton);

    ShadowActivity shadowActivity = shadowOf(activity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    assertNotNull(startedIntent);
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName(), equalTo(InjectedActivity.class.getName()));
}
项目:foul-android    文件:FoulTest.java   
private void testMenuClick(final int index, final Class<?> expected) {
    ShadowListView list = shadowOf_(foul.getListView());
    assertThat(list.performItemClick(index), is(true));

    ShadowActivity activity = shadowOf_(foul);
    ShadowIntent intent = shadowOf_(activity.getNextStartedActivity());
    assertThat(intent.getIntentClass().getName(), equalTo(expected.getName()));
}
项目:PanicButton    文件:BootReceiverTest.java   
@Test
public void shouldStartHardwareTriggerServiceOnBootWhenHomeReady() {
    bootReceiver.onReceive(Robolectric.application, bootIntent);

    Intent startedIntent = Robolectric.getShadowApplication().getNextStartedService();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertNotNull(startedIntent);
    assertEquals(HardwareTriggerService.class, shadowIntent.getIntentClass());
}
项目:lmis-moz-mobile    文件:HomeActivityTest.java   
private void verifyNextPage(String className) {
    ShadowActivity shadowActivity = shadowOf(homeActivity);
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = shadowOf(startedIntent);
    assertThat(shadowIntent.getComponent().getClassName(), equalTo(className));
}
项目:FullRobolectricTestSample    文件:Robolectric.java   
public static ShadowIntent shadowOf(Intent instance) {
  return (ShadowIntent) shadowOf_(instance);
}
项目:Attendance    文件:CompaniesMvvmActivityRoboelectricTest.java   
@Test
public void testOptinsMenuItem_click_items() {

    ShadowActivity shadowActivity = Shadows.shadowOf(activity);

    // Click menu1
    shadowActivity.clickMenuItem(R.id.action_settings);

    // Get intent
    Intent startedIntent = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent = Shadows.shadowOf(startedIntent);

    // Make your assertion
    assertEquals(shadowIntent.getIntentClass().getName(), SettingsActivity.class.getName());


    // Click menu2
    shadowActivity.clickMenuItem(R.id.action_logout);

    // Get intent
    Intent startedIntent2 = shadowActivity.getNextStartedActivity();
    ShadowIntent shadowIntent2 = Shadows.shadowOf(startedIntent2);

    // Make your assertion
    assertEquals(shadowIntent2.getIntentClass().getName(), EmailPasswordActivity.class.getName());

}