Skip to content

Commit

Permalink
Use Java 17 ServiceLoader#stream in AbstractContainerGroupAssert
Browse files Browse the repository at this point in the history
  • Loading branch information
ascopes committed Jan 6, 2025
1 parent 851fe7e commit 23c0839
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import static org.assertj.core.api.Assertions.assertThat;

import io.github.ascopes.jct.containers.ContainerGroup;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
import org.assertj.core.api.AbstractAssert;
import org.assertj.core.api.AbstractListAssert;
import org.assertj.core.api.ObjectAssert;
Expand Down Expand Up @@ -74,9 +74,9 @@ public LocationAssert location() {
requireNonNull(type, "type must not be null");
isNotNull();

var items = new ArrayList<T>();
actual.getServiceLoader(type).iterator().forEachRemaining(items::add);

var items = actual.getServiceLoader(type)
.stream()
.map(ServiceLoader.Provider::get);
return assertThat(items);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,8 @@ protected TraceDiagnosticListAssert newAbstractIterableAssert(
}

private Predicate<@Nullable TraceDiagnostic<? extends JavaFileObject>> kindIsOneOf(
Iterable<Kind> kinds) {
Iterable<Kind> kinds
) {
var kindsSet = new LinkedHashSet<Kind>();
kinds.forEach(kindsSet::add);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,7 @@ protected A toAssert(@Nullable E value, String description) {
protected TypeAwareListAssert<@Nullable E, A> newAbstractIterableAssert(
Iterable<? extends @Nullable E> iterable
) {
var list = StreamSupport
.stream(iterable.spliterator(), false)
.toList();

var list = StreamSupport.stream(iterable.spliterator(), false).toList();
return new TypeAwareListAssert<>(list, assertFactory);
}
}

0 comments on commit 23c0839

Please sign in to comment.