ServiceLoaderUtils { public static <T> List<T> loadServicesList(ClassLoader classLoader, Class<T> serviceInterfaceType) throws IllegalArgumentException { return Collections.unmodifiableList(loadServicesList0(classLoader, serviceInterfaceType)); }  static List<T> loadServicesList(ClassLoader classLoader, Class<T> serviceInterfaceType); static T loadFirstService(ClassLoader classLoader, Class<T> serviceInterfaceType); static T loadLastService(ClassLoader classLoader, Class<T> serviceInterfaceType);  }
@Test public void testLoadServicesList() throws Exception { ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); List<CharSequence> charSequenceList = ServiceLoaderUtils.loadServicesList(classLoader, CharSequence.class); Assert.assertEquals(1, charSequenceList.size()); CharSequence charSequence = charSequenceList.get(0); CharSequence firstService = ServiceLoaderUtils.loadFirstService(classLoader, CharSequence.class); CharSequence lastService = ServiceLoaderUtils.loadLastService(classLoader, CharSequence.class); Assert.assertNotNull(charSequence); Assert.assertEquals(charSequence, firstService); Assert.assertEquals(charSequence, lastService); Assert.assertEquals(firstService, lastService); String string = charSequence.toString(); Assert.assertTrue(string.isEmpty()); IllegalArgumentException e = null; try { ServiceLoaderUtils.loadServicesList(classLoader, Set.class); } catch (IllegalArgumentException e_) { e = e_; e.printStackTrace(); } Assert.assertNotNull(e); }