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

The following examples show how to use org.robolectric.android.controller.ActivityController#destroy() . 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: 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 2
Source File: NavigationSceneUtilityTests.java    From scene with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetupInActivityOnStart() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start();
    TestActivity activity = controller.get();
    SceneDelegate sceneDelegate = NavigationSceneUtility.setupWithActivity(activity, TestScene.class).build();
    NavigationScene navigationScene = sceneDelegate.getNavigationScene();
    assertNotNull(navigationScene);
    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: GroupSceneUtilityTests.java    From scene with Apache License 2.0 6 votes vote down vote up
@LooperMode(PAUSED)
@Test
public void testNotImmediateSetupInActivityOnResume() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume();
    TestActivity activity = controller.get();
    GroupSceneDelegate sceneDelegate = GroupSceneUtility.setupWithActivity(activity, TestScene.class).immediate(false).build();
    GroupScene groupScene = sceneDelegate.getGroupScene();
    assertNotNull(groupScene);

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

    controller.pause();
    assertEquals(State.STARTED, groupScene.getState());
    controller.stop();
    assertEquals(State.ACTIVITY_CREATED, groupScene.getState());
    controller.destroy();
    assertEquals(State.NONE, groupScene.getState());
}
 
Example 5
Source File: NavigationSceneUtilityTests.java    From scene with Apache License 2.0 6 votes vote down vote up
@LooperMode(PAUSED)
@Test
public void testNotImmediateSetupInActivityOnResume() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume();
    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.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 6
Source File: ViewModelUtilTest.java    From toothpick with Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseOnClear() {
  // GIVEN
  ActivityController<FragmentActivity> activityController =
      Robolectric.buildActivity(FragmentActivity.class).create();
  FragmentActivity activity = activityController.get();
  Application application = ApplicationProvider.getApplicationContext();
  Scope activityScope = Toothpick.openScopes(application, activity);

  // WHEN
  ViewModelUtil.closeOnViewModelCleared(activity, activityScope);
  activityController.destroy();

  // THEN
  assertThat(Toothpick.isScopeOpen(activity), is(false));
}
 
Example 7
Source File: LifecycleUtilTest.java    From toothpick with Apache License 2.0 6 votes vote down vote up
@Test
public void testCloseOnDestroy() {
  // GIVEN
  ActivityController<FragmentActivity> activityController =
      Robolectric.buildActivity(FragmentActivity.class).create();
  FragmentActivity activity = activityController.get();
  Application application = ApplicationProvider.getApplicationContext();
  Scope activityScope = Toothpick.openScopes(application, activity);

  // WHEN
  LifecycleUtil.closeOnDestroy(activity, activityScope);
  activityController.destroy();

  // THEN
  assertThat(Toothpick.isScopeOpen(activity), is(false));
}
 
Example 8
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 9
Source File: NavigationSceneUtilityTests.java    From scene with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetupInActivityOnStop() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume().pause().stop();
    TestActivity activity = controller.get();
    SceneDelegate sceneDelegate = NavigationSceneUtility.setupWithActivity(activity, TestScene.class).build();
    NavigationScene navigationScene = sceneDelegate.getNavigationScene();
    assertNotNull(navigationScene);
    assertEquals(State.ACTIVITY_CREATED, navigationScene.getState());
    controller.destroy();
    assertEquals(State.NONE, navigationScene.getState());
}
 
Example 10
Source File: AndroidLifecycleFragmentTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
private void testBindToLifecycle(LifecycleOwner owner) {
    Fragment fragment = (Fragment) owner;
    LifecycleProvider<Lifecycle.Event> provider = AndroidLifecycle.createLifecycleProvider(owner);
    ActivityController<?> controller = startFragment(fragment);

    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 11
Source File: GroupSceneUtilityTests.java    From scene with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetupInActivityOnPause() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume().pause();
    TestActivity activity = controller.get();
    GroupSceneDelegate sceneDelegate = GroupSceneUtility.setupWithActivity(activity, TestScene.class).build();
    GroupScene groupScene = sceneDelegate.getGroupScene();
    assertNotNull(groupScene);
    assertEquals(State.STARTED, groupScene.getState());
    controller.stop();
    assertEquals(State.ACTIVITY_CREATED, groupScene.getState());
    controller.destroy();
    assertEquals(State.NONE, groupScene.getState());
}
 
Example 12
Source File: GroupSceneUtilityTests.java    From scene with Apache License 2.0 5 votes vote down vote up
@Test
public void testSetupInActivityOnResume() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume();
    TestActivity activity = controller.get();
    GroupSceneDelegate sceneDelegate = GroupSceneUtility.setupWithActivity(activity, TestScene.class).build();
    GroupScene groupScene = sceneDelegate.getGroupScene();
    assertNotNull(groupScene);
    assertEquals(State.RESUMED, groupScene.getState());
    controller.pause();
    assertEquals(State.STARTED, groupScene.getState());
    controller.stop();
    assertEquals(State.ACTIVITY_CREATED, groupScene.getState());
    controller.destroy();
    assertEquals(State.NONE, groupScene.getState());
}
 
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 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 14
Source File: RxActivityLifecycleTest.java    From RxLifecycle with Apache License 2.0 5 votes vote down vote up
private void testBindToLifecycle(ActivityController<? extends LifecycleProvider<ActivityEvent>> controller) {
    LifecycleProvider<ActivityEvent> activity = controller.get();

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

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

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

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

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

    controller.destroy();
    createObserver.assertComplete();
    stopObserver.assertComplete();
}
 
Example 15
Source File: NavigationSceneUtilityTests.java    From scene with Apache License 2.0 5 votes vote down vote up
@LooperMode(PAUSED)
@Test
public void testNotImmediateSetupInActivityOnStop() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume().pause().stop();
    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.destroy();
    assertEquals(State.NONE, navigationScene.getState());
}
 
Example 16
Source File: TestActivityTest.java    From Awesome-WanAndroid with Apache License 2.0 5 votes vote down vote up
@Test
public void testActivityLifecycle() {
    ActivityController<TestActivity> activityController =
            Robolectric.buildActivity(TestActivity.class);
    TestActivity testActivity = activityController.get();
    Assert.assertNull(testActivity.getLifeCycleStatus());

    activityController.create();
    Assert.assertEquals("onCreate", testActivity.getLifeCycleStatus());

    activityController.start();
    Assert.assertEquals("onStart", testActivity.getLifeCycleStatus());

    activityController.resume();
    Assert.assertEquals("onResume", testActivity.getLifeCycleStatus());

    activityController.pause();
    Assert.assertEquals("onPause", testActivity.getLifeCycleStatus());

    activityController.stop();
    Assert.assertEquals("onStop", testActivity.getLifeCycleStatus());

    activityController.restart();
    Assert.assertEquals("onStart", testActivity.getLifeCycleStatus());

    activityController.destroy();
    Assert.assertEquals("onDestroy", testActivity.getLifeCycleStatus());
}
 
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: TransactionViewActivityTest.java    From budget-watch with GNU General Public License v3.0 5 votes vote down vote up
@Test
public void startAsEditWithExpenseWithReceiptUpdateReceiptCancel() throws IOException
{
    ActivityController activityController = setupActivity("budget", "receipt", false, true);
    Activity activity = (Activity)activityController.get();

    checkAllFields(activity, "description", "account", "budget", "budget", "100.10", "note", nowString,
            "receipt", false, false);

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

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

    checkAllFields(activity, "description", "account", "budget", "budget", "100.10", "note", nowString,
            "receipt", true, false);

    // Cancel the expense update
    assertEquals(false, activity.isFinishing());
    shadowOf(activity).clickMenuItem(android.R.id.home);
    assertEquals(true, activity.isFinishing());
    activityController.destroy();

    // Ensure the image has been deleted
    File imageFile = new File(imageLocation.getPath());
    assertEquals(false, imageFile.exists());
}
 
Example 19
Source File: GroupSceneUtilityTests.java    From scene with Apache License 2.0 5 votes vote down vote up
@LooperMode(PAUSED)
@Test
public void testNotImmediateSetupInActivityOnStop() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create().start().resume().pause().stop();
    TestActivity activity = controller.get();
    GroupSceneDelegate sceneDelegate = GroupSceneUtility.setupWithActivity(activity, TestScene.class).immediate(false).build();
    GroupScene groupScene = sceneDelegate.getGroupScene();
    assertNotNull(groupScene);

    assertEquals(State.NONE, groupScene.getState());
    shadowOf(getMainLooper()).idle();//execute Handler posted task
    assertEquals(State.ACTIVITY_CREATED, groupScene.getState());
    controller.destroy();
    assertEquals(State.NONE, groupScene.getState());
}
 
Example 20
Source File: NavigationSceneCompatUtility_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);
}