/** * Prepare the instance subject to being injected with no qualifier for the fragment being * navigated to. This instance will be not be released until the navigation is settled. To * config the instance try {@link #with(Class, Preparer)} or {@link #with(Class, Annotation, Preparer)} * * @param type The class type of the instance needs to be prepared * @return This navigator * @throws MvcGraphException Raised when the required injectable object cannot be injected */ public <T> Navigator with(Class<T> type) throws MvcGraphException { with(type, null, null); return this; }
with(type, null, preparer); return this;
@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(expected = MvcGraphException.class) public void should_throw_MvcGraphException_when_mvcGraph_with_method_encounters_PokeException() { navigationManager.navigate(this).with(X.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_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()); } }); }
Navigator navigator = navigationManager.navigate(this).with(TimerController.class, slower2Qualifier, new Preparer<TimerController>() { @Override public void prepare(TimerController instance) { navigator = navigationManager.navigate(this).with(TimerController.class, slower3Qualifier, new Preparer<TimerController>() { @Override public void prepare(TimerController instance) {