ServiceResolver { public static <T> List<T> getServices(Class<T> intf) { List<T> ret = new ArrayList<T>(); for (T service : ServiceLoader.load(intf)) { if (!(service instanceof ServiceStatus) || ((ServiceStatus)service).isAvailable()) { if (service instanceof ServiceLifecycle) { ((ServiceLifecycle)service).init(); } ret.add(service); } } return ret; }  @SuppressWarnings("unchecked") static T getSingletonService(Class<T> intf); static List<T> getServices(Class<T> intf);  }
@Test public void testServices() { List<TestService> services = ServiceResolver.getServices(TestService.class); assertNotNull(services); assertTrue("List should have two services", services.size() == 2); assertTrue(services.get(0).isInitialised()); assertFalse(services.get(1).isInitialised()); }