Search in sources :

Example 61 with TestController

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

the class ControllerTests method testViewRetention.

@Test
public void testViewRetention() {
    Controller controller = new TestController();
    controller.setRouter(router);
    // Test View getting released w/ RELEASE_DETACH
    controller.setRetainViewMode(RetainViewMode.RELEASE_DETACH);
    assertNull(controller.getView());
    View view = controller.inflate(router.container);
    assertNotNull(controller.getView());
    ViewUtils.reportAttached(view, true);
    assertNotNull(controller.getView());
    ViewUtils.reportAttached(view, false);
    assertNull(controller.getView());
    // Test View getting retained w/ RETAIN_DETACH
    controller.setRetainViewMode(RetainViewMode.RETAIN_DETACH);
    view = controller.inflate(router.container);
    assertNotNull(controller.getView());
    ViewUtils.reportAttached(view, true);
    assertNotNull(controller.getView());
    ViewUtils.reportAttached(view, false);
    assertNotNull(controller.getView());
    // Ensure re-setting RELEASE_DETACH releases
    controller.setRetainViewMode(RetainViewMode.RELEASE_DETACH);
    assertNull(controller.getView());
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) View(android.view.View) Test(org.junit.Test)

Example 62 with TestController

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

the class ControllerTransactionTests method testRouterSaveRestore.

@Test
public void testRouterSaveRestore() {
    RouterTransaction transaction = RouterTransaction.with(new TestController()).pushChangeHandler(new HorizontalChangeHandler()).popChangeHandler(new VerticalChangeHandler()).tag("Test Tag");
    Bundle bundle = transaction.saveInstanceState();
    RouterTransaction restoredTransaction = new RouterTransaction(bundle);
    assertEquals(transaction.controller.getClass(), restoredTransaction.controller.getClass());
    assertEquals(transaction.pushChangeHandler().getClass(), restoredTransaction.pushChangeHandler().getClass());
    assertEquals(transaction.popChangeHandler().getClass(), restoredTransaction.popChangeHandler().getClass());
    assertEquals(transaction.tag(), restoredTransaction.tag());
}
Also used : Bundle(android.os.Bundle) TestController(com.bluelinelabs.conductor.util.TestController) VerticalChangeHandler(com.bluelinelabs.conductor.changehandler.VerticalChangeHandler) HorizontalChangeHandler(com.bluelinelabs.conductor.changehandler.HorizontalChangeHandler) Test(org.junit.Test)

Example 63 with TestController

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

the class ReattachCaseTests method testChildNeedsAttachOnPauseAndOrientation.

@Test
public void testChildNeedsAttachOnPauseAndOrientation() {
    final Controller controllerA = new TestController();
    final Controller childController = new TestController();
    final Controller controllerB = new TestController();
    router.pushController(RouterTransaction.with(controllerA).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    Router childRouter = controllerA.getChildRouter((ViewGroup) controllerA.getView().findViewById(TestController.VIEW_ID));
    childRouter.pushController(RouterTransaction.with(childController).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    assertTrue(controllerA.isAttached());
    assertTrue(childController.isAttached());
    assertFalse(controllerB.isAttached());
    sleepWakeDevice();
    assertTrue(controllerA.isAttached());
    assertTrue(childController.isAttached());
    assertFalse(controllerB.isAttached());
    router.pushController(RouterTransaction.with(controllerB).pushChangeHandler(MockChangeHandler.defaultHandler()).popChangeHandler(MockChangeHandler.defaultHandler()));
    assertFalse(controllerA.isAttached());
    assertFalse(childController.isAttached());
    assertTrue(controllerB.isAttached());
    activityProxy.rotate();
    router.rebindIfNeeded();
    assertFalse(controllerA.isAttached());
    assertFalse(childController.isAttached());
    assertTrue(childController.getNeedsAttach());
    assertTrue(controllerB.isAttached());
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 64 with TestController

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

the class RouterChangeHandlerTests method testSetRootHandler.

@Test
public void testSetRootHandler() {
    MockChangeHandler handler = MockChangeHandler.taggedHandler("root", true);
    TestController rootController = new TestController();
    router.setRoot(RouterTransaction.with(rootController).pushChangeHandler(handler));
    assertTrue(rootController.changeHandlerHistory.isValidHistory);
    assertNull(rootController.changeHandlerHistory.latestFromView());
    assertNotNull(rootController.changeHandlerHistory.latestToView());
    assertEquals(rootController.getView(), rootController.changeHandlerHistory.latestToView());
    assertTrue(rootController.changeHandlerHistory.latestIsPush());
    assertEquals(handler.tag, rootController.changeHandlerHistory.latestChangeHandler().tag);
}
Also used : MockChangeHandler(com.bluelinelabs.conductor.util.MockChangeHandler) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 65 with TestController

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

the class RouterTests method testNewSetBackstack.

@Test
public void testNewSetBackstack() {
    router.setRoot(RouterTransaction.with(new TestController()));
    assertEquals(1, router.getBackstackSize());
    RouterTransaction rootTransaction = RouterTransaction.with(new TestController());
    RouterTransaction middleTransaction = RouterTransaction.with(new TestController());
    RouterTransaction topTransaction = RouterTransaction.with(new TestController());
    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));
    assertEquals(router, rootTransaction.controller.getRouter());
    assertEquals(router, middleTransaction.controller.getRouter());
    assertEquals(router, topTransaction.controller.getRouter());
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) 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