Search in sources :

Example 21 with TestController

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

the class ControllerLifecycleCallbacksTests method testLifecycleWithActivityBackground.

@Test
public void testLifecycleWithActivityBackground() {
    TestController controller = new TestController();
    attachLifecycleListener(controller);
    CallState expectedCallState = new CallState();
    assertCalls(expectedCallState, controller);
    router.pushController(RouterTransaction.with(controller).pushChangeHandler(getPushHandler(expectedCallState, controller)));
    assertCalls(expectedCallState, controller);
    activityProxy.pause();
    Bundle bundle = new Bundle();
    activityProxy.saveInstanceState(bundle);
    expectedCallState.saveInstanceStateCalls++;
    expectedCallState.saveViewStateCalls++;
    assertCalls(expectedCallState, controller);
    activityProxy.resume();
}
Also used : Bundle(android.os.Bundle) TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 22 with TestController

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

the class ControllerLifecycleCallbacksTests method testLifecycleWithActivityDestroy.

@Test
public void testLifecycleWithActivityDestroy() {
    TestController controller = new TestController();
    attachLifecycleListener(controller);
    CallState expectedCallState = new CallState();
    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(true);
    expectedCallState.saveViewStateCalls++;
    expectedCallState.detachCalls++;
    expectedCallState.destroyViewCalls++;
    assertCalls(expectedCallState, controller);
    activityProxy.destroy();
    expectedCallState.destroyCalls++;
    assertCalls(expectedCallState, controller);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 23 with TestController

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

the class ControllerTests method testActivityResultForChild.

@Test
public void testActivityResultForChild() {
    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 onActivityResult w/o requesting a result doesn't do anything
    router.onActivityResult(1, Activity.RESULT_OK, null);
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure starting an activity for result gets us the result back
    child.startActivityForResult(new Intent("action"), 1);
    router.onActivityResult(1, Activity.RESULT_OK, null);
    childExpectedCallState.onActivityResultCalls++;
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure requesting a result w/o calling startActivityForResult works
    child.registerForActivityResult(2);
    router.onActivityResult(2, Activity.RESULT_OK, null);
    childExpectedCallState.onActivityResultCalls++;
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
}
Also used : ViewGroup(android.view.ViewGroup) TestController(com.bluelinelabs.conductor.util.TestController) Intent(android.content.Intent) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 24 with TestController

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

the class ControllerTests method testAddRemoveChildControllers.

@Test
public void testAddRemoveChildControllers() {
    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 childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID));
    childRouter.setPopsLastView(true);
    childRouter.setRoot(RouterTransaction.with(child1));
    assertEquals(1, parent.getChildRouters().size());
    assertEquals(childRouter, parent.getChildRouters().get(0));
    assertEquals(1, childRouter.getBackstackSize());
    assertEquals(child1, childRouter.getControllers().get(0));
    assertEquals(parent, child1.getParentController());
    assertNull(child2.getParentController());
    childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.VIEW_ID));
    childRouter.pushController(RouterTransaction.with(child2));
    assertEquals(1, parent.getChildRouters().size());
    assertEquals(childRouter, parent.getChildRouters().get(0));
    assertEquals(2, childRouter.getBackstackSize());
    assertEquals(child1, childRouter.getControllers().get(0));
    assertEquals(child2, childRouter.getControllers().get(1));
    assertEquals(parent, child1.getParentController());
    assertEquals(parent, child2.getParentController());
    childRouter.popController(child2);
    assertEquals(1, parent.getChildRouters().size());
    assertEquals(childRouter, parent.getChildRouters().get(0));
    assertEquals(1, childRouter.getBackstackSize());
    assertEquals(child1, childRouter.getControllers().get(0));
    assertEquals(parent, child1.getParentController());
    assertNull(child2.getParentController());
    childRouter.popController(child1);
    assertEquals(1, parent.getChildRouters().size());
    assertEquals(childRouter, parent.getChildRouters().get(0));
    assertEquals(0, childRouter.getBackstackSize());
    assertNull(child1.getParentController());
    assertNull(child2.getParentController());
}
Also used : ViewGroup(android.view.ViewGroup) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 25 with TestController

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

the class ControllerTests method testPermissionResultForChild.

@Test
public void testPermissionResultForChild() {
    final String[] requestedPermissions = new String[] { "test" };
    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 handleRequestedPermission w/o requesting a result doesn't do anything
    router.onRequestPermissionsResult("anotherId", 1, requestedPermissions, new int[] { 1 });
    assertCalls(childExpectedCallState, child);
    assertCalls(parentExpectedCallState, parent);
    // Ensure requesting the permission gets us the result back
    try {
        child.requestPermissions(requestedPermissions, 1);
    } catch (NoSuchMethodError ignored) {
    }
    router.onRequestPermissionsResult(child.getInstanceId(), 1, requestedPermissions, new int[] { 1 });
    childExpectedCallState.onRequestPermissionsResultCalls++;
    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)

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