ServiceCollection implements SpotlessEclipseServiceConfig { @Override public <S> void add(Class<S> interfaceClass, S service) throws ServiceException { String className = interfaceClass.getName(); if (null != className2Service.put(interfaceClass.getName(), new FrameworkServiceReference<S>(className, service))) { throw new ServiceException( String.format("Service '%s' is already registered.", interfaceClass.getName()), ServiceException.FACTORY_ERROR); } } ServiceCollection(Bundle systemBundle, Map<String, String> properties); @Override void set(String key, String value); @Override void add(Class<S> interfaceClass, S service);  }
@Test public void testAddGet() { Service1 service1 = new Service1(); Service2 service2 = new Service2(); instance.add(Interf1.class, service1); instance.add(Interf2a.class, service2); instance.add(Interf2b.class, service2); assertFor(instance).getServiceForReferences(Interf1.class).matchesService(service1); assertFor(instance).getServiceForReferences(Interf2a.class).matchesService(service2); assertFor(instance).getServiceForReferences(Interf2b.class).matchesService(service2); }
@Test public void testMultipleServicesPerInterface() { Service1 serviceX = new Service1(); Service1 serviceY = new Service1(); instance.add(Interf1.class, serviceX); boolean exceptionCaught = false; try { instance.add(Interf1.class, serviceY); } catch (ServiceException e) { exceptionCaught = true; assertThat(e.getMessage()).as("ServiceException does not contain interface class name.").contains(Interf1.class.getName()); } assertThat(exceptionCaught).as("No ServiceException thrown for duplicate interfaces.").isTrue(); }