/** * Prints navigation history */ private void dumpHistory() { if (navigationManager.dumpHistoryOnLocationChange) { navigationManager.logger.trace(""); navigationManager.logger.trace("Nav Controller: dump: begin ---------------------------------------------->"); NavLocation curLoc = navigationManager.getModel().getCurrentLocation(); while (curLoc != null) { navigationManager.logger.trace("Nav Controller: dump: {}({})", curLoc.getLocationId()); curLoc = curLoc.getPreviousLocation(); } navigationManager.logger.trace("Nav Controller: dump: end ---------------------------------------------->"); navigationManager.logger.trace(""); } } }
NavLocation previousLoc = currentLoc.getPreviousLocation(); while (previousLoc != null && previousLoc.isInterim()) { previousLoc = previousLoc.getPreviousLocation(); needFastRewind = true; navigateBackToLoc(previousLoc == null ? null : previousLoc.getLocationId()); } else { navigationManager.getModel().setCurrentLocation(previousLoc);
if (clearToLocationId.equals(currentLoc.getLocationId())) { currentLoc = currentLoc.getPreviousLocation(); if (lastLoc == null) { locationChanged = true; } else if (!locationId.equals(lastLoc.getLocationId())) { locationChanged = true; NavLocation currentLoc = new NavLocation(); currentLoc._setLocationId(locationId); currentLoc._setInterim(forwarder.interim); currentLoc._setPreviousLocation(lastLoc); } else { currentLoc._setPreviousLocation(clearedTopToLocation);
/** * Sends out the navigation event to execute the navigation */ private void go() { if (navigateEvent != null) { navigationManager.postEvent2C(navigateEvent); if (navigationManager.logger.isTraceEnabled()) { if (navigateEvent instanceof NavigationManager.Event.OnLocationForward) { NavigationManager.Event.OnLocationForward event = (NavigationManager.Event.OnLocationForward) navigateEvent; String lastLocId = event.getLastValue() == null ? null : event.getLastValue().getLocationId(); navigationManager.logger.trace("Nav Manager: Forward: {} -> {}", lastLocId, event.getCurrentValue().getLocationId()); } } if (navigateEvent instanceof NavigationManager.Event.OnLocationBack) { if (navigationManager.logger.isTraceEnabled()) { NavigationManager.Event.OnLocationBack event = (NavigationManager.Event.OnLocationBack) navigateEvent; NavLocation lastLoc = event.getLastValue(); NavLocation currentLoc = event.getCurrentValue(); navigationManager.logger.trace("Nav Manager: Backward: {} -> {}", lastLoc.getLocationId(), currentLoc == null ? "null" : currentLoc.getLocationId()); } checkAppExit(sender); } } dumpHistory(); }
@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()); }
private void doUpdateNavIcon(NavLocation location) { if (location != null) { view.changeNavIcon(location.getPreviousLocation() != null); } else { view.changeNavIcon(false); } } }
verify(forwardListener).onEvent(event.capture()); assertEquals(event.getValue().getLastValue(), null); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId1.getName()); assertEquals(event.getValue().getLastValue().getLocationId(), locId1.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId2.getName()); assertEquals(event.getValue().getLastValue().getLocationId(), locId2.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId3.getName()); assertEquals(event.getValue().getLastValue().getLocationId(), locId3.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId4.getName());
if (currentLoc.getPreviousLocation() == null) { if (toLocationId.equals(currentLoc.getLocationId())) { success = true; break; if (currentLoc.getPreviousLocation() == null) { break; currentLoc = currentLoc.getPreviousLocation();
@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()); }
= ArgumentCaptor.forClass(NavigationManager.Event.OnLocationForward.class); verify(forwardListener).onEvent(event.capture()); assertEquals(event.getValue().getLastValue().getLocationId(), locId1.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId5.getName()); assertEquals(event.getValue().getLocationWhereHistoryClearedUpTo().getLocationId(), locId3.getName()); assertEquals(event.getValue().isClearHistory(), true); assertEquals(curLoc.getLocationId(), locId5.getName()); curLoc = curLoc.getPreviousLocation(); assertEquals(curLoc.getLocationId(), locId3.getName()); curLoc = curLoc.getPreviousLocation(); assertEquals(curLoc.getLocationId(), locId2.getName()); curLoc = curLoc.getPreviousLocation(); assertEquals(curLoc.getLocationId(), locId1.getName()); curLoc = curLoc.getPreviousLocation(); assertEquals(curLoc, null); assertEquals(currentLoc.getLocationId(), locId5.getName()); assertEquals(currentLoc.getPreviousLocation().getLocationId(), locId3.getName()); assertEquals(currentLoc.getPreviousLocation().getPreviousLocation().getLocationId(), locId2.getName()); assertEquals(currentLoc.getPreviousLocation().getPreviousLocation().getPreviousLocation().getLocationId(), locId1.getName()); assertEquals(currentLoc.getPreviousLocation().getPreviousLocation().getPreviousLocation().getPreviousLocation(), null);
@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 shouldBeAbleToNavigateBackToGivenLocation() throws Exception { //mock the subscriber BackListener backListener = mock(BackListener.class); eventBusC.register(backListener); prepareLocationHistory(); reset(backListener); navigationManager.navigate(this).back(locId2); ArgumentCaptor<NavigationManager.Event.OnLocationBack> event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationBack.class); verify(backListener).onEvent(event.capture()); assertEquals(event.getValue().getLastValue().getLocationId(), locId4.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId2.getName()); NavLocation currentLoc = navigationManager.getModel().getCurrentLocation(); assertEquals(currentLoc.getLocationId(), locId2.getName()); assertEquals(currentLoc.getPreviousLocation().getLocationId(), locId1.getName()); assertEquals(currentLoc.getPreviousLocation().getPreviousLocation(), null); Assert.assertTrue(event.getValue().isFastRewind()); }
@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 shouldBeAbleToNavigateBackToFirstLocation() throws Exception { //mock the subscriber BackListener backListener = mock(BackListener.class); eventBusC.register(backListener); prepareLocationHistory(); reset(backListener); Navigator navigator = navigationManager.navigate(this); navigator.back(null); ArgumentCaptor<NavigationManager.Event.OnLocationBack> event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationBack.class); verify(backListener).onEvent(event.capture()); Assert.assertTrue(this == event.getValue().getSender()); Assert.assertTrue(navigator == event.getValue().getNavigator()); assertEquals(event.getValue().getLastValue().getLocationId(), locId4.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId1.getName()); NavLocation currentLoc = navigationManager.getModel().getCurrentLocation(); assertEquals(currentLoc.getLocationId(), locId1.getName()); assertEquals(currentLoc.getPreviousLocation(), null); Assert.assertTrue(event.getValue().isFastRewind()); }
= ArgumentCaptor.forClass(NavigationManager.Event.OnLocationBack.class); verify(backListener).onEvent(event.capture()); assertEquals(event.getValue().getLastValue().getLocationId(), locId4.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId3.getName()); NavLocation currentLoc = navigationManager.getModel().getCurrentLocation(); assertEquals(currentLoc.getLocationId(), locId3.getName()); assertEquals(currentLoc.getPreviousLocation().getLocationId(), locId2.getName()); assertEquals(currentLoc.getPreviousLocation().getPreviousLocation().getLocationId(), locId1.getName()); assertEquals(currentLoc.getPreviousLocation().getPreviousLocation().getPreviousLocation(), null); Assert.assertFalse(event.getValue().isFastRewind()); event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationBack.class); verify(backListener).onEvent(event.capture()); assertEquals(event.getValue().getLastValue().getLocationId(), locId3.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId2.getName()); currentLoc = navigationManager.getModel().getCurrentLocation(); assertEquals(currentLoc.getLocationId(), locId2.getName()); assertEquals(currentLoc.getPreviousLocation().getLocationId(), locId1.getName()); assertEquals(currentLoc.getPreviousLocation().getPreviousLocation(), null); Assert.assertFalse(event.getValue().isFastRewind()); event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationBack.class); verify(backListener).onEvent(event.capture()); assertEquals(event.getValue().getLastValue().getLocationId(), locId2.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId1.getName()); currentLoc = navigationManager.getModel().getCurrentLocation(); assertEquals(currentLoc.getLocationId(), locId1.getName()); assertEquals(currentLoc.getPreviousLocation(), null); Assert.assertFalse(event.getValue().isFastRewind());