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(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(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); assertEquals(event.getValue().getLastValue().getLocationId(), locId1.getName()); assertEquals(event.getValue().getCurrentValue(), null); currentLoc = navigationManager.getModel().getCurrentLocation(); assertEquals(currentLoc, null); Assert.assertFalse(event.getValue().isFastRewind());
if (clearToLocationId != null) { NavLocation currentLoc = navigationManager.getModel().getCurrentLocation(); while (currentLoc != null) { if (clearToLocationId.equals(currentLoc.getLocationId())) { NavLocation lastLoc = navigationManager.getModel().getCurrentLocation(); boolean locationChanged = false; navigationManager.getModel().setCurrentLocation(currentLoc);
NavLocation currentLoc = navigationManager.getModel().getCurrentLocation(); if (currentLoc == null) { navigationManager.logger.warn("Current location should never be null before navigating backwards."); navigateBackToLoc(previousLoc == null ? null : previousLoc.getLocationId()); } else { navigationManager.getModel().setCurrentLocation(previousLoc); navigateEvent = new NavigationManager.Event.OnLocationBack(sender, currentLoc, previousLoc, false, this); go();
private void navigateBackToLoc(String toLocationId) { NavLocation currentLoc = navigationManager.getModel().getCurrentLocation(); if (currentLoc == null) { navigationManager.logger.warn("Current location should never be null before navigating backwards."); navigationManager.getModel().setCurrentLocation(currentLoc); navigateEvent = new NavigationManager.Event.OnLocationBack(sender, previousLoc, currentLoc, true, this);
NavLocation curLoc = model.getCurrentLocation(); assertEquals(curLoc.getLocationId(), locId5.getName()); curLoc = curLoc.getPreviousLocation(); NavLocation currentLoc = navigationManager.getModel().getCurrentLocation(); assertEquals(currentLoc.getLocationId(), locId5.getName()); assertEquals(currentLoc.getPreviousLocation().getLocationId(), locId3.getName());
@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()); }
@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 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()); }
/** * 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(""); } } }
@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_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()); }
@Override public void onViewReady(Reason reason) { super.onViewReady(reason); view.updateTitle(appManager.getModel().getTitle()); doUpdateNavIcon(navigationManager.getModel().getCurrentLocation()); }
/** * Check the app is exiting * * @param sender The sender */ private void checkAppExit(Object sender) { NavLocation curLocation = navigationManager.getModel().getCurrentLocation(); if (curLocation == null) { navigationManager.postEvent2C(new NavigationManager.Event.OnAppExit(sender)); } }