Search in sources :

Example 11 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerTests method testPermissionResult.

@Test
public void testPermissionResult() {
    final String[] requestedPermissions = new String[] { "test" };
    TestController controller = new TestController();
    CallState expectedCallState = new CallState(true);
    router.pushController(RouterTransaction.with(controller));
    // Ensure that calling handleRequestedPermission w/o requesting a result doesn't do anything
    router.onRequestPermissionsResult("anotherId", 1, requestedPermissions, new int[] { 1 });
    assertCalls(expectedCallState, controller);
    // Ensure requesting the permission gets us the result back
    try {
        controller.requestPermissions(requestedPermissions, 1);
    } catch (NoSuchMethodError ignored) {
    }
    router.onRequestPermissionsResult(controller.getInstanceId(), 1, requestedPermissions, new int[] { 1 });
    expectedCallState.onRequestPermissionsResultCalls++;
    assertCalls(expectedCallState, controller);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 12 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerLifecycleCallbacksTests method testNormalLifecycle.

@Test
public void testNormalLifecycle() {
    TestController controller = new TestController();
    attachLifecycleListener(controller);
    CallState expectedCallState = new CallState(false);
    assertCalls(expectedCallState, controller);
    router.pushController(RouterTransaction.with(controller).pushChangeHandler(getPushHandler(expectedCallState, controller)).popChangeHandler(getPopHandler(expectedCallState, controller)));
    assertCalls(expectedCallState, controller);
    router.popCurrentController();
    assertNull(controller.getView());
    assertCalls(expectedCallState, controller);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 13 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerLifecycleCallbacksTests method testChildLifecycle.

@Test
public void testChildLifecycle() {
    Controller parent = new TestController();
    router.pushController(RouterTransaction.with(parent).pushChangeHandler(MockChangeHandler.defaultHandler()));
    TestController child = new TestController();
    attachLifecycleListener(child);
    CallState expectedCallState = new CallState(false);
    assertCalls(expectedCallState, child);
    Router childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID));
    childRouter.setRoot(RouterTransaction.with(child).pushChangeHandler(getPushHandler(expectedCallState, child)).popChangeHandler(getPopHandler(expectedCallState, child)));
    assertCalls(expectedCallState, child);
    parent.removeChildRouter(childRouter);
    assertCalls(expectedCallState, child);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 14 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerLifecycleCallbacksTests method testLifecycleWithActivityStop.

@Test
public void testLifecycleWithActivityStop() {
    TestController controller = new TestController();
    attachLifecycleListener(controller);
    CallState expectedCallState = new CallState(false);
    assertCalls(expectedCallState, controller);
    router.pushController(RouterTransaction.with(controller).pushChangeHandler(getPushHandler(expectedCallState, controller)));
    assertCalls(expectedCallState, controller);
    activityProxy.getActivity().isDestroying = true;
    activityProxy.pause();
    assertCalls(expectedCallState, controller);
    activityProxy.stop(false);
    expectedCallState.detachCalls++;
    assertCalls(expectedCallState, controller);
    assertNotNull(controller.getView());
    ViewUtils.reportAttached(controller.getView(), false);
    expectedCallState.saveViewStateCalls++;
    expectedCallState.destroyViewCalls++;
    assertCalls(expectedCallState, controller);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 15 with CallState

use of com.bluelinelabs.conductor.util.CallState in project Conductor by bluelinelabs.

the class ControllerLifecycleCallbacksTests method testLifecycleCallOrder.

@Test
public void testLifecycleCallOrder() {
    final TestController testController = new TestController();
    final CallState callState = new CallState(false);
    testController.addLifecycleListener(new LifecycleListener() {

        @Override
        public void preCreateView(@NonNull Controller controller) {
            callState.createViewCalls++;
            assertEquals(1, callState.createViewCalls);
            assertEquals(0, testController.currentCallState.createViewCalls);
            assertEquals(0, callState.attachCalls);
            assertEquals(0, testController.currentCallState.attachCalls);
            assertEquals(0, callState.detachCalls);
            assertEquals(0, testController.currentCallState.detachCalls);
            assertEquals(0, callState.destroyViewCalls);
            assertEquals(0, testController.currentCallState.destroyViewCalls);
            assertEquals(0, callState.destroyCalls);
            assertEquals(0, testController.currentCallState.destroyCalls);
        }

        @Override
        public void postCreateView(@NonNull Controller controller, @NonNull View view) {
            callState.createViewCalls++;
            assertEquals(2, callState.createViewCalls);
            assertEquals(1, testController.currentCallState.createViewCalls);
            assertEquals(0, callState.attachCalls);
            assertEquals(0, testController.currentCallState.attachCalls);
            assertEquals(0, callState.detachCalls);
            assertEquals(0, testController.currentCallState.detachCalls);
            assertEquals(0, callState.destroyViewCalls);
            assertEquals(0, testController.currentCallState.destroyViewCalls);
            assertEquals(0, callState.destroyCalls);
            assertEquals(0, testController.currentCallState.destroyCalls);
        }

        @Override
        public void preAttach(@NonNull Controller controller, @NonNull View view) {
            callState.attachCalls++;
            assertEquals(2, callState.createViewCalls);
            assertEquals(1, testController.currentCallState.createViewCalls);
            assertEquals(1, callState.attachCalls);
            assertEquals(0, testController.currentCallState.attachCalls);
            assertEquals(0, callState.detachCalls);
            assertEquals(0, testController.currentCallState.detachCalls);
            assertEquals(0, callState.destroyViewCalls);
            assertEquals(0, testController.currentCallState.destroyViewCalls);
            assertEquals(0, callState.destroyCalls);
            assertEquals(0, testController.currentCallState.destroyCalls);
        }

        @Override
        public void postAttach(@NonNull Controller controller, @NonNull View view) {
            callState.attachCalls++;
            assertEquals(2, callState.createViewCalls);
            assertEquals(1, testController.currentCallState.createViewCalls);
            assertEquals(2, callState.attachCalls);
            assertEquals(1, testController.currentCallState.attachCalls);
            assertEquals(0, callState.detachCalls);
            assertEquals(0, testController.currentCallState.detachCalls);
            assertEquals(0, callState.destroyViewCalls);
            assertEquals(0, testController.currentCallState.destroyViewCalls);
            assertEquals(0, callState.destroyCalls);
            assertEquals(0, testController.currentCallState.destroyCalls);
        }

        @Override
        public void preDetach(@NonNull Controller controller, @NonNull View view) {
            callState.detachCalls++;
            assertEquals(2, callState.createViewCalls);
            assertEquals(1, testController.currentCallState.createViewCalls);
            assertEquals(2, callState.attachCalls);
            assertEquals(1, testController.currentCallState.attachCalls);
            assertEquals(1, callState.detachCalls);
            assertEquals(0, testController.currentCallState.detachCalls);
            assertEquals(0, callState.destroyViewCalls);
            assertEquals(0, testController.currentCallState.destroyViewCalls);
            assertEquals(0, callState.destroyCalls);
            assertEquals(0, testController.currentCallState.destroyCalls);
        }

        @Override
        public void postDetach(@NonNull Controller controller, @NonNull View view) {
            callState.detachCalls++;
            assertEquals(2, callState.createViewCalls);
            assertEquals(1, testController.currentCallState.createViewCalls);
            assertEquals(2, callState.attachCalls);
            assertEquals(1, testController.currentCallState.attachCalls);
            assertEquals(2, callState.detachCalls);
            assertEquals(1, testController.currentCallState.detachCalls);
            assertEquals(0, callState.destroyViewCalls);
            assertEquals(0, testController.currentCallState.destroyViewCalls);
            assertEquals(0, callState.destroyCalls);
            assertEquals(0, testController.currentCallState.destroyCalls);
        }

        @Override
        public void preDestroyView(@NonNull Controller controller, @NonNull View view) {
            callState.destroyViewCalls++;
            assertEquals(2, callState.createViewCalls);
            assertEquals(1, testController.currentCallState.createViewCalls);
            assertEquals(2, callState.attachCalls);
            assertEquals(1, testController.currentCallState.attachCalls);
            assertEquals(2, callState.detachCalls);
            assertEquals(1, testController.currentCallState.detachCalls);
            assertEquals(1, callState.destroyViewCalls);
            assertEquals(0, testController.currentCallState.destroyViewCalls);
            assertEquals(0, callState.destroyCalls);
            assertEquals(0, testController.currentCallState.destroyCalls);
        }

        @Override
        public void postDestroyView(@NonNull Controller controller) {
            callState.destroyViewCalls++;
            assertEquals(2, callState.createViewCalls);
            assertEquals(1, testController.currentCallState.createViewCalls);
            assertEquals(2, callState.attachCalls);
            assertEquals(1, testController.currentCallState.attachCalls);
            assertEquals(2, callState.detachCalls);
            assertEquals(1, testController.currentCallState.detachCalls);
            assertEquals(2, callState.destroyViewCalls);
            assertEquals(1, testController.currentCallState.destroyViewCalls);
            assertEquals(0, callState.destroyCalls);
            assertEquals(0, testController.currentCallState.destroyCalls);
        }

        @Override
        public void preDestroy(@NonNull Controller controller) {
            callState.destroyCalls++;
            assertEquals(2, callState.createViewCalls);
            assertEquals(1, testController.currentCallState.createViewCalls);
            assertEquals(2, callState.attachCalls);
            assertEquals(1, testController.currentCallState.attachCalls);
            assertEquals(2, callState.detachCalls);
            assertEquals(1, testController.currentCallState.detachCalls);
            assertEquals(2, callState.destroyViewCalls);
            assertEquals(1, testController.currentCallState.destroyViewCalls);
            assertEquals(1, callState.destroyCalls);
            assertEquals(0, testController.currentCallState.destroyCalls);
        }

        @Override
        public void postDestroy(@NonNull Controller controller) {
            callState.destroyCalls++;
            assertEquals(2, callState.createViewCalls);
            assertEquals(1, testController.currentCallState.createViewCalls);
            assertEquals(2, callState.attachCalls);
            assertEquals(1, testController.currentCallState.attachCalls);
            assertEquals(2, callState.detachCalls);
            assertEquals(1, testController.currentCallState.detachCalls);
            assertEquals(2, callState.destroyViewCalls);
            assertEquals(1, testController.currentCallState.destroyViewCalls);
            assertEquals(2, callState.destroyCalls);
            assertEquals(1, testController.currentCallState.destroyCalls);
        }
    });
    router.pushController(RouterTransaction.with(testController).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    router.popController(testController);
    assertEquals(2, callState.createViewCalls);
    assertEquals(2, callState.attachCalls);
    assertEquals(2, callState.detachCalls);
    assertEquals(2, callState.destroyViewCalls);
    assertEquals(2, callState.destroyCalls);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) LifecycleListener(com.bluelinelabs.conductor.Controller.LifecycleListener) CallState(com.bluelinelabs.conductor.util.CallState) TestController(com.bluelinelabs.conductor.util.TestController) View(android.view.View) Test(org.junit.Test)

Aggregations

CallState (com.bluelinelabs.conductor.util.CallState)15 TestController (com.bluelinelabs.conductor.util.TestController)14 Test (org.junit.Test)14 ViewGroup (android.view.ViewGroup)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 View (android.view.View)1 LifecycleListener (com.bluelinelabs.conductor.Controller.LifecycleListener)1 Before (org.junit.Before)1