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

The following examples show how to use org.robolectric.android.controller.ActivityController#stop() . 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: 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 2
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 3
Source File: GroupSceneUtilityTests.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();
    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.STARTED, groupScene.getState());

    controller.resume();
    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 4
Source File: GroupSceneUtilityTests.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();
    GroupSceneDelegate sceneDelegate = GroupSceneUtility.setupWithActivity(activity, TestScene.class).build();
    GroupScene groupScene = sceneDelegate.getGroupScene();
    assertNotNull(groupScene);
    assertEquals(State.STARTED, groupScene.getState());
    controller.resume();
    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: RxActivityLifecycleTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(ActivityController<? extends LifecycleProvider<ActivityEvent>> controller) {
    LifecycleProvider<ActivityEvent> activity = controller.get();

    TestObserver<Object> testObserver = observable.compose(activity.bindUntilEvent(STOP)).test();

    controller.create();
    testObserver.assertNotComplete();
    controller.start();
    testObserver.assertNotComplete();
    controller.resume();
    testObserver.assertNotComplete();
    controller.pause();
    testObserver.assertNotComplete();
    controller.stop();
    testObserver.assertComplete();
}
 
Example 6
Source File: AndroidLifecycleActivityTest.java    From RxLifecycle with Apache License 2.0 6 votes vote down vote up
private void testBindUntilEvent(ActivityController<? extends LifecycleOwner> controller) {
    LifecycleProvider<Lifecycle.Event> activity = AndroidLifecycle.createLifecycleProvider(controller.get());

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

    controller.create();
    testObserver.assertNotComplete();
    controller.start();
    testObserver.assertNotComplete();
    controller.resume();
    testObserver.assertNotComplete();
    controller.pause();
    testObserver.assertNotComplete();
    controller.stop();
    testObserver.assertComplete();
}
 
Example 7
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 8
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 9
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 10
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 11
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 12
Source File: NavigationSceneUtilityTests.java    From scene with Apache License 2.0 6 votes vote down vote up
@Test
public void testSetupInActivityOnCreate() {
    ActivityController<TestActivity> controller = Robolectric.buildActivity(TestActivity.class).create();
    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.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 13
Source File: NavigationSceneUtilityTests.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();
    SceneDelegate sceneDelegate = NavigationSceneUtility.setupWithActivity(activity, TestScene.class).build();
    NavigationScene navigationScene = sceneDelegate.getNavigationScene();
    assertNotNull(navigationScene);
    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 14
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 15
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 16
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 17
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 18
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 19
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 20
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();
}