Search in sources :

Example 16 with TestController

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

the class RouterChangeHandlerTests method testPushPopHandlers.

@Test
public void testPushPopHandlers() {
    TestController rootController = new TestController();
    router.setRoot(RouterTransaction.with(rootController).pushChangeHandler(MockChangeHandler.defaultHandler()));
    View rootView = rootController.getView();
    MockChangeHandler pushHandler = MockChangeHandler.taggedHandler("push", true);
    MockChangeHandler popHandler = MockChangeHandler.taggedHandler("pop", true);
    TestController pushController = new TestController();
    router.pushController(RouterTransaction.with(pushController).pushChangeHandler(pushHandler).popChangeHandler(popHandler));
    assertTrue(rootController.changeHandlerHistory.isValidHistory);
    assertTrue(pushController.changeHandlerHistory.isValidHistory);
    assertNotNull(pushController.changeHandlerHistory.latestFromView());
    assertNotNull(pushController.changeHandlerHistory.latestToView());
    assertEquals(rootView, pushController.changeHandlerHistory.latestFromView());
    assertEquals(pushController.getView(), pushController.changeHandlerHistory.latestToView());
    assertTrue(pushController.changeHandlerHistory.latestIsPush());
    assertEquals(pushHandler.tag, pushController.changeHandlerHistory.latestChangeHandler().tag);
    View pushView = pushController.getView();
    router.popController(pushController);
    assertNotNull(pushController.changeHandlerHistory.latestFromView());
    assertNotNull(pushController.changeHandlerHistory.latestToView());
    assertEquals(pushView, pushController.changeHandlerHistory.fromViewAt(1));
    assertEquals(rootController.getView(), pushController.changeHandlerHistory.latestToView());
    assertFalse(pushController.changeHandlerHistory.latestIsPush());
    assertEquals(popHandler.tag, pushController.changeHandlerHistory.latestChangeHandler().tag);
}
Also used : MockChangeHandler(com.bluelinelabs.conductor.util.MockChangeHandler) TestController(com.bluelinelabs.conductor.util.TestController) View(android.view.View) Test(org.junit.Test)

Example 17 with TestController

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

the class RouterTests method testNewSetBackstackWithNoRemoveViewOnPush.

@Test
public void testNewSetBackstackWithNoRemoveViewOnPush() {
    RouterTransaction oldRootTransaction = RouterTransaction.with(new TestController());
    RouterTransaction oldTopTransaction = RouterTransaction.with(new TestController()).pushChangeHandler(MockChangeHandler.noRemoveViewOnPushHandler());
    router.setRoot(oldRootTransaction);
    router.pushController(oldTopTransaction);
    assertEquals(2, router.getBackstackSize());
    assertTrue(oldRootTransaction.controller.isAttached());
    assertTrue(oldTopTransaction.controller.isAttached());
    RouterTransaction rootTransaction = RouterTransaction.with(new TestController());
    RouterTransaction middleTransaction = RouterTransaction.with(new TestController()).pushChangeHandler(MockChangeHandler.noRemoveViewOnPushHandler());
    RouterTransaction topTransaction = RouterTransaction.with(new TestController()).pushChangeHandler(MockChangeHandler.noRemoveViewOnPushHandler());
    List<RouterTransaction> backstack = Arrays.asList(rootTransaction, middleTransaction, topTransaction);
    router.setBackstack(backstack, null);
    assertEquals(3, router.getBackstackSize());
    List<RouterTransaction> fetchedBackstack = router.getBackstack();
    assertEquals(rootTransaction, fetchedBackstack.get(0));
    assertEquals(middleTransaction, fetchedBackstack.get(1));
    assertEquals(topTransaction, fetchedBackstack.get(2));
    assertFalse(oldRootTransaction.controller.isAttached());
    assertFalse(oldTopTransaction.controller.isAttached());
    assertTrue(rootTransaction.controller.isAttached());
    assertTrue(middleTransaction.controller.isAttached());
    assertTrue(topTransaction.controller.isAttached());
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 18 with TestController

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

the class RouterTests method testGetByInstanceId.

@Test
public void testGetByInstanceId() {
    Controller controller = new TestController();
    router.pushController(RouterTransaction.with(controller));
    assertEquals(controller, router.getControllerWithInstanceId(controller.getInstanceId()));
    assertNull(router.getControllerWithInstanceId("fake id"));
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 19 with TestController

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

the class ControllerLifecycleCallbacksTests method testChildLifecycle2.

@Test
public void testChildLifecycle2() {
    Controller parent = new TestController();
    router.pushController(RouterTransaction.with(parent).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    TestController child = new TestController();
    attachLifecycleListener(child);
    CallState expectedCallState = new CallState();
    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);
    router.popCurrentController();
    expectedCallState.detachCalls++;
    expectedCallState.destroyViewCalls++;
    expectedCallState.destroyCalls++;
    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 20 with TestController

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

the class ControllerLifecycleCallbacksTests method testLifecycleWithActivityConfigurationChange.

@Test
public void testLifecycleWithActivityConfigurationChange() {
    TestController controller = new TestController();
    attachLifecycleListener(controller);
    CallState expectedCallState = new CallState();
    assertCalls(expectedCallState, controller);
    router.pushController(RouterTransaction.with(controller).pushChangeHandler(getPushHandler(expectedCallState, controller)).tag("root"));
    assertCalls(expectedCallState, controller);
    activityProxy.getActivity().isChangingConfigurations = true;
    Bundle bundle = new Bundle();
    activityProxy.saveInstanceState(bundle);
    expectedCallState.saveViewStateCalls++;
    expectedCallState.saveInstanceStateCalls++;
    assertCalls(expectedCallState, controller);
    activityProxy.pause();
    assertCalls(expectedCallState, controller);
    activityProxy.stop(true);
    expectedCallState.detachCalls++;
    expectedCallState.destroyViewCalls++;
    assertCalls(expectedCallState, controller);
    activityProxy.destroy();
    assertCalls(expectedCallState, controller);
    createActivityController(bundle, false);
    controller = (TestController) router.getControllerWithTag("root");
    expectedCallState.restoreInstanceStateCalls++;
    expectedCallState.restoreViewStateCalls++;
    expectedCallState.changeStartCalls++;
    expectedCallState.createViewCalls++;
    // Lifecycle listener isn't attached during restore, grab the current views from the controller for this stuff...
    currentCallState.restoreInstanceStateCalls = controller.currentCallState.restoreInstanceStateCalls;
    currentCallState.restoreViewStateCalls = controller.currentCallState.restoreViewStateCalls;
    currentCallState.changeStartCalls = controller.currentCallState.changeStartCalls;
    currentCallState.changeEndCalls = controller.currentCallState.changeEndCalls;
    currentCallState.createViewCalls = controller.currentCallState.createViewCalls;
    currentCallState.attachCalls = controller.currentCallState.attachCalls;
    assertCalls(expectedCallState, controller);
    activityProxy.start().resume();
    currentCallState.changeEndCalls = controller.currentCallState.changeEndCalls;
    currentCallState.attachCalls = controller.currentCallState.attachCalls;
    expectedCallState.changeEndCalls++;
    expectedCallState.attachCalls++;
    assertCalls(expectedCallState, controller);
    activityProxy.resume();
    assertCalls(expectedCallState, controller);
}
Also used : Bundle(android.os.Bundle) TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) 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