Search in sources :

Example 26 with TestController

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);
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) Intent(android.content.Intent) CallState(com.bluelinelabs.conductor.util.CallState) Test(org.junit.Test)

Example 27 with TestController

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));
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 28 with TestController

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());
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 29 with TestController

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());
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) TestController(com.bluelinelabs.conductor.util.TestController) Test(org.junit.Test)

Example 30 with TestController

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));
}
Also used : TestController(com.bluelinelabs.conductor.util.TestController) 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