/** * Go to detail view. * @param sender */ public void goToDetailScreen(Object sender) { //Navigate to CounterDetailController which is paired by CounterDetailScreen navigationManager.navigate(sender).to(CounterDetailController.class); }
public void startApp(Object sender) { navigationManager.navigate(sender).to(CounterMasterController.class); }
@Test public void should_not_raise_navigate_back_event_when_navigate_to_first_location_from_the_first_location() throws Exception { // Arrange BackListener backListener = mock(BackListener.class); eventBusC.register(backListener); navigationManager.navigate(this).to(locId1); // Arrange Navigator navigator = navigationManager.navigate(this); navigator.back(null); // Verify ArgumentCaptor<NavigationManager.Event.OnLocationBack> event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationBack.class); verify(backListener, times(0)).onEvent(event.capture()); }
@Test public void should_invoke_on_settled_when_navigation_is_done() throws Exception { // Arrange Navigator.OnSettled onSettled = mock(Navigator.OnSettled.class); // Act Navigator navigator = navigationManager.navigate(this).with(TimerController.class) .onSettled(onSettled); navigator.to(TimerController.class); verify(onSettled, times(0)).run(); //destroy the navigator navigator.destroy(); verify(onSettled, times(1)).run(); }
@Test public void shouldClearAllNavigationHistory() throws Exception { ForwardListener forwardListener = prepareLocationHistory(); reset(forwardListener); navigationManager.navigate(this).to(locId5, new Forwarder().clearAll()); ArgumentCaptor<NavigationManager.Event.OnLocationForward> event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationForward.class); verify(forwardListener).onEvent(event.capture()); assertEquals(event.getValue().getLastValue().getLocationId(), locId4.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId5.getName()); assertEquals(event.getValue().getLocationWhereHistoryClearedUpTo(), null); assertEquals(event.getValue().isClearHistory(), true); //Now the history should be loc1->loc2->loc5 NavLocation currentLoc = navigationManager.getModel().getCurrentLocation(); assertEquals(currentLoc.getLocationId(), locId5.getName()); assertEquals(currentLoc.getPreviousLocation(), null); }
@Test public void should_skip_interim_location_on_back_navigation() throws Exception { //mock the subscriber BackListener backListener = mock(BackListener.class); eventBusC.register(backListener); prepareLocationHistory(); reset(backListener); navigationManager.navigate(this).to(locId1, new Forwarder().setInterim(true)); navigationManager.navigate(this).to(locId2, new Forwarder().setInterim(true)); navigationManager.navigate(this).back(); ArgumentCaptor<NavigationManager.Event.OnLocationBack> event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationBack.class); verify(backListener).onEvent(event.capture()); assertEquals(event.getValue().getLastValue().getLocationId(), locId2.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId4.getName()); NavLocation currentLoc = navigationManager.getModel().getCurrentLocation(); assertEquals(currentLoc.getLocationId(), locId4.getName()); Assert.assertTrue(event.getValue().isFastRewind()); }
@Test public void interim_forwarder_should_instruct_navigation_not_push_location_to_back_stack(){ ForwardListener forwardListener = mock(ForwardListener.class); eventBusC.register(forwardListener); // Act Navigator navigator = navigationManager.navigate(this); Forwarder forwarder = new Forwarder(); Assert.assertFalse(forwarder.isInterim()); forwarder.setInterim(true); Assert.assertTrue(forwarder.isInterim()); navigator.to(TimerController.class, forwarder); ArgumentCaptor<NavigationManager.Event.OnLocationForward> event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationForward.class); verify(forwardListener).onEvent(event.capture()); assertEquals(event.getValue().getCurrentValue().getLocationId(), TimerController.class.getName()); assertTrue(event.getValue().getCurrentValue().isInterim()); Assert.assertTrue(this == event.getValue().getSender()); Assert.assertTrue(navigator == event.getValue().getNavigator()); }
@Test public void should_navigate_correctly() { //Act: navigate to MasterScreen navigationManager.navigate(this).to(CounterMasterController.class); //Verify: location should be changed to MasterScreen Assert.assertEquals(CounterMasterController.class.getName(), navigationManager.getModel().getCurrentLocation().getLocationId()); //Act: navigate to DetailScreen controller.goToDetailScreen(this); //Verify: Current location should be at the view paired with CounterDetailController Assert.assertEquals(CounterDetailController.class.getName(), navigationManager.getModel().getCurrentLocation().getLocationId()); }
@Test public void should_retain_prepared_instance_until_navigation_settled_without_qualifier() throws Exception { // Arrange final long fiveMinutes = 60 * 5; // Act Navigator navigator = navigationManager.navigate(this).with(TimerController.class, new Preparer<TimerController>() { @Override public void prepare(TimerController instance) { instance.setInitialValue(fiveMinutes); } }); navigator.to(TimerController.class); Mvc.graph().use(TimerController.class, null, new Consumer<TimerController>() { @Override public void consume(TimerController instance) { //Controller should not have been released yet Assert.assertEquals(fiveMinutes, instance.getInitialValue()); } }); //destroy the navigator navigator.destroy(); Mvc.graph().use(TimerController.class, new Consumer<TimerController>() { @Override public void consume(TimerController instance) { //Controller should have now been released Assert.assertEquals(0, instance.getInitialValue()); } }); }