### Question:
GuiceFxmlLoader implements IFxmlLoaderProvider { @Override public FXMLLoader create(final String fxmlFile) throws IOException { Preconditions.checkNotNull(injector); FXMLLoader loader = create(fxmlFile, injector); return loader; } @Inject  GuiceFxmlLoader(Injector injector);  GuiceFxmlLoader(); @Override FXMLLoader create(final String fxmlFile); @Override FXMLLoader create(final String fxmlFile, Injector injector);  }### Answer:
@Test public void testCreateLoginViewDependencies() throws Exception { Injector injector = Guice.createInjector( new AppModule(Mockito.mock(Stage.class)), new AppConfigModule(), new ApiServerModule() ); IFxmlLoaderProvider fxmlLoaderProvider = new GuiceFxmlLoader(injector); FXMLLoader fxmlLoader = fxmlLoaderProvider.create(ViewNames.LOGIN_VIEW); Parent loginView = fxmlLoader.load(); Object loginController = fxmlLoader.getController(); assertNotNull(loginView); assertNotNull(loginController); assertTrue(loginController instanceof LoginController); Class<?> ctrl = loginController.getClass(); Field appContextField = ctrl.getDeclaredField("appContext"); appContextField.setAccessible(true); Object appContext = appContextField.get(loginController); assertNotNull(appContext); assertTrue(appContext instanceof AppContext); Field userManagerField = ctrl.getDeclaredField("userManager"); userManagerField.setAccessible(true); Object userManager = userManagerField.get(loginController); assertNotNull(userManager); assertTrue(userManager instanceof IUserManager); Field navigationServiceField = ctrl.getDeclaredField("fNavigationService"); navigationServiceField.setAccessible(true); Object navigationService = navigationServiceField.get(loginController); assertNotNull(navigationService); assertTrue(navigationService instanceof NavigationService); }
@Test public void testCreateMainViewMock() throws IOException { Injector injector = Mockito.mock(Injector.class); when(injector.getInstance(MainController.class)).thenReturn(new MainController()); IFxmlLoaderProvider fxmlLoaderProvider = new GuiceFxmlLoader(injector); FXMLLoader fxmlLoader = fxmlLoaderProvider.create(ViewNames.MAIN_VIEW); Parent mainView = fxmlLoader.load(); Object mainController = fxmlLoader.getController(); assertNotNull(mainView); assertNotNull(mainController); Mockito.verify(injector, Mockito.times(1)).getInstance(MainController.class); }
@SuppressWarnings("unused") @Test(expected = IOException.class) public void testCreateNoName() throws IOException { Injector injector = Guice.createInjector(); IFxmlLoaderProvider fxmlLoaderProvider = new GuiceFxmlLoader(injector); FXMLLoader fxmlLoader; fxmlLoader = fxmlLoaderProvider.create(""); Parent mainView = fxmlLoader.load(); Object mainController = fxmlLoader.getController(); }