Search in sources :

Example 36 with TestController

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

the class ControllerLifecycleActivityReferenceTests method testSingleControllerActivityOnPop.

@Test
public void testSingleControllerActivityOnPop() {
    Controller controller = new TestController();
    ActivityReferencingLifecycleListener listener = new ActivityReferencingLifecycleListener();
    controller.addLifecycleListener(listener);
    router.pushController(RouterTransaction.with(controller).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    router.popCurrentController();
    assertEquals(Arrays.asList(true, true), listener.changeEndReferences);
    assertEquals(Collections.singletonList(true), listener.postCreateViewReferences);
    assertEquals(Collections.singletonList(true), listener.postAttachReferences);
    assertEquals(Collections.singletonList(true), listener.postDetachReferences);
    assertEquals(Collections.singletonList(true), listener.postDestroyViewReferences);
    assertEquals(Collections.singletonList(true), listener.postDestroyReferences);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 37 with TestController

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

the class ControllerLifecycleActivityReferenceTests method testSingleControllerActivityOnDestroy.

@Test
public void testSingleControllerActivityOnDestroy() {
    Controller controller = new TestController();
    ActivityReferencingLifecycleListener listener = new ActivityReferencingLifecycleListener();
    controller.addLifecycleListener(listener);
    router.pushController(RouterTransaction.with(controller).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    activityProxy.pause().stop(false).destroy();
    assertEquals(Collections.singletonList(true), listener.changeEndReferences);
    assertEquals(Collections.singletonList(true), listener.postCreateViewReferences);
    assertEquals(Collections.singletonList(true), listener.postAttachReferences);
    assertEquals(Collections.singletonList(true), listener.postDetachReferences);
    assertEquals(Collections.singletonList(true), listener.postDestroyViewReferences);
    assertEquals(Collections.singletonList(true), listener.postDestroyReferences);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 38 with TestController

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

the class ControllerLifecycleActivityReferenceTests method testChildControllerActivityOnPop.

@Test
public void testChildControllerActivityOnPop() {
    Controller parent = new TestController();
    router.pushController(RouterTransaction.with(parent).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    TestController child = new TestController();
    ActivityReferencingLifecycleListener listener = new ActivityReferencingLifecycleListener();
    child.addLifecycleListener(listener);
    Router childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID));
    childRouter.setPopsLastView(true);
    childRouter.pushController(RouterTransaction.with(child).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    childRouter.popCurrentController();
    assertEquals(Arrays.asList(true, true), listener.changeEndReferences);
    assertEquals(Collections.singletonList(true), listener.postCreateViewReferences);
    assertEquals(Collections.singletonList(true), listener.postAttachReferences);
    assertEquals(Collections.singletonList(true), listener.postDetachReferences);
    assertEquals(Collections.singletonList(true), listener.postDestroyViewReferences);
    assertEquals(Collections.singletonList(true), listener.postDestroyReferences);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 39 with TestController

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

the class ControllerLifecycleActivityReferenceTests method testSingleControllerActivityOnPush.

@Test
public void testSingleControllerActivityOnPush() {
    Controller controller = new TestController();
    assertNull(controller.getActivity());
    ActivityReferencingLifecycleListener listener = new ActivityReferencingLifecycleListener();
    controller.addLifecycleListener(listener);
    router.pushController(RouterTransaction.with(controller).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    assertEquals(Collections.singletonList(true), listener.changeEndReferences);
    assertEquals(Collections.singletonList(true), listener.postCreateViewReferences);
    assertEquals(Collections.singletonList(true), listener.postAttachReferences);
    assertEquals(Collections.emptyList(), listener.postDetachReferences);
    assertEquals(Collections.emptyList(), listener.postDestroyViewReferences);
    assertEquals(Collections.emptyList(), listener.postDestroyReferences);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 40 with TestController

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

the class ControllerLifecycleCallbacksTests method testLifecycleCallOrder.

@Test
public void testLifecycleCallOrder() {
    final TestController testController = new TestController();
    final CallState callState = new CallState();
    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

TestController (com.bluelinelabs.conductor.util.TestController)65 Test (org.junit.Test)64 CallState (com.bluelinelabs.conductor.util.CallState)14 View (android.view.View)6 ViewGroup (android.view.ViewGroup)5 MockChangeHandler (com.bluelinelabs.conductor.util.MockChangeHandler)5 Bundle (android.os.Bundle)4 HorizontalChangeHandler (com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler)3 Intent (android.content.Intent)2 FadeChangeHandler (com.bluelinelabs.conductor.changehandler.FadeChangeHandler)2 LifecycleListener (com.bluelinelabs.conductor.Controller.LifecycleListener)1 VerticalChangeHandler (com.bluelinelabs.conductor.changehandler.VerticalChangeHandler)1 ActivityProxy (com.bluelinelabs.conductor.util.ActivityProxy)1