use of com.bluelinelabs.conductor.util.TestController 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);
}
use of com.bluelinelabs.conductor.util.TestController in project Conductor by bluelinelabs.
the class RouterTests method testPushPopControllers.
@Test
public void testPushPopControllers() {
String controller1Tag = "controller1";
String controller2Tag = "controller2";
Controller controller1 = new TestController();
Controller controller2 = new TestController();
router.pushController(RouterTransaction.with(controller1).tag(controller1Tag));
assertEquals(1, router.getBackstackSize());
router.pushController(RouterTransaction.with(controller2).tag(controller2Tag));
assertEquals(2, router.getBackstackSize());
router.popCurrentController();
assertEquals(1, router.getBackstackSize());
assertEquals(controller1, router.getControllerWithTag(controller1Tag));
assertNull(router.getControllerWithTag(controller2Tag));
router.popCurrentController();
assertEquals(0, router.getBackstackSize());
assertNull(router.getControllerWithTag(controller1Tag));
assertNull(router.getControllerWithTag(controller2Tag));
}
use of com.bluelinelabs.conductor.util.TestController in project Conductor by bluelinelabs.
the class RouterTests method testPopToRoot.
@Test
public void testPopToRoot() {
RouterTransaction rootTransaction = RouterTransaction.with(new TestController());
RouterTransaction transaction1 = RouterTransaction.with(new TestController());
RouterTransaction transaction2 = RouterTransaction.with(new TestController());
List<RouterTransaction> backstack = Arrays.asList(rootTransaction, transaction1, transaction2);
router.setBackstack(backstack, null);
assertEquals(3, router.getBackstackSize());
router.popToRoot();
assertEquals(1, router.getBackstackSize());
assertEquals(rootTransaction, router.getBackstack().get(0));
assertTrue(rootTransaction.controller.isAttached());
assertFalse(transaction1.controller.isAttached());
assertFalse(transaction2.controller.isAttached());
}
use of com.bluelinelabs.conductor.util.TestController in project Conductor by bluelinelabs.
the class RouterTests method testChildRouterRearrangeTransactionBackstack.
@Test
public void testChildRouterRearrangeTransactionBackstack() {
Controller parent = new TestController();
router.setRoot(RouterTransaction.with(parent));
Router childRouter = parent.getChildRouter((ViewGroup) parent.getView().findViewById(TestController.CHILD_VIEW_ID_1));
RouterTransaction transaction1 = RouterTransaction.with(new TestController());
RouterTransaction transaction2 = RouterTransaction.with(new TestController());
List<RouterTransaction> backstack = Arrays.asList(transaction1, transaction2);
childRouter.setBackstack(backstack, null);
assertEquals(2, transaction1.transactionIndex);
assertEquals(3, transaction2.transactionIndex);
backstack = Arrays.asList(transaction2, transaction1);
childRouter.setBackstack(backstack, null);
assertEquals(2, transaction2.transactionIndex);
assertEquals(3, transaction1.transactionIndex);
childRouter.handleBack();
assertEquals(1, childRouter.getBackstackSize());
assertEquals(transaction2, childRouter.getBackstack().get(0));
childRouter.handleBack();
assertEquals(0, childRouter.getBackstackSize());
}
use of com.bluelinelabs.conductor.util.TestController in project Conductor by bluelinelabs.
the class RouterTests method testGetByTag.
@Test
public void testGetByTag() {
String controller1Tag = "controller1";
String controller2Tag = "controller2";
Controller controller1 = new TestController();
Controller controller2 = new TestController();
router.pushController(RouterTransaction.with(controller1).tag(controller1Tag));
router.pushController(RouterTransaction.with(controller2).tag(controller2Tag));
assertEquals(controller1, router.getControllerWithTag(controller1Tag));
assertEquals(controller2, router.getControllerWithTag(controller2Tag));
}
Aggregations