Search in sources :

Example 1 with CallState

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

the class ControllerTests method testActivityResult.

@Test
public void testActivityResult() {
    TestController controller = new TestController();
    CallState expectedCallState = new CallState(true);
    router.pushController(RouterTransaction.with(controller));
    // Ensure that calling onActivityResult w/o requesting a result doesn't do anything
    router.onActivityResult(1, Activity.RESULT_OK, null);
    assertCalls(expectedCallState, controller);
    // Ensure starting an activity for result gets us the result back
    controller.startActivityForResult(new Intent("action"), 1);
    router.onActivityResult(1, Activity.RESULT_OK, null);
    expectedCallState.onActivityResultCalls++;
    assertCalls(expectedCallState, controller);
    // Ensure requesting a result w/o calling startActivityForResult works
    controller.registerForActivityResult(2);
    router.onActivityResult(2, Activity.RESULT_OK, null);
    expectedCallState.onActivityResultCalls++;
    assertCalls(expectedCallState, controller);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) Intent(android.content.Intent) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 2 with CallState

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

the class ControllerTests method testOptionsMenu.

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

Example 3 with CallState

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

use of com.bluelinelabs.conductor.util.CallState 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)

Example 5 with CallState

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

the class ControllerLifecycleCallbacksTests method testLifecycleWithActivityDestroy.

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

Aggregations

CallState (com.bluelinelabs.conductor.util.CallState)15 TestController (com.bluelinelabs.conductor.util.TestController)14 Test (org.junit.Test)14 ViewGroup (android.view.ViewGroup)3 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 View (android.view.View)1 LifecycleListener (com.bluelinelabs.conductor.Controller.LifecycleListener)1 Before (org.junit.Before)1