= 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().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());
@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()); }
} else { navigationManager.getModel().setCurrentLocation(previousLoc); navigateEvent = new NavigationManager.Event.OnLocationBack(sender, currentLoc, previousLoc, false, this); go();
navigateEvent = new NavigationManager.Event.OnLocationBack(sender, previousLoc, currentLoc, true, this);
/** * 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 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()); }
/** * Subscribe to backward navigation * @param event */ private void onEvent(NavigationManager.Event.OnLocationBack event) { updateToolbar(event.getCurrentValue()); }