add coverage all be it with superfacial assertions.
@@ -4,9 +4,12 @@ import org.junit.After;
import org.junit.Before;
import org.junit.Test;
+import java.util.function.Consumer;
import java.util.function.Predicate;
import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.Mockito.*;
public class ServiceLoaderExtTest {
@@ -37,6 +40,18 @@ public class ServiceLoaderExtTest {
public void iterator() {
assertThat(sampleServiceServiceLoader.iterator())
.hasSize(2);
+ }
+
+ @Test
+ public void spliterator() {
+ assertThat(sampleServiceServiceLoader.spliterator()).isNotNull();
+ }
+
+ @Test
+ public void foreach() {
+ Consumer<? super SampleService> c = mock(Consumer.class);
+ sampleServiceServiceLoader.forEach(c);
+ verify(c, times(2)).accept(any(SampleService.class));
}
@@ -82,6 +97,23 @@ public class ServiceLoaderExtTest {
}
+ @Test
+ public void loadWithClassloader() throws Exception {
+ ClassLoader classLoader = mock(ClassLoader.class);
+ ServiceLoaderExt<SampleService> result = ServiceLoaderExt.load(SampleService.class, classLoader);
+ assertThat(result).isNotNull().isExactlyInstanceOf(ServiceLoaderExt.class);
+ }
+
+ @Test
+ public void loadWithModuleLayer() throws Exception {
+ ServiceLoaderExt<SampleService> result = ServiceLoaderExt.load(ModuleLayer.empty(),SampleService.class);
+ assertThat(result).isNotNull();
+ }
+ @Test
+ public void loadInstalled() {
+ ServiceLoaderExt<SampleService> result = ServiceLoaderExt.loadInstalled(SampleService.class);
+ assertThat(result).isNotNull().isExactlyInstanceOf(ServiceLoaderExt.class);
+ }
}
