GuiceServiceLoader { public <T> List<T> load(Class<T> cls, ClassLoader classLoader) { try { return Collections.list(classLoader.getResources(PREFIX + cls.getName())).stream() .map(this::getLines) .flatMap(Collection::stream) .map(s -> (Class<T>) ClassUtils.load(s, classLoader)) .map(injector::getInstance) .collect(Collectors.toList()); } catch (IOException e) { throw new OxalisPluginException("Unable to load resources.", e); } } @Inject  GuiceServiceLoader(Injector injector); List<T> load(Class<T> cls, ClassLoader classLoader);  }
@Test public void simple() { List<TimestampProvider> providers = serviceLoader.load(TimestampProvider.class, classLoader); Assert.assertEquals(providers.size(), 1); Assert.assertTrue(providers.get(0) instanceof SampleTimestampProvider); }
@Test public void noneDetected() { Assert.assertEquals(serviceLoader.load(PayloadPersister.class, classLoader).size(), 0); }
@Test(expectedExceptions = OxalisLoadingException.class) public void triggerException() { serviceLoader.load(ReceiptPersister.class, classLoader); }