@Test public void testGetServices_noImpl_shouldReturnEmptyList() { Collection<NoImplInterface> services = context.getServices(NoImplInterface.class); assertThat(services).isNotNull(); assertThat(services).isEmpty(); }
@Override public <T> List<T> getServices(final Class<T> serviceType, Supplier<List<T>> supplier) { @SuppressWarnings("unchecked") List<T> found = (List<T>) servicesLoaded.get(serviceType); if (found != null) { return found; } List<T> services = loadServices(serviceType, supplier); @SuppressWarnings("unchecked") final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services)); return previousServices != null ? previousServices : services; }
DefaultServiceContext implements ServiceContext { @Override public <T> List<T> getServices(final Class<T> serviceType, Supplier<List<T>> supplier) { @SuppressWarnings("unchecked") List<T> found = (List<T>) servicesLoaded.get(serviceType); if (found != null) { return found; } List<T> services = loadServices(serviceType, supplier); @SuppressWarnings("unchecked") final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services)); return previousServices != null ? previousServices : services; } }
DefaultServiceContext implements ServiceContext { @Override public <T> List<T> getServices(final Class<T> serviceType, Supplier<List<T>> supplier) { @SuppressWarnings("unchecked") List<T> found = (List<T>) servicesLoaded.get(serviceType); if (found != null) { return found; } List<T> services = loadServices(serviceType, supplier); @SuppressWarnings("unchecked") final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services)); return previousServices != null ? previousServices : services; }  }
DefaultServiceContext implements ServiceContext { @Override public <T> List<T> getServices(final Class<T> serviceType, Supplier<List<T>> supplier) { @SuppressWarnings("unchecked") List<T> found = (List<T>) servicesLoaded.get(serviceType); if (found != null) { return found; } List<T> services = loadServices(serviceType, supplier); @SuppressWarnings("unchecked") final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services)); return previousServices != null ? previousServices : services; }  @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> List<T> getServices(final Class<T> serviceType, Supplier<List<T>> supplier) { @SuppressWarnings("unchecked") List<T> found = (List<T>) servicesLoaded.get(serviceType); if (found != null) { return found; } List<T> services = loadServices(serviceType, supplier); @SuppressWarnings("unchecked") final List<T> previousServices = List.class.cast(servicesLoaded.putIfAbsent(serviceType, (List<Object>) services)); return previousServices != null ? previousServices : services; }  @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);  }