Java Code Examples for org.robolectric.util.ActivityController#pause()

The following examples show how to use org.robolectric.util.ActivityController#pause() . 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: ControllerActivity.java    From AndroidUnitTest with Apache License 2.0 6 votes vote down vote up
private void applyState(ActivityState state,
                        ActivityController controller) {
    switch (state) {
        case STARTED:
            controller.start();
            break;
        case RESUMED:
            controller.resume();
            break;
        case PAUSED:
            controller.pause();
            break;
        case STOPPED:
            controller.stop();
            break;
        case DESTROYED:
            controller.destroy();
            break;
        case CREATED:
        default:
            controller.create();
            break;
    }
}
 
Example 2
Source File: MainActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void addOneGiftCard()
{
    ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();

    Activity mainActivity = (Activity)activityController.get();
    activityController.start();
    activityController.resume();

    TextView helpText = (TextView)mainActivity.findViewById(R.id.helpText);
    ListView list = (ListView)mainActivity.findViewById(R.id.list);

    assertEquals(0, list.getCount());

    DBHelper db = new DBHelper(mainActivity);
    db.insertGiftCard("store", "cardId", "value", "receipt");

    assertEquals(View.VISIBLE, helpText.getVisibility());
    assertEquals(View.GONE, list.getVisibility());

    activityController.pause();
    activityController.resume();

    assertEquals(View.GONE, helpText.getVisibility());
    assertEquals(View.VISIBLE, list.getVisibility());

    assertEquals(1, list.getAdapter().getCount());
    Cursor cursor = (Cursor)list.getAdapter().getItem(0);
    assertNotNull(cursor);
}
 
Example 3
Source File: ActivitiesTest.java    From tickmate with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void editTrackActivityStoresChanges() throws Exception {
    openMethod.invoke(dataSource);
    Track t = new Track("Testing", "Run my tests");
    t.setEnabled(true);
    dataSource.storeTrack(t);
    closeMethod.invoke(dataSource);
    assertThat(t, equalTo(t));

    Intent i = new Intent(RuntimeEnvironment.application.getApplicationContext(), tickmate.getClass());
    i.putExtra("track_id", t.getId());
    ActivityController<TrackPreferenceActivity> r_eta = Robolectric.buildActivity(TrackPreferenceActivity.class)
            .withIntent(i)
            .create(new Bundle())
            .start()
            .resume();

    TrackPreferenceActivity eta = r_eta.get();
    TrackPreferenceFragment tpf = (TrackPreferenceFragment) eta.getFragmentManager().findFragmentById(android.R.id.content);
    EditTextPreference description = (EditTextPreference) tpf.findPreference("description");
    assertThat(description.getText().toString(), is("Run my tests"));
    description.setText("Krishna Hare");

    r_eta.pause();
    r_eta.stop();

    Track t_also = dataSource.getTrack(t.getId());

    assertThat(t, equalTo(t_also));
    assertThat(t_also.getName(), is(t.getName()));
    assertThat(t_also.getIcon(), is(t.getIcon()));
    assertThat(t_also.getDescription(), is("Krishna Hare"));
    assertThat(t_also.isEnabled(), is(t.isEnabled()));
}