Source:
public void setUp() throws Exception { connectorDeployerService = new ConnectorDeployerService(); authManagerMock = mock(AuthenticationManager.class); authMock = mock(Authentication.class); ServiceManagerImpl serviceManagerImpl = new ServiceManagerImpl(); ServiceRegistrationManagerImpl registrationManager = new ServiceRegistrationManagerImpl(); registrationManager.setBundleContext(bundleContext); serviceManagerImpl.setRegistrationManager(registrationManager); this.serviceManager = serviceManagerImpl; DummyPersistenceManager dummyPersistenceManager = new DummyPersistenceManager(); CorePersistenceServiceBackend backend = new CorePersistenceServiceBackend(); backend.setBundleContext(bundleContext); backend.setPersistenceManager(dummyPersistenceManager); backend.init(); DefaultConfigPersistenceService configPersistence = new DefaultConfigPersistenceService(backend); Dictionary<String, Object> props2 = new Hashtable<String, Object>(); props2.put("configuration.id", "CONNECTOR"); registerService(configPersistence, props2, ConfigPersistenceService.class); when(authManagerMock.authenticate(any(UsernamePasswordAuthenticationToken.class))).thenReturn(authMock); Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put("connector", "a-connector"); connectorDeployerService.setAuthenticationManager(authManagerMock); connectorDeployerService.setServiceManager(serviceManagerImpl); factory = mock(ServiceInstanceFactory.class); createdService = mock(NullDomain.class); when(factory.createNewInstance(anyString())).thenReturn(createdService); registerService(factory, props, ServiceInstanceFactory.class); createDomainProviderMock(NullDomain.class, "mydomain"); DefaultWiringService defaultWiringService = new DefaultWiringService(); defaultWiringService.setBundleContext(bundleContext); registerServiceViaId(defaultWiringService, "wiring", WiringService.class); }

Target:
public void setUp() throws Exception { connectorDeployerService = new ConnectorDeployerService(); authManagerMock = mock(AuthenticationManager.class); authMock = mock(Authentication.class); ConnectorManagerImpl serviceManagerImpl = new ConnectorManagerImpl(); ConnectorRegistrationManagerImpl registrationManager = new ConnectorRegistrationManagerImpl(); registrationManager.setBundleContext(bundleContext); serviceManagerImpl.setRegistrationManager(registrationManager); this.serviceManager = serviceManagerImpl; DummyPersistenceManager dummyPersistenceManager = new DummyPersistenceManager(); CorePersistenceServiceBackend backend = new CorePersistenceServiceBackend(); backend.setBundleContext(bundleContext); backend.setPersistenceManager(dummyPersistenceManager); backend.init(); DefaultConfigPersistenceService configPersistence = new DefaultConfigPersistenceService(backend); Dictionary<String, Object> props2 = new Hashtable<String, Object>(); props2.put("configuration.id", org.openengsb.core.api.Constants.CONFIG_CONNECTOR); registerService(configPersistence, props2, ConfigPersistenceService.class); when(authManagerMock.authenticate(any(UsernamePasswordAuthenticationToken.class))).thenReturn(authMock); Dictionary<String, Object> props = new Hashtable<String, Object>(); props.put(org.openengsb.core.api.Constants.CONNECTOR_KEY, "a-connector"); connectorDeployerService.setAuthenticationManager(authManagerMock); connectorDeployerService.setServiceManager(serviceManagerImpl); factory = mock(ConnectorInstanceFactory.class); createdService = mock(NullDomain.class); when(factory.createNewInstance(anyString())).thenReturn(createdService); registerService(factory, props, ConnectorInstanceFactory.class); createDomainProviderMock(NullDomain.class, "mydomain"); DefaultWiringService defaultWiringService = new DefaultWiringService(); defaultWiringService.setBundleContext(bundleContext); registerServiceViaId(defaultWiringService, "wiring", WiringService.class); }