### Question:
Service { public static <T> Iterable<T> load( Class<T> type ) { Iterable<T> loader; if ( null != (loader = java6Loader( type )) ) { return loader; } return Collections.emptyList(); } protected  Service( String key, String... altKeys ); static Iterable<T> load( Class<T> type ); static T loadSilently( Class<T> type, String key ); static T load( Class<T> type, String key ); @Override String toString(); boolean matches( String key ); Iterable<String> getKeys(); @Override boolean equals( Object o ); @Override int hashCode();  }### Answer:
@Test void shouldLoadServiceInDefaultEnvironment() { FooService fooService = Service.load( FooService.class, "foo" ); assertTrue( fooService instanceof BarService ); }
@Test void whenContextCallsLoaderBlocksServicesFolderShouldLoadClassFromKernelClassloader() { Thread.currentThread().setContextClassLoader( new ServiceBlockClassLoader( contextClassLoader ) ); FooService fooService = Service.load( FooService.class, "foo" ); assertTrue( fooService instanceof BarService ); }
@Test void whenContextClassLoaderOverridesServiceShouldLoadThatClass() { Thread.currentThread().setContextClassLoader( new ServiceRedirectClassLoader( contextClassLoader ) ); FooService fooService = Service.load( FooService.class, "foo" ); assertTrue( fooService instanceof BazService ); }
@Test void whenContextClassLoaderDuplicatesServiceShouldLoadItOnce() { Thread.currentThread().setContextClassLoader( Service.class.getClassLoader() ); Iterable<FooService> services = Service.load( FooService.class ); assertEquals( 1, Iterables.count( services ) ); }