@Test public void testGetService_noImpl_shouldReturnEmptyOpional() { NoImplInterface service = context.getService(NoImplInterface.class); assertThat(service).isNull(); }
@Override public <T> T getService(Class<T> serviceType, Supplier<T> supplier) { T service = (T)singletons.get(serviceType); if(service!=null){ return service; } Collection<T> services = loadServices(serviceType, null); if (services.isEmpty() && supplier!=null){ T instance = supplier.get(); if(instance instanceof ClassloaderAware){ ((ClassloaderAware)instance).init(this.classLoader); } register(serviceType, instance, true); return instance; } T t = getServiceWithHighestPriority(services, serviceType); if(t!=null) { this.singletons.put(serviceType, t); } return t; }
DefaultServiceContext implements ServiceContext { @Override public <T> T getService(Class<T> serviceType, Supplier<T> supplier) { T service = (T)singletons.get(serviceType); if(service!=null){ return service; } Collection<T> services = loadServices(serviceType, null); if (services.isEmpty() && supplier!=null){ T instance = supplier.get(); if(instance instanceof ClassloaderAware){ ((ClassloaderAware)instance).init(this.classLoader); } register(serviceType, instance, true); return instance; } T t = getServiceWithHighestPriority(services, serviceType); if(t!=null) { this.singletons.put(serviceType, t); } return t; } }
DefaultServiceContext implements ServiceContext { @Override public <T> T getService(Class<T> serviceType, Supplier<T> supplier) { T service = (T)singletons.get(serviceType); if(service!=null){ return service; } Collection<T> services = loadServices(serviceType, null); if (services.isEmpty() && supplier!=null){ T instance = supplier.get(); if(instance instanceof ClassloaderAware){ ((ClassloaderAware)instance).init(this.classLoader); } register(serviceType, instance, true); return instance; } T t = getServiceWithHighestPriority(services, serviceType); if(t!=null) { this.singletons.put(serviceType, t); } return t; }  }
DefaultServiceContext implements ServiceContext { @Override public <T> T getService(Class<T> serviceType, Supplier<T> supplier) { T service = (T)singletons.get(serviceType); if(service!=null){ return service; } Collection<T> services = loadServices(serviceType, null); if (services.isEmpty() && supplier!=null){ T instance = supplier.get(); if(instance instanceof ClassloaderAware){ ((ClassloaderAware)instance).init(this.classLoader); } register(serviceType, instance, true); return instance; } T t = getServiceWithHighestPriority(services, serviceType); if(t!=null) { this.singletons.put(serviceType, t); } return t; }  @Override T getService(Class<T> serviceType, Supplier<T> supplier); @Override T create(Class<T> serviceType, Supplier<T> supplier); @Override List<T> getServices(final Class<T> serviceType, Supplier<List<T>> supplier); @Override T register(Class<T> serviceType, T instance, boolean force); @Override List<T> register(Class<T> type, List<T> instances, boolean force); @Override void reset(); @Override ClassLoader getClassLoader(); @Override void init(ClassLoader classLoader); }
DefaultServiceContext implements ServiceContext { @Override public <T> T getService(Class<T> serviceType, Supplier<T> supplier) { T service = (T)singletons.get(serviceType); if(service!=null){ return service; } Collection<T> services = loadServices(serviceType, null); if (services.isEmpty() && supplier!=null){ T instance = supplier.get(); if(instance instanceof ClassloaderAware){ ((ClassloaderAware)instance).init(this.classLoader); } register(serviceType, instance, true); return instance; } T t = getServiceWithHighestPriority(services, serviceType); if(t!=null) { this.singletons.put(serviceType, t); } return t; }  @Override T getService(Class<T> serviceType, Supplier<T> supplier); @Override T create(Class<T> serviceType, Supplier<T> supplier); @Override List<T> getServices(final Class<T> serviceType, Supplier<List<T>> supplier); @Override T register(Class<T> serviceType, T instance, boolean force); @Override List<T> register(Class<T> type, List<T> instances, boolean force); @Override void reset(); @Override ClassLoader getClassLoader(); @Override void init(ClassLoader classLoader);  }