### Question:
DependencyInjectingServiceLoader { public static <T> List<T> load(Class<T> clazz, Object... constructorArguments) { return new DependencyInjectingServiceLoader<>(clazz, constructorArguments).instances; } private  DependencyInjectingServiceLoader(Class<T> clazz, Object... constructorArguments); private  DependencyInjectingServiceLoader(Class<T> clazz, List<ClassLoader> classLoaders, Object... constructorArguments); static List<T> load(Class<T> clazz, Object... constructorArguments); static List<T> load(Class<T> clazz, List<ClassLoader> classLoaders, Object... constructorArguments);  }### Answer:
@Test void testServiceWithConstructorArgument() { final List<Service> serviceImplementations = DependencyInjectingServiceLoader.load(Service.class, "foo"); assertThat(serviceImplementations).hasSize(2); assertThat(serviceImplementations.get(0).getString()).isEqualTo("foo"); assertThat(serviceImplementations.get(0)).isInstanceOf(ServiceImpl.class); assertThat(serviceImplementations.get(1).getString()).isEqualTo("foo"); assertThat(serviceImplementations.get(1)).isInstanceOf(ServiceImpl2.class); }
@Test void testServiceWithoutConstructorArgument() { final List<Service> serviceImplementations = DependencyInjectingServiceLoader.load(Service.class); assertThat(serviceImplementations).hasSize(2); assertThat(serviceImplementations.get(0).getString()).isEqualTo("bar"); assertThat(serviceImplementations.get(0)).isInstanceOf(ServiceImpl.class); assertThat(serviceImplementations.get(1).getString()).isEqualTo("bar"); assertThat(serviceImplementations.get(1)).isInstanceOf(ServiceImpl2.class); }