### Question:
Services { public static <S> S get(Class<S> serviceClass) { @SuppressWarnings("unchecked") S service = (S)INSTANCES.computeIfAbsent(serviceClass, sc -> { ServiceLoader<?> serviceLoader = ServiceLoader.load(sc); return StreamSupport.stream(serviceLoader.spliterator(), false).reduce((f1, f2) -> { throw new IllegalStateException( "Multiple implementations of " + sc.getName() + " found on the classpath: " + f1.getClass() + " and " + f2.getClass()); }).orElseThrow(() -> new IllegalStateException( "No implementation of " + sc.getName() + " found on the classpath.")); }); return service; } private  Services(); static S get(Class<S> serviceClass);  }### Answer:
@Test public void testGetSingleImplementation() { assertThat(Services.get(InterfaceWithSingleImplementation.class), is(instanceOf(SingleImplementation.class))); }
@Test public void testGetNoImplementation() { Assertions.assertThrows(IllegalStateException.class, () -> { Services.get(InterfaceWithoutImplementation.class); }); }
@Test public void testGetMultipleImplementations() { Assertions.assertThrows(IllegalStateException.class, () -> { Services.get(InterfaceWithMultipleImplementations.class); }); }