Search in sources :

Example 56 with TestController

use of com.bluelinelabs.conductor.util.TestController 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();
    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 57 with TestController

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

the class ControllerTests method testOptionsMenuForChild.

@Test
public void testOptionsMenuForChild() {
    TestController parent = new TestController();
    TestController child = new TestController();
    router.pushController(RouterTransaction.with(parent));
    parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID)).setRoot(RouterTransaction.with(child));
    CallState childExpectedCallState = new CallState(true);
    CallState parentExpectedCallState = new CallState(true);
    // Ensure that calling onCreateOptionsMenu w/o declaring that we have one doesn't do anything
    router.onCreateOptionsMenu(null, null);
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure calling onCreateOptionsMenu with a menu works
    child.setHasOptionsMenu(true);
    // Ensure it'll still get called back next time onCreateOptionsMenu is called
    router.onCreateOptionsMenu(null, null);
    childExpectedCallState.createOptionsMenuCalls++;
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure we stop getting them when we hide it
    child.setOptionsMenuHidden(true);
    router.onCreateOptionsMenu(null, null);
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure we get the callback them when we un-hide it
    child.setOptionsMenuHidden(false);
    router.onCreateOptionsMenu(null, null);
    childExpectedCallState.createOptionsMenuCalls++;
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure we don't get the callback when we no longer have a menu
    child.setHasOptionsMenu(false);
    router.onCreateOptionsMenu(null, null);
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
}
Also used : ViewGroup(android.view.ViewGroup) TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 58 with TestController

use of com.bluelinelabs.conductor.util.TestController 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 59 with TestController

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

the class ControllerTests method testAddRemoveChildRouters.

@Test
public void testAddRemoveChildRouters() {
    TestController parent = new TestController();
    TestController child1 = new TestController();
    TestController child2 = new TestController();
    router.pushController(RouterTransaction.with(parent));
    assertEquals(0, parent.getChildRouters().size());
    assertNull(child1.getParentController());
    assertNull(child2.getParentController());
    Router childRouter1 = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.CHILD_VIEW_ID_1));
    Router childRouter2 = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.CHILD_VIEW_ID_2));
    childRouter1.setRoot(RouterTransaction.with(child1));
    childRouter2.setRoot(RouterTransaction.with(child2));
    assertEquals(2, parent.getChildRouters().size());
    assertEquals(childRouter1, parent.getChildRouters().get(0));
    assertEquals(childRouter2, parent.getChildRouters().get(1));
    assertEquals(1, childRouter1.getBackstackSize());
    assertEquals(1, childRouter2.getBackstackSize());
    assertEquals(child1, childRouter1.getControllers().get(0));
    assertEquals(child2, childRouter2.getControllers().get(0));
    assertEquals(parent, child1.getParentController());
    assertEquals(parent, child2.getParentController());
    parent.removeChildRouter(childRouter2);
    assertEquals(1, parent.getChildRouters().size());
    assertEquals(childRouter1, parent.getChildRouters().get(0));
    assertEquals(1, childRouter1.getBackstackSize());
    assertEquals(0, childRouter2.getBackstackSize());
    assertEquals(child1, childRouter1.getControllers().get(0));
    assertEquals(parent, child1.getParentController());
    assertNull(child2.getParentController());
    parent.removeChildRouter(childRouter1);
    assertEquals(0, parent.getChildRouters().size());
    assertEquals(0, childRouter1.getBackstackSize());
    assertEquals(0, childRouter2.getBackstackSize());
    assertNull(child1.getParentController());
    assertNull(child2.getParentController());
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 60 with TestController

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

the class ControllerTests method testRestoredChildRouterBackstack.

@Test
public void testRestoredChildRouterBackstack() {
    TestController parent = new TestController();
    router.pushController(RouterTransaction.with(parent));
    ViewUtils.reportAttached(parent.getView(), true);
    RouterTransaction childTransaction1 = RouterTransaction.with(new TestController());
    RouterTransaction childTransaction2 = RouterTransaction.with(new TestController());
    Router childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.CHILD_VIEW_ID_1));
    childRouter.setPopsLastView(true);
    childRouter.setRoot(childTransaction1);
    childRouter.pushController(childTransaction2);
    Bundle savedState = new Bundle();
    childRouter.saveInstanceState(savedState);
    parent.removeChildRouter(childRouter);
    childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.CHILD_VIEW_ID_1));
    assertEquals(0, childRouter.getBackstackSize());
    childRouter.restoreInstanceState(savedState);
    childRouter.rebindIfNeeded();
    assertEquals(2, childRouter.getBackstackSize());
    RouterTransaction restoredChildTransaction1 = childRouter.getBackstack().get(0);
    RouterTransaction restoredChildTransaction2 = childRouter.getBackstack().get(1);
    assertEquals(childTransaction1.transactionIndex, restoredChildTransaction1.transactionIndex);
    assertEquals(childTransaction1.controller.getInstanceId(), restoredChildTransaction1.controller.getInstanceId());
    assertEquals(childTransaction2.transactionIndex, restoredChildTransaction2.transactionIndex);
    assertEquals(childTransaction2.controller.getInstanceId(), restoredChildTransaction2.controller.getInstanceId());
    assertTrue(parent.handleBack());
    assertEquals(1, childRouter.getBackstackSize());
    assertEquals(restoredChildTransaction1, childRouter.getBackstack().get(0));
    assertTrue(parent.handleBack());
    assertEquals(0, childRouter.getBackstackSize());
}
Also used : Bundle(android.os.Bundle) ViewGroup(android.view.ViewGroup) 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