OSGIServiceContext implements ServiceContext { @Override public <T> List<T> getServices(Class<T> serviceType, Supplier<List<T>> supplier) { LOG.finest("TAMAYA Loading services: " + serviceType.getName()); List<T> services = loadServices(serviceType, null); if(services.isEmpty() && supplier!=null) { services = supplier.get(); try { for (T t : services) { this.osgiServiceLoader.getBundleContext().registerService(serviceType, t, new Hashtable<>()); } } catch (Exception e) { LOG.log(Level.SEVERE, "Error while getting service.", e); } } return services; } OSGIServiceContext(OSGIServiceLoader osgiServiceLoader); boolean isInitialized(); @Override ClassLoader getClassLoader(); @Override void init(ClassLoader classLoader); @Override int ordinal(); @Override T getService(Class<T> serviceType, Supplier<T> supplier); @Override T create(Class<T> serviceType, Supplier<T> supplier); @Override List<T> getServices(Class<T> serviceType, Supplier<List<T>> supplier); @Override Collection<URL> getResources(String resource); @Override URL getResource(String resource); @Override T register(Class<T> serviceType, T instance, boolean force); @Override List<T> register(Class<T> serviceType, List<T> instances, boolean force); @Override void reset();  }
@Test public void testGetServices() { BundleContext mockBundleContext = new MockBundleContext(); OSGIServiceLoader loader = new OSGIServiceLoader(mockBundleContext); OSGIServiceContext instance = new OSGIServiceContext(loader); List services = instance.getServices(Integer.class); assertThat(services).isNotNull(); assertThat(services).isEmpty(); }