ArgumentCaptor.forClass(NavigationManager.Event.OnLocationForward.class); verify(forwardListener).onEvent(event.capture()); assertEquals(event.getValue().getLastValue(), null); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId1.getName()); assertEquals(event.getValue().getLocationWhereHistoryClearedUpTo(), null); assertEquals(event.getValue().isClearHistory(), false); assertEquals(event.getValue().getLastValue().getLocationId(), locId1.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId2.getName()); assertEquals(event.getValue().getLocationWhereHistoryClearedUpTo(), null); assertEquals(event.getValue().isClearHistory(), false); assertEquals(event.getValue().getLastValue().getLocationId(), locId2.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId3.getName()); assertEquals(event.getValue().getLocationWhereHistoryClearedUpTo(), null); assertEquals(event.getValue().isClearHistory(), false); assertEquals(event.getValue().getLastValue().getLocationId(), locId3.getName()); assertEquals(event.getValue().getCurrentValue().getLocationId(), locId4.getName()); assertEquals(event.getValue().getLocationWhereHistoryClearedUpTo(), null); assertEquals(event.getValue().isClearHistory(), false);
@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()); }
navigateEvent = new NavigationManager.Event.OnLocationForward(sender, lastLoc, currentLoc, clearTop, clearedTopToLocation, this);
= 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);
/** * 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 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); }
/** * Subscribe to forward navigation * @param event */ private void onEvent(NavigationManager.Event.OnLocationForward event) { updateToolbar(event.getCurrentValue()); }