### Question:
InjectorHandler { public InjectorService getInjectorService() { Map<String, InjectorService> beansOfType = context.getBeansOfType(InjectorService.class); if (beansOfType.entrySet().isEmpty()) { throw new NoSuchBeanDefinitionException("No InjectorType found"); } return beansOfType.entrySet().iterator().next().getValue(); } InjectorHandler(ApplicationContext context); InjectorService getInjectorService();  }### Answer:
@Test public void create_local_connection_and_return_it() throws Exception { Connection properties = new Connection("", "9999"); doReturn(localInjector).when(connectionService).createLocalInjector(any()); connectionService.createConnection(properties); connectionService.getCurrentConnection(); InjectorService injectorService = injectorHandler.getInjectorService(); Assert.assertNotNull(injectorService); Assert.assertTrue(injectorService instanceof LocalInjector); }
@Test public void create_remote_connection_and_return_it() throws Exception { Connection properties = new Connection("localhost", 12345); doReturn(remoteInjector).when(connectionService).createRemoteInjector(any()); connectionService.createConnection(properties); InjectorService currentConnection = injectorHandler.getInjectorService(); Assert.assertNotNull(currentConnection); Assert.assertTrue(currentConnection instanceof RemoteInjector); }
@Test public void should_return_an_error_because_there_is_no_connection_opened(){ expectedException.expect(NoSuchBeanDefinitionException.class); expectedException.expectMessage("No InjectorType found"); injectorHandler.getInjectorService(); }