@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_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 should_retain_prepared_instance_until_navigation_settled_without_qualifier() throws Exception { // Arrange final long fiveMinutes = 60 * 5; // Act Navigator navigator = navigationManager.navigate(this).with(TimerController.class, new Preparer<TimerController>() { @Override public void prepare(TimerController instance) { instance.setInitialValue(fiveMinutes); } }); navigator.to(TimerController.class); Mvc.graph().use(TimerController.class, null, new Consumer<TimerController>() { @Override public void consume(TimerController instance) { //Controller should not have been released yet Assert.assertEquals(fiveMinutes, instance.getInitialValue()); } }); //destroy the navigator navigator.destroy(); Mvc.graph().use(TimerController.class, new Consumer<TimerController>() { @Override public void consume(TimerController instance) { //Controller should have now been released Assert.assertEquals(0, instance.getInitialValue()); } }); }