Java Code Examples for org.robolectric.android.controller.ActivityController#resume()

The following examples show how to use org.robolectric.android.controller.ActivityController#resume() . 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: AndroidLifecycleFragmentTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(LifecycleOwner owner) {
    Fragment fragment = (Fragment) owner;
    ActivityController<?> controller = startFragment(fragment);

    TestObserver<Object> testObserver = observable.compose(AndroidLifecycle.createLifecycleProvider(owner).bindUntilEvent(Lifecycle.Event.ON_STOP)).test();

    testObserver.assertNotComplete();
    controller.start();
    testObserver.assertNotComplete();
    controller.resume();
    testObserver.assertNotComplete();
    controller.pause();
    testObserver.assertNotComplete();
    controller.stop();
    testObserver.assertComplete();
}
 
Example 2
Source File: NavigationSceneUtilityTests.java    From scene with Apache License 2.0 6 votes vote down vote up
@LooperMode(PAUSED)
@Test
public void testNotImmediateSetupInActivityOnCreate() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create();
    TestActivity activity = controller.get();
    SceneDelegate sceneDelegate = NavigationSceneUtility.setupWithActivity(activity, TestScene.class).immediate(false).build();
    NavigationScene navigationScene = sceneDelegate.getNavigationScene();
    assertNotNull(navigationScene);

    assertEquals(State.NONE, navigationScene.getState());
    shadowOf(getMainLooper()).idle();//execute Handler posted task
    assertEquals(State.ACTIVITY_CREATED, navigationScene.getState());

    controller.start();
    assertEquals(State.STARTED, navigationScene.getState());
    controller.resume();
    assertEquals(State.RESUMED, navigationScene.getState());
    controller.pause();
    assertEquals(State.STARTED, navigationScene.getState());
    controller.stop();
    assertEquals(State.ACTIVITY_CREATED, navigationScene.getState());
    controller.destroy();
    assertEquals(State.NONE, navigationScene.getState());
}
 
Example 3
Source File: NavigationSceneUtilityTests.java    From scene with Apache License 2.0 6 votes vote down vote up
@LooperMode(PAUSED)
@Test
public void testNotImmediateSetupInActivityOnStart() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start();
    TestActivity activity = controller.get();
    SceneDelegate sceneDelegate = NavigationSceneUtility.setupWithActivity(activity, TestScene.class).immediate(false).build();
    NavigationScene navigationScene = sceneDelegate.getNavigationScene();
    assertNotNull(navigationScene);

    assertEquals(State.NONE, navigationScene.getState());
    shadowOf(getMainLooper()).idle();//execute Handler posted task
    assertEquals(State.STARTED, navigationScene.getState());

    controller.resume();
    assertEquals(State.RESUMED, navigationScene.getState());
    controller.pause();
    assertEquals(State.STARTED, navigationScene.getState());
    controller.stop();
    assertEquals(State.ACTIVITY_CREATED, navigationScene.getState());
    controller.destroy();
    assertEquals(State.NONE, navigationScene.getState());
}
 
Example 4
Source File: BudgetActivityTest.java    From budget-watch with GNU General Public License v3.0 6 votes vote down vote up
@Test
public void testClickAdd()
{
    ActivityController activityController = Robolectric.buildActivity(BudgetActivity.class).create();
    Activity activity = (Activity)activityController.get();

    activityController.start();
    activityController.resume();
    activityController.visible();

    shadowOf(activity).clickMenuItem(R.id.action_add);

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

    ComponentName name = startedIntent.getComponent();
    assertNotNull(name);
    assertEquals("protect.budgetwatch/.BudgetViewActivity", name.flattenToShortString());
    Bundle bundle = startedIntent.getExtras();
    assertNull(bundle);
}
 
Example 5
Source File: RxActivityLifecycleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testLifecycle(ActivityController<? extends LifecycleProvider<ActivityEvent>> controller) {
    LifecycleProvider<ActivityEvent> activity = controller.get();

    TestObserver<ActivityEvent> testObserver = activity.lifecycle().test();

    controller.create();
    controller.start();
    controller.resume();
    controller.pause();
    controller.stop();
    controller.destroy();

    testObserver.assertValues(
        ActivityEvent.CREATE,
        ActivityEvent.START,
        ActivityEvent.RESUME,
        ActivityEvent.PAUSE,
        ActivityEvent.STOP,
        ActivityEvent.DESTROY
    );
}
 
Example 6
Source File: AndroidLifecycleActivityTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testLifecycle(ActivityController<? extends LifecycleOwner> controller) {
    LifecycleProvider<Lifecycle.Event> provider = AndroidLifecycle.createLifecycleProvider(controller.get());

    TestObserver<Lifecycle.Event> testObserver = provider.lifecycle().test();

    controller.create();
    controller.start();
    controller.resume();
    controller.pause();
    controller.stop();
    controller.destroy();

    testObserver.assertValues(
            Lifecycle.Event.ON_CREATE,
            Lifecycle.Event.ON_START,
            Lifecycle.Event.ON_RESUME,
            Lifecycle.Event.ON_PAUSE,
            Lifecycle.Event.ON_STOP,
            Lifecycle.Event.ON_DESTROY
    );
}
 
Example 7
Source File: AndroidLifecycleFragmentTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testLifecycle(LifecycleOwner owner) {
    Fragment fragment = (Fragment) owner;
    ActivityController<?> controller = startFragment(fragment);

    TestObserver<Lifecycle.Event> testObserver = AndroidLifecycle.createLifecycleProvider(owner).lifecycle().test();

    controller.start();
    controller.resume();
    controller.pause();
    controller.stop();
    controller.destroy();

    testObserver.assertValues(
            Lifecycle.Event.ON_CREATE,
            Lifecycle.Event.ON_START,
            Lifecycle.Event.ON_RESUME,
            Lifecycle.Event.ON_PAUSE,
            Lifecycle.Event.ON_STOP,
            Lifecycle.Event.ON_DESTROY
    );
}
 
Example 8
Source File: AndroidLifecycleActivityTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
private void testBindToLifecycle(ActivityController<? extends LifecycleOwner> controller) {
    LifecycleProvider<Lifecycle.Event> provider = AndroidLifecycle.createLifecycleProvider(controller.get());

    controller.create();
    TestObserver<Object> createObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.start();
    createObserver.assertNotComplete();
    TestObserver<Object> startObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.resume();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    TestObserver<Object> resumeObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.pause();
    createObserver.assertNotComplete();
    startObserver.assertNotComplete();
    resumeObserver.assertComplete();
    TestObserver<Object> pauseObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.stop();
    createObserver.assertNotComplete();
    startObserver.assertComplete();
    pauseObserver.assertComplete();
    TestObserver<Object> stopObserver = observable.compose(provider.bindToLifecycle()).test();

    controller.destroy();
    createObserver.assertComplete();
    stopObserver.assertComplete();
}
 
Example 9
Source File: GroupSceneCompatUtility_SetupWithFragment_Tests.java    From scene with Apache License 2.0 5 votes vote down vote up
@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 10
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void startWithoutParametersCaptureReceiptCancel() throws IOException
{
    ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create();
    activityController.start();
    activityController.visible();
    activityController.resume();

    // Add something that will 'handle' the media capture intent
    registerMediaStoreIntentHandler();

    Activity activity = (Activity)activityController.get();

    checkAllFields(activity, "", "", "", "", false);

    // Complete image capture successfully
    Uri imageLocation = captureImageWithResult(activity, R.id.captureButton, true);

    checkAllFields(activity, "", "", "", "", true);

    // Cancel the gift card creation
    final Button cancelButton = (Button) activity.findViewById(R.id.cancelButton);
    assertEquals(false, activity.isFinishing());
    cancelButton.performClick();
    assertEquals(true, activity.isFinishing());
    activityController.destroy();

    // Ensure the image has been deleted
    File imageFile = new File(imageLocation.getPath());
    assertEquals(false, imageFile.exists());
}
 
Example 11
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void startWithoutParametersCaptureReceiptFailureCreateGiftCard() throws IOException
{
    ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create();
    activityController.start();
    activityController.visible();
    activityController.resume();

    // Add something that will 'handle' the media capture intent
    registerMediaStoreIntentHandler();

    Activity activity = (Activity)activityController.get();

    checkAllFields(activity, "", "", "", "", false);

    // Complete image capture in failure
    Uri imageLocation = captureImageWithResult(activity, R.id.captureButton, false);

    checkAllFields(activity, "", "", "", "", false);

    // Save and check the gift card
    saveGiftCardWithArguments(activity, "store", "cardId", "value", "", true);

    // Check that no file was created
    File imageFile = new File(imageLocation.getPath());
    assertEquals(false, imageFile.exists());
}
 
Example 12
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void startWithoutParametersCaptureReceiptCreateGiftCard() throws IOException
{
    ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create();
    activityController.start();
    activityController.visible();
    activityController.resume();

    // Add something that will 'handle' the media capture intent
    registerMediaStoreIntentHandler();

    Activity activity = (Activity)activityController.get();

    checkAllFields(activity, "", "", "", "", false);

    // Complete image capture successfully
    Uri imageLocation = captureImageWithResult(activity, R.id.captureButton, true);

    checkAllFields(activity, "", "", "", "", true);

    // Save and check the gift card
    saveGiftCardWithArguments(activity, "store", "cardId", "value", imageLocation.getPath(), true);

    // Ensure that the file still exists
    File imageFile = new File(imageLocation.getPath());
    assertTrue(imageFile.isFile());

    // Delete the file to cleanup
    boolean result = imageFile.delete();
    assertTrue(result);
}
 
Example 13
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void startWithGiftCardWithReceiptCheckDisplay() throws IOException
{
    ActivityController activityController = createActivityWithGiftCard();
    Activity activity = (Activity)activityController.get();
    DBHelper db = new DBHelper(activity);

    db.insertGiftCard("store", "cardId", "value", "receipt");

    activityController.start();
    activityController.visible();
    activityController.resume();

    checkAllFields(activity, "store", "cardId", "value", "receipt", false);
}
 
Example 14
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void startWithoutParametersCannotCreateGiftCard()
{
    ActivityController activityController = Robolectric.buildActivity(GiftCardViewActivity.class).create();
    activityController.start();
    activityController.visible();
    activityController.resume();

    Activity activity = (Activity)activityController.get();
    DBHelper db = new DBHelper(activity);
    assertEquals(0, db.getGiftCardCount());

    final EditText storeField = (EditText) activity.findViewById(R.id.storeName);
    final EditText cardIdField = (EditText) activity.findViewById(R.id.cardId);
    final TextView receiptField = (TextView) activity.findViewById(R.id.receiptLocation);

    final Button saveButton = (Button) activity.findViewById(R.id.saveButton);

    saveButton.performClick();
    assertEquals(0, db.getGiftCardCount());

    storeField.setText("store");
    saveButton.performClick();
    assertEquals(0, db.getGiftCardCount());

    cardIdField.setText("cardId");
    saveButton.performClick();
    assertEquals(0, db.getGiftCardCount());

    receiptField.setText("receipt");
    saveButton.performClick();
    assertEquals(0, db.getGiftCardCount());
}
 
Example 15
Source File: TransactionActivityTest.java    From budget-watch with GNU General Public License v3.0 5 votes vote down vote up
private void checkClickAddWhileOnTap(Integer tab, int expectedType)
{
    ActivityController activityController = Robolectric.buildActivity(TransactionActivity.class).create();
    Activity activity = (Activity)activityController.get();

    activityController.start();
    activityController.resume();
    activityController.visible();

    if(tab != null)
    {
        final ViewPager viewPager = (ViewPager) activity.findViewById(R.id.pager);
        viewPager.setCurrentItem(tab);
    }

    shadowOf(activity).clickMenuItem(R.id.action_add);

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

    ComponentName name = startedIntent.getComponent();
    assertNotNull(name);
    assertEquals("protect.budgetwatch/.TransactionViewActivity", name.flattenToShortString());
    Bundle bundle = startedIntent.getExtras();
    assertNotNull(bundle);

    // Fields which should not be present
    assertEquals(-1, bundle.getInt("id", -1));
    assertEquals(false, bundle.getBoolean("update", false));
    assertEquals(false, bundle.getBoolean("view", false));

    // Check the field which is expected
    assertEquals(expectedType, bundle.getInt("type", -1));
}
 
Example 16
Source File: BudgetActivityTest.java    From budget-watch with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void addOneBudget()
{
    ActivityController activityController = Robolectric.buildActivity(BudgetActivity.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());

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

    DBHelper db = new DBHelper(mainActivity);
    db.insertBudget("name", 100);
    db.close();

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

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

    assertEquals(1, list.getAdapter().getCount());
    Budget budget = (Budget)list.getAdapter().getItem(0);
    assertNotNull(budget);
    assertEquals("name", budget.name);
    assertEquals(100, budget.max);
    assertEquals(0, budget.current);
}
 
Example 17
Source File: GiftCardViewActivityTest.java    From gift-card-guard with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void startWithGiftCardWithReceiptUpdateReceiptCancel() throws IOException
{
    ActivityController activityController = createActivityWithGiftCard();
    Activity activity = (Activity)activityController.get();
    DBHelper db = new DBHelper(activity);

    db.insertGiftCard("store", "cardId", "value", "receipt");

    activityController.start();
    activityController.visible();
    activityController.resume();

    checkAllFields(activity, "store", "cardId", "value", "receipt", false);

    // Add something that will 'handle' the media capture intent
    registerMediaStoreIntentHandler();

    // Complete image capture successfully
    Uri imageLocation = captureImageWithResult(activity, R.id.updateButton, true);

    checkAllFields(activity, "store", "cardId", "value", "receipt", true);

    // Cancel the gift card creation
    final Button cancelButton = (Button) activity.findViewById(R.id.cancelButton);
    assertEquals(false, activity.isFinishing());
    cancelButton.performClick();
    assertEquals(true, activity.isFinishing());
    activityController.destroy();

    // Ensure the image has been deleted
    File imageFile = new File(imageLocation.getPath());
    assertEquals(false, imageFile.exists());
}
 
Example 18
Source File: MainActivityTest.java    From budget-watch with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void testClickImportExport()
{
    ActivityController activityController = Robolectric.buildActivity(MainActivity.class).create();
    Activity activity = (Activity)activityController.get();

    activityController.start();
    activityController.resume();
    activityController.visible();

    shadowOf(activity).clickMenuItem(R.id.action_import_export);
    testNextStartedActivity(activity, "protect.budgetwatch/.ImportExportActivity");
}
 
Example 19
Source File: BudgetActivityTest.java    From budget-watch with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void clickOnBudget()
{
    ActivityController activityController = Robolectric.buildActivity(BudgetActivity.class).create();
    Activity activity = (Activity)activityController.get();

    DBHelper db = new DBHelper(activity);
    db.insertBudget("name", 100);
    db.close();

    activityController.start();
    activityController.resume();

    ListView list = (ListView)activity.findViewById(R.id.list);

    ShadowListView shadowList = shadowOf(list);
    shadowList.populateItems();
    shadowList.performItemClick(0);

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

    ComponentName name = startedIntent.getComponent();
    assertEquals("protect.budgetwatch/.TransactionActivity", name.flattenToShortString());
    Bundle bundle = startedIntent.getExtras();
    String budget = bundle.getString("budget");
    assertEquals("name", budget);
}
 
Example 20
Source File: BudgetViewActivityTest.java    From budget-watch with GNU General Public License v3.0 4 votes vote down vote up
private ActivityController setupActivity(final String budget, int value,
                                         boolean launchAsView, boolean launchAsUpdate)
{
    Intent intent = new Intent();
    final Bundle bundle = new Bundle();

    if(budget != null)
    {
        bundle.putString("id", budget);
    }

    if(launchAsView)
    {
        bundle.putBoolean("view", true);
    }

    if(launchAsUpdate)
    {
        bundle.putBoolean("update", true);
    }

    intent.putExtras(bundle);

    ActivityController activityController = Robolectric.buildActivity(BudgetViewActivity.class, intent).create();

    Activity activity = (Activity)activityController.get();
    DBHelper db = new DBHelper(activity);

    if(budget != null)
    {
        boolean result = db.insertBudget(budget, value);
        assertTrue(result);
    }
    db.close();

    activityController.start();
    activityController.visible();
    activityController.resume();

    return activityController;
}