/** * 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); }
public void navigateBack(Object sender) { navigationManager.navigate(sender).back(); }
public void goBackToBasicView(Object sender) { navigationManager.navigate(sender).back(); }
protected void navigateBackByFragment() { navigationManager.navigate(this).back(); }
@Test public void should_not_fail_when_logger_is_set_trace() { navigationManager.logger = mock(Logger.class); when(navigationManager.logger.isTraceEnabled()).thenReturn(true); prepareLocationHistory(); navigationManager.navigate(this).back(); }
@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_not_raise_navigate_back_event_when_fast_back_navigate_from_null_location() throws Exception { // Arrange BackListener backListener = mock(BackListener.class); eventBusC.register(backListener); // Arrange navigationManager.navigate(this).back(Controller1.class); // Verify ArgumentCaptor<NavigationManager.Event.OnLocationBack> event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationBack.class); verify(backListener, times(0)).onEvent(event.capture()); }
@Test(expected = MvcGraphException.class) public void should_throw_MvcGraphException_when_mvcGraph_with_method_encounters_PokeException() { navigationManager.navigate(this).with(X.class); }
@Test public void should_not_raise_navigate_back_event_when_navigate_to_unknown_location() throws Exception { // Arrange BackListener backListener = mock(BackListener.class); eventBusC.register(backListener); prepareLocationHistory(); // Arrange navigationManager.navigate(this).back(Controller.class); // Verify ArgumentCaptor<NavigationManager.Event.OnLocationBack> event = ArgumentCaptor.forClass(NavigationManager.Event.OnLocationBack.class); verify(backListener, times(0)).onEvent(event.capture()); }
@Test public void should_invoke_singular_argument_with_method_of_navigator_correct() throws Exception { Navigator navigator = navigationManager.navigate(this); Navigator spiedNavigator = spy(navigator); verify(spiedNavigator, times(0)).with(eq(NavigationManager.class), isNull(Annotation.class), isNull(Preparer.class)); spiedNavigator.with(NavigationManager.class); verify(spiedNavigator).with(eq(NavigationManager.class), isNull(Annotation.class), isNull(Preparer.class)); }
@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 should_return_correct_sender_by_navigator() throws Exception { // Act Navigator navigator = navigationManager.navigate(this); Assert.assertTrue(this == navigator.getSender()); }
@Test public void should_post_app_exit_event_on_the_last_back_of_fast_back_navigation() { //mock the subscriber class AppExitListener { public void onEvent(NavigationManager.Event.OnAppExit event) { } } ArgumentCaptor<NavigationManager.Event.OnAppExit> event = ArgumentCaptor.forClass(NavigationManager.Event.OnAppExit.class); AppExitListener exitListener = mock(AppExitListener.class); eventBusC.register(exitListener); prepareLocationHistory(); reset(exitListener); navigationManager.navigate(this).back(null); verify(exitListener, times(0)).onEvent(event.capture()); navigateBackByFragment(); verify(exitListener, times(1)).onEvent(event.capture()); Assert.assertTrue(this == event.getValue().getSender()); }
@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 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_throw_MvcGraphException_when_mvcGraph_destroy_method_encounters_PokeException() throws ProvideException, ProviderConflictException, ProviderMissingException { navigationManager.logger = mock(Logger.class); Navigator navigator = navigationManager.navigate(this); Mvc.graph().getRootComponent().register(new Object(){ @Provides public X x() { return new X_1(); } }); navigator.with(X.class); Mvc.graph().getRootComponent().unregister(X.class, null); navigator.destroy(); verify(navigationManager.logger).warn(anyString(), anyString()); }
@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()); }