From 2b7d5b12c19da96eebd37e11ef90df4ebfc0fbed Mon Sep 17 00:00:00 2001 From: Marc Philipp Date: Sun, 11 Oct 2020 18:04:22 +0200 Subject: [PATCH] Use Java 9 collection factory methods --- .../commons/util/AnnotationUtilsTests.java | 11 +- .../ClassNamePatternFilterUtilsTests.java | 13 +- .../commons/util/CollectionUtilsTests.java | 15 +- .../commons/util/PackageUtilsTests.java | 7 +- .../commons/util/PreconditionsTests.java | 12 +- .../platform/console/ConsoleDetailsTests.java | 3 +- .../PicocliCommandLineOptionsParserTests.java | 249 +++++++++--------- .../tasks/ConsoleTestExecutorTests.java | 7 +- .../tasks/DiscoveryRequestCreatorTests.java | 45 ++-- .../console/tasks/TreePrinterTests.java | 10 +- .../discovery/DiscoverySelectorsTests.java | 23 +- .../descriptor/CompositeTestSourceTests.java | 13 +- .../hierarchical/CompositeLockTests.java | 8 +- .../HierarchicalTestExecutorTests.java | 4 +- .../hierarchical/LockManagerTests.java | 18 +- .../NodeTreeWalkerIntegrationTests.java | 5 +- .../launcher/TestIdentifierTests.java | 7 +- .../platform/launcher/TestPlanTests.java | 9 +- .../LauncherConfigurationParametersTests.java | 28 +- .../LauncherDiscoveryRequestBuilderTests.java | 3 +- .../TestExecutionListenerRegistryTests.java | 6 +- .../listeners/SummaryGenerationTests.java | 4 +- .../tagexpression/TagExpressionsTests.java | 29 +- .../legacy/LegacyReportingUtilsTests.java | 7 +- ...egacyXmlReportGeneratingListenerTests.java | 11 +- .../legacy/xml/XmlReportDataTests.java | 8 +- .../legacy/xml/XmlReportWriterTests.java | 20 +- .../runner/JUnitPlatformRunnerTests.java | 14 +- 28 files changed, 279 insertions(+), 310 deletions(-) diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java b/platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java index 319b15eb26d4..76d9c9fd9862 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/AnnotationUtilsTests.java @@ -10,7 +10,6 @@ package org.junit.platform.commons.util; -import static java.util.Arrays.asList; import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -239,7 +238,7 @@ void findRepeatableAnnotationsWithComposedTagBeforeContainer() { } private void assertTagsFound(Class clazz, String... tags) { - assertEquals(asList(tags), + assertEquals(List.of(tags), findRepeatableAnnotations(clazz, Tag.class).stream().map(Tag::value).collect(toList()), () -> "Tags found for class " + clazz.getName()); } @@ -297,7 +296,7 @@ void findInheritedRepeatableAnnotationsWithMultipleComposedAnnotationsOnSupercla } private void assertExtensionsFound(Class clazz, String... tags) { - assertEquals(asList(tags), + assertEquals(List.of(tags), findRepeatableAnnotations(clazz, ExtendWith.class).stream().map(ExtendWith::value).collect(toList()), () -> "Extensions found for class " + clazz.getName()); } @@ -490,7 +489,7 @@ void findPublicAnnotatedFieldsForDirectlyAnnotatedFieldOfWrongFieldType() { void findPublicAnnotatedFieldsForDirectlyAnnotatedField() { var fields = findPublicAnnotatedFields(getClass(), String.class, Annotation1.class); assertNotNull(fields); - assertIterableEquals(asList("directlyAnnotatedField"), asNames(fields)); + assertIterableEquals(List.of("directlyAnnotatedField"), asNames(fields)); } @Test @@ -498,14 +497,14 @@ void findPublicAnnotatedFieldsForMetaAnnotatedField() { var fields = findPublicAnnotatedFields(getClass(), Number.class, Annotation1.class); assertNotNull(fields); assertEquals(1, fields.size()); - assertIterableEquals(asList("metaAnnotatedField"), asNames(fields)); + assertIterableEquals(List.of("metaAnnotatedField"), asNames(fields)); } @Test void findPublicAnnotatedFieldsForDirectlyAnnotatedFieldInInterface() { var fields = findPublicAnnotatedFields(InterfaceWithAnnotatedFields.class, String.class, Annotation1.class); assertNotNull(fields); - assertIterableEquals(asList("foo"), asNames(fields)); + assertIterableEquals(List.of("foo"), asNames(fields)); } @Test diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/ClassNamePatternFilterUtilsTests.java b/platform-tests/src/test/java/org/junit/platform/commons/util/ClassNamePatternFilterUtilsTests.java index b240c08618d0..0567ae3eaeea 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/ClassNamePatternFilterUtilsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/ClassNamePatternFilterUtilsTests.java @@ -10,7 +10,6 @@ package org.junit.platform.commons.util; -import static java.util.Arrays.asList; import static org.assertj.core.api.Assertions.assertThat; import java.util.List; @@ -47,7 +46,7 @@ class ClassNamePatternFilterUtilsTests { //@formatter:on @ParameterizedTest void alwaysEnabledConditions(String pattern) { - List executionConditions = asList(new AExecutionConditionClass(), + List executionConditions = List.of(new AExecutionConditionClass(), new BExecutionConditionClass()); assertThat(executionConditions).filteredOn( ClassNamePatternFilterUtils.excludeMatchingClasses(pattern)).isNotEmpty(); @@ -64,7 +63,7 @@ void alwaysEnabledConditions(String pattern) { //@formatter:on @ParameterizedTest void alwaysDisabledConditions(String pattern) { - List executionConditions = asList(new AExecutionConditionClass(), + List executionConditions = List.of(new AExecutionConditionClass(), new BExecutionConditionClass()); assertThat(executionConditions).filteredOn( ClassNamePatternFilterUtils.excludeMatchingClasses(pattern)).isEmpty(); @@ -81,7 +80,7 @@ void alwaysDisabledConditions(String pattern) { //@formatter:on @ParameterizedTest void alwaysEnabledListeners(String pattern) { - List executionConditions = asList(new ATestExecutionListenerClass(), + List executionConditions = List.of(new ATestExecutionListenerClass(), new BTestExecutionListenerClass()); assertThat(executionConditions).filteredOn( ClassNamePatternFilterUtils.excludeMatchingClasses(pattern)).isNotEmpty(); @@ -98,7 +97,7 @@ void alwaysEnabledListeners(String pattern) { //@formatter:on @ParameterizedTest void alwaysDisabledListeners(String pattern) { - List executionConditions = asList(new ATestExecutionListenerClass(), + List executionConditions = List.of(new ATestExecutionListenerClass(), new BTestExecutionListenerClass()); assertThat(executionConditions).filteredOn( ClassNamePatternFilterUtils.excludeMatchingClasses(pattern)).isEmpty(); @@ -115,7 +114,7 @@ void alwaysDisabledListeners(String pattern) { //@formatter:on @ParameterizedTest void alwaysEnabledClass(String pattern) { - var executionConditions = asList(new AVanillaEmpty(), new BVanillaEmpty()); + var executionConditions = List.of(new AVanillaEmpty(), new BVanillaEmpty()); assertThat(executionConditions).filteredOn( ClassNamePatternFilterUtils.excludeMatchingClasses(pattern)).isNotEmpty(); } @@ -131,7 +130,7 @@ void alwaysEnabledClass(String pattern) { //@formatter:on @ParameterizedTest void alwaysDisabledClass(String pattern) { - var executionConditions = asList(new AVanillaEmpty(), new BVanillaEmpty()); + var executionConditions = List.of(new AVanillaEmpty(), new BVanillaEmpty()); assertThat(executionConditions).filteredOn( ClassNamePatternFilterUtils.excludeMatchingClasses(pattern)).isEmpty(); } diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/CollectionUtilsTests.java b/platform-tests/src/test/java/org/junit/platform/commons/util/CollectionUtilsTests.java index cf4e2572acab..d836fdf7bc52 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/CollectionUtilsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/CollectionUtilsTests.java @@ -10,9 +10,6 @@ package org.junit.platform.commons.util; -import static java.util.Arrays.asList; -import static java.util.Collections.emptySet; -import static java.util.Collections.singleton; import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -25,6 +22,8 @@ import java.lang.reflect.Array; import java.util.ArrayList; import java.util.Collection; +import java.util.List; +import java.util.Set; import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.DoubleStream; import java.util.stream.IntStream; @@ -52,21 +51,21 @@ void getOnlyElementWithNullCollection() { @Test void getOnlyElementWithEmptyCollection() { var exception = assertThrows(PreconditionViolationException.class, - () -> CollectionUtils.getOnlyElement(emptySet())); + () -> CollectionUtils.getOnlyElement(Set.of())); assertEquals("collection must contain exactly one element: []", exception.getMessage()); } @Test void getOnlyElementWithSingleElementCollection() { var expected = new Object(); - var actual = CollectionUtils.getOnlyElement(singleton(expected)); + var actual = CollectionUtils.getOnlyElement(Set.of(expected)); assertSame(expected, actual); } @Test void getOnlyElementWithMultiElementCollection() { var exception = assertThrows(PreconditionViolationException.class, - () -> CollectionUtils.getOnlyElement(asList("foo", "bar"))); + () -> CollectionUtils.getOnlyElement(List.of("foo", "bar"))); assertEquals("collection must contain exactly one element: [foo, bar]", exception.getMessage()); } @@ -159,7 +158,7 @@ public Stream stream() { @SuppressWarnings("unchecked") void toStreamWithIterable() { - Iterable input = () -> asList("foo", "bar").iterator(); + Iterable input = () -> List.of("foo", "bar").iterator(); var result = (Stream) CollectionUtils.toStream(input); @@ -169,7 +168,7 @@ void toStreamWithIterable() { @Test @SuppressWarnings("unchecked") void toStreamWithIterator() { - var input = asList("foo", "bar").iterator(); + var input = List.of("foo", "bar").iterator(); var result = (Stream) CollectionUtils.toStream(input); diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/PackageUtilsTests.java b/platform-tests/src/test/java/org/junit/platform/commons/util/PackageUtilsTests.java index 224e946ec771..cc30ab49ee16 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/PackageUtilsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/PackageUtilsTests.java @@ -16,7 +16,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.DynamicTest.dynamicTest; -import java.util.Arrays; import java.util.List; import java.util.function.Function; @@ -91,13 +90,15 @@ void getAttributeFromDefaultPackageMemberIsEmpty() throws Exception { @TestFactory List attributesFromValueWrapperClassArePresent() { - return Arrays.asList(dynamicTest("getName", isPresent(Package::getName)), + return List.of( // + dynamicTest("getName", isPresent(Package::getName)), dynamicTest("getImplementationTitle", isPresent(Package::getImplementationTitle)), dynamicTest("getImplementationVendor", isPresent(Package::getImplementationVendor)), dynamicTest("getImplementationVersion", isPresent(Package::getImplementationVersion)), dynamicTest("getSpecificationTitle", isPresent(Package::getSpecificationTitle)), dynamicTest("getSpecificationVendor", isPresent(Package::getSpecificationVendor)), - dynamicTest("getSpecificationVersion", isPresent(Package::getSpecificationVersion))); + dynamicTest("getSpecificationVersion", isPresent(Package::getSpecificationVersion)) // + ); } private Executable isPresent(Function function) { diff --git a/platform-tests/src/test/java/org/junit/platform/commons/util/PreconditionsTests.java b/platform-tests/src/test/java/org/junit/platform/commons/util/PreconditionsTests.java index e49b9a362d9f..edfedaec8a90 100644 --- a/platform-tests/src/test/java/org/junit/platform/commons/util/PreconditionsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/commons/util/PreconditionsTests.java @@ -10,7 +10,6 @@ package org.junit.platform.commons.util; -import static java.util.Collections.emptyList; import static java.util.Collections.singletonList; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; @@ -21,7 +20,6 @@ import static org.junit.platform.commons.util.Preconditions.notEmpty; import static org.junit.platform.commons.util.Preconditions.notNull; -import java.util.Arrays; import java.util.Collection; import java.util.List; @@ -70,7 +68,7 @@ void notEmptyPassesForNonEmptyArray() { @Test void notEmptyPassesForNonEmptyCollection() { - Collection collection = Arrays.asList("a", "b", "c"); + Collection collection = List.of("a", "b", "c"); var nonEmptyCollection = notEmpty(collection, () -> "should not fail"); assertSame(collection, nonEmptyCollection); } @@ -117,7 +115,7 @@ void notEmptyThrowsForEmptyArray() { void notEmptyThrowsForEmptyCollection() { var message = "collection is empty"; - var exception = assertThrows(PreconditionViolationException.class, () -> notEmpty(emptyList(), message)); + var exception = assertThrows(PreconditionViolationException.class, () -> notEmpty(List.of(), message)); assertEquals(message, exception.getMessage()); } @@ -134,10 +132,10 @@ void containsNoNullElementsPassesForArrayThatIsNullOrEmpty() { @Test void containsNoNullElementsPassesForCollectionThatIsNullOrEmpty() { containsNoNullElements((List) null, "collection is null"); - containsNoNullElements(emptyList(), "collection is empty"); + containsNoNullElements(List.of(), "collection is empty"); containsNoNullElements((List) null, () -> "collection is null"); - containsNoNullElements(emptyList(), () -> "collection is empty"); + containsNoNullElements(List.of(), () -> "collection is empty"); } @Test @@ -149,7 +147,7 @@ void containsNoNullElementsPassesForArrayContainingNonNullElements() { @Test void containsNoNullElementsPassesForCollectionContainingNonNullElements() { - Collection input = Arrays.asList("a", "b", "c"); + var input = List.of("a", "b", "c"); var output = containsNoNullElements(input, "message"); assertSame(input, output); diff --git a/platform-tests/src/test/java/org/junit/platform/console/ConsoleDetailsTests.java b/platform-tests/src/test/java/org/junit/platform/console/ConsoleDetailsTests.java index bef06659d8ce..4e39a4a3a802 100644 --- a/platform-tests/src/test/java/org/junit/platform/console/ConsoleDetailsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/console/ConsoleDetailsTests.java @@ -12,7 +12,6 @@ import static java.lang.String.format; import static java.nio.charset.StandardCharsets.UTF_8; -import static java.util.Arrays.asList; import static org.junit.jupiter.api.Assertions.assertLinesMatch; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -229,7 +228,7 @@ public void execute() throws Throwable { assumeTrue(Files.isReadable(path), "can not read: " + path); var expectedLines = Files.readAllLines(path, UTF_8); - var actualLines = asList(result.out.split("\\R")); + var actualLines = List.of(result.out.split("\\R")); assertLinesMatch(expectedLines, actualLines); } diff --git a/platform-tests/src/test/java/org/junit/platform/console/options/PicocliCommandLineOptionsParserTests.java b/platform-tests/src/test/java/org/junit/platform/console/options/PicocliCommandLineOptionsParserTests.java index ceb39694e10c..a4a61fb4a0d3 100644 --- a/platform-tests/src/test/java/org/junit/platform/console/options/PicocliCommandLineOptionsParserTests.java +++ b/platform-tests/src/test/java/org/junit/platform/console/options/PicocliCommandLineOptionsParserTests.java @@ -10,11 +10,6 @@ package org.junit.platform.console.options; -import static java.util.Arrays.asList; -import static java.util.Arrays.stream; -import static java.util.Collections.emptyList; -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; import static org.junit.jupiter.api.Assertions.assertAll; @@ -32,9 +27,11 @@ import java.net.URI; import java.nio.file.Files; import java.nio.file.Paths; -import java.util.Arrays; +import java.util.List; +import java.util.Map; import java.util.Optional; import java.util.function.Predicate; +import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; @@ -57,22 +54,22 @@ void parseNoArguments() { () -> assertFalse(options.isDisplayHelp()), () -> assertEquals(CommandLineOptions.DEFAULT_DETAILS, options.getDetails()), () -> assertFalse(options.isScanClasspath()), - () -> assertEquals(singletonList(STANDARD_INCLUDE_PATTERN), options.getIncludedClassNamePatterns()), - () -> assertEquals(emptyList(), options.getExcludedClassNamePatterns()), - () -> assertEquals(emptyList(), options.getIncludedPackages()), - () -> assertEquals(emptyList(), options.getExcludedPackages()), - () -> assertEquals(emptyList(), options.getIncludedTagExpressions()), - () -> assertEquals(emptyList(), options.getExcludedTagExpressions()), - () -> assertEquals(emptyList(), options.getAdditionalClasspathEntries()), + () -> assertEquals(List.of(STANDARD_INCLUDE_PATTERN), options.getIncludedClassNamePatterns()), + () -> assertEquals(List.of(), options.getExcludedClassNamePatterns()), + () -> assertEquals(List.of(), options.getIncludedPackages()), + () -> assertEquals(List.of(), options.getExcludedPackages()), + () -> assertEquals(List.of(), options.getIncludedTagExpressions()), + () -> assertEquals(List.of(), options.getExcludedTagExpressions()), + () -> assertEquals(List.of(), options.getAdditionalClasspathEntries()), () -> assertEquals(Optional.empty(), options.getReportsDir()), - () -> assertEquals(emptyList(), options.getSelectedUris()), - () -> assertEquals(emptyList(), options.getSelectedFiles()), - () -> assertEquals(emptyList(), options.getSelectedDirectories()), - () -> assertEquals(emptyList(), options.getSelectedModules()), - () -> assertEquals(emptyList(), options.getSelectedPackages()), - () -> assertEquals(emptyList(), options.getSelectedMethods()), - () -> assertEquals(emptyList(), options.getSelectedClasspathEntries()), - () -> assertEquals(emptyMap(), options.getConfigurationParameters()) + () -> assertEquals(List.of(), options.getSelectedUris()), + () -> assertEquals(List.of(), options.getSelectedFiles()), + () -> assertEquals(List.of(), options.getSelectedDirectories()), + () -> assertEquals(List.of(), options.getSelectedModules()), + () -> assertEquals(List.of(), options.getSelectedPackages()), + () -> assertEquals(List.of(), options.getSelectedMethods()), + () -> assertEquals(List.of(), options.getSelectedClasspathEntries()), + () -> assertEquals(Map.of(), options.getConfigurationParameters()) ); // @formatter:on } @@ -132,9 +129,9 @@ void parseInvalidDetailsTheme() { void parseValidIncludeClassNamePatterns(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList(".*Test"), type.parseArgLine("-n .*Test").getIncludedClassNamePatterns()), - () -> assertEquals(asList(".*Test", ".*Tests"), type.parseArgLine("--include-classname .*Test --include-classname .*Tests").getIncludedClassNamePatterns()), - () -> assertEquals(singletonList(".*Test"), type.parseArgLine("--include-classname=.*Test").getIncludedClassNamePatterns()) + () -> assertEquals(List.of(".*Test"), type.parseArgLine("-n .*Test").getIncludedClassNamePatterns()), + () -> assertEquals(List.of(".*Test", ".*Tests"), type.parseArgLine("--include-classname .*Test --include-classname .*Tests").getIncludedClassNamePatterns()), + () -> assertEquals(List.of(".*Test"), type.parseArgLine("--include-classname=.*Test").getIncludedClassNamePatterns()) ); // @formatter:on } @@ -144,17 +141,16 @@ void parseValidIncludeClassNamePatterns(ArgsType type) { void parseValidExcludeClassNamePatterns(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList(".*Test"), type.parseArgLine("-N .*Test").getExcludedClassNamePatterns()), - () -> assertEquals(asList(".*Test", ".*Tests"), type.parseArgLine("--exclude-classname .*Test --exclude-classname .*Tests").getExcludedClassNamePatterns()), - () -> assertEquals(singletonList(".*Test"), type.parseArgLine("--exclude-classname=.*Test").getExcludedClassNamePatterns()) + () -> assertEquals(List.of(".*Test"), type.parseArgLine("-N .*Test").getExcludedClassNamePatterns()), + () -> assertEquals(List.of(".*Test", ".*Tests"), type.parseArgLine("--exclude-classname .*Test --exclude-classname .*Tests").getExcludedClassNamePatterns()), + () -> assertEquals(List.of(".*Test"), type.parseArgLine("--exclude-classname=.*Test").getExcludedClassNamePatterns()) ); // @formatter:on } @Test void usesDefaultClassNamePatternWithoutExplicitArgument() throws Exception { - assertEquals(singletonList(STANDARD_INCLUDE_PATTERN), - ArgsType.args.parseArgLine("").getIncludedClassNamePatterns()); + assertEquals(List.of(STANDARD_INCLUDE_PATTERN), ArgsType.args.parseArgLine("").getIncludedClassNamePatterns()); } @Test @@ -172,11 +168,11 @@ void parseInvalidExcludeClassNamePatterns() { void parseValidIncludedPackages(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(asList("org.junit.included"), + () -> assertEquals(List.of("org.junit.included"), type.parseArgLine("--include-package org.junit.included").getIncludedPackages()), - () -> assertEquals(asList("org.junit.included"), + () -> assertEquals(List.of("org.junit.included"), type.parseArgLine("--include-package=org.junit.included").getIncludedPackages()), - () -> assertEquals(asList("org.junit.included1", "org.junit.included2"), + () -> assertEquals(List.of("org.junit.included1", "org.junit.included2"), type.parseArgLine("--include-package org.junit.included1 --include-package org.junit.included2").getIncludedPackages()) ); // @formatter:on @@ -187,11 +183,11 @@ void parseValidIncludedPackages(ArgsType type) { void parseValidExcludedPackages(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(asList("org.junit.excluded"), + () -> assertEquals(List.of("org.junit.excluded"), type.parseArgLine("--exclude-package org.junit.excluded").getExcludedPackages()), - () -> assertEquals(asList("org.junit.excluded"), + () -> assertEquals(List.of("org.junit.excluded"), type.parseArgLine("--exclude-package=org.junit.excluded").getExcludedPackages()), - () -> assertEquals(asList("org.junit.excluded1", "org.junit.excluded2"), + () -> assertEquals(List.of("org.junit.excluded1", "org.junit.excluded2"), type.parseArgLine("--exclude-package org.junit.excluded1 --exclude-package org.junit.excluded2").getExcludedPackages()) ); // @formatter:on @@ -202,10 +198,10 @@ void parseValidExcludedPackages(ArgsType type) { void parseValidIncludedTags(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(asList("fast"), type.parseArgLine("-t fast").getIncludedTagExpressions()), - () -> assertEquals(asList("fast"), type.parseArgLine("--include-tag fast").getIncludedTagExpressions()), - () -> assertEquals(asList("fast"), type.parseArgLine("--include-tag=fast").getIncludedTagExpressions()), - () -> assertEquals(asList("fast", "slow"), type.parseArgLine("-t fast -t slow").getIncludedTagExpressions()) + () -> assertEquals(List.of("fast"), type.parseArgLine("-t fast").getIncludedTagExpressions()), + () -> assertEquals(List.of("fast"), type.parseArgLine("--include-tag fast").getIncludedTagExpressions()), + () -> assertEquals(List.of("fast"), type.parseArgLine("--include-tag=fast").getIncludedTagExpressions()), + () -> assertEquals(List.of("fast", "slow"), type.parseArgLine("-t fast -t slow").getIncludedTagExpressions()) ); // @formatter:on } @@ -220,10 +216,10 @@ void parseInvalidIncludedTags() { void parseValidExcludedTags(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(asList("fast"), type.parseArgLine("-T fast").getExcludedTagExpressions()), - () -> assertEquals(asList("fast"), type.parseArgLine("--exclude-tag fast").getExcludedTagExpressions()), - () -> assertEquals(asList("fast"), type.parseArgLine("--exclude-tag=fast").getExcludedTagExpressions()), - () -> assertEquals(asList("fast", "slow"), type.parseArgLine("-T fast -T slow").getExcludedTagExpressions()) + () -> assertEquals(List.of("fast"), type.parseArgLine("-T fast").getExcludedTagExpressions()), + () -> assertEquals(List.of("fast"), type.parseArgLine("--exclude-tag fast").getExcludedTagExpressions()), + () -> assertEquals(List.of("fast"), type.parseArgLine("--exclude-tag=fast").getExcludedTagExpressions()), + () -> assertEquals(List.of("fast", "slow"), type.parseArgLine("-T fast -T slow").getExcludedTagExpressions()) ); // @formatter:on } @@ -238,9 +234,9 @@ void parseInvalidExcludedTags() { void parseValidIncludedEngines(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(asList("junit-jupiter"), type.parseArgLine("-e junit-jupiter").getIncludedEngines()), - () -> assertEquals(asList("junit-vintage"), type.parseArgLine("--include-engine junit-vintage").getIncludedEngines()), - () -> assertEquals(emptyList(), type.parseArgLine("").getIncludedEngines()) + () -> assertEquals(List.of("junit-jupiter"), type.parseArgLine("-e junit-jupiter").getIncludedEngines()), + () -> assertEquals(List.of("junit-vintage"), type.parseArgLine("--include-engine junit-vintage").getIncludedEngines()), + () -> assertEquals(List.of(), type.parseArgLine("").getIncludedEngines()) ); // @formatter:on } @@ -255,9 +251,9 @@ void parseInvalidIncludedEngines() { void parseValidExcludedEngines(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(asList("junit-jupiter"), type.parseArgLine("-E junit-jupiter").getExcludedEngines()), - () -> assertEquals(asList("junit-vintage"), type.parseArgLine("--exclude-engine junit-vintage").getExcludedEngines()), - () -> assertEquals(emptyList(), type.parseArgLine("").getExcludedEngines()) + () -> assertEquals(List.of("junit-jupiter"), type.parseArgLine("-E junit-jupiter").getExcludedEngines()), + () -> assertEquals(List.of("junit-vintage"), type.parseArgLine("--exclude-engine junit-vintage").getExcludedEngines()), + () -> assertEquals(List.of(), type.parseArgLine("").getExcludedEngines()) ); // @formatter:on } @@ -273,16 +269,16 @@ void parseValidAdditionalClasspathEntries(ArgsType type) { var dir = Paths.get("."); // @formatter:off assertAll( - () -> assertEquals(singletonList(dir), type.parseArgLine("-cp .").getAdditionalClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("--cp .").getAdditionalClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("-classpath .").getAdditionalClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("-classpath=.").getAdditionalClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("--classpath .").getAdditionalClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("--classpath=.").getAdditionalClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("--class-path .").getAdditionalClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("--class-path=.").getAdditionalClasspathEntries()), - () -> assertEquals(asList(dir, Paths.get("src", "test", "java")), type.parseArgLine("-cp . -cp src/test/java").getAdditionalClasspathEntries()), - () -> assertEquals(asList(dir, Paths.get("src", "test", "java")), type.parseArgLine("-cp ." + File.pathSeparator + "src/test/java").getAdditionalClasspathEntries()) + () -> assertEquals(List.of(dir), type.parseArgLine("-cp .").getAdditionalClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("--cp .").getAdditionalClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("-classpath .").getAdditionalClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("-classpath=.").getAdditionalClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("--classpath .").getAdditionalClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("--classpath=.").getAdditionalClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("--class-path .").getAdditionalClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("--class-path=.").getAdditionalClasspathEntries()), + () -> assertEquals(List.of(dir, Paths.get("src", "test", "java")), type.parseArgLine("-cp . -cp src/test/java").getAdditionalClasspathEntries()), + () -> assertEquals(List.of(dir, Paths.get("src", "test", "java")), type.parseArgLine("-cp ." + File.pathSeparator + "src/test/java").getAdditionalClasspathEntries()) ); // @formatter:on } @@ -314,13 +310,13 @@ void parseInvalidXmlReportsDirs() { void parseValidUriSelectors(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList(new URI("file:///foo.txt")), type.parseArgLine("-u file:///foo.txt").getSelectedUris()), - () -> assertEquals(singletonList(new URI("file:///foo.txt")), type.parseArgLine("--u file:///foo.txt").getSelectedUris()), - () -> assertEquals(singletonList(new URI("file:///foo.txt")), type.parseArgLine("-select-uri file:///foo.txt").getSelectedUris()), - () -> assertEquals(singletonList(new URI("file:///foo.txt")), type.parseArgLine("-select-uri=file:///foo.txt").getSelectedUris()), - () -> assertEquals(singletonList(new URI("file:///foo.txt")), type.parseArgLine("--select-uri file:///foo.txt").getSelectedUris()), - () -> assertEquals(singletonList(new URI("file:///foo.txt")), type.parseArgLine("--select-uri=file:///foo.txt").getSelectedUris()), - () -> assertEquals(asList(new URI("file:///foo.txt"), new URI("https://example")), type.parseArgLine("-u file:///foo.txt -u https://example").getSelectedUris()) + () -> assertEquals(List.of(new URI("file:///foo.txt")), type.parseArgLine("-u file:///foo.txt").getSelectedUris()), + () -> assertEquals(List.of(new URI("file:///foo.txt")), type.parseArgLine("--u file:///foo.txt").getSelectedUris()), + () -> assertEquals(List.of(new URI("file:///foo.txt")), type.parseArgLine("-select-uri file:///foo.txt").getSelectedUris()), + () -> assertEquals(List.of(new URI("file:///foo.txt")), type.parseArgLine("-select-uri=file:///foo.txt").getSelectedUris()), + () -> assertEquals(List.of(new URI("file:///foo.txt")), type.parseArgLine("--select-uri file:///foo.txt").getSelectedUris()), + () -> assertEquals(List.of(new URI("file:///foo.txt")), type.parseArgLine("--select-uri=file:///foo.txt").getSelectedUris()), + () -> assertEquals(List.of(new URI("file:///foo.txt"), new URI("https://example")), type.parseArgLine("-u file:///foo.txt -u https://example").getSelectedUris()) ); // @formatter:on } @@ -335,13 +331,13 @@ void parseInvalidUriSelectors() { void parseValidFileSelectors(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList("foo.txt"), type.parseArgLine("-f foo.txt").getSelectedFiles()), - () -> assertEquals(singletonList("foo.txt"), type.parseArgLine("--f foo.txt").getSelectedFiles()), - () -> assertEquals(singletonList("foo.txt"), type.parseArgLine("-select-file foo.txt").getSelectedFiles()), - () -> assertEquals(singletonList("foo.txt"), type.parseArgLine("-select-file=foo.txt").getSelectedFiles()), - () -> assertEquals(singletonList("foo.txt"), type.parseArgLine("--select-file foo.txt").getSelectedFiles()), - () -> assertEquals(singletonList("foo.txt"), type.parseArgLine("--select-file=foo.txt").getSelectedFiles()), - () -> assertEquals(asList("foo.txt", "bar.csv"), type.parseArgLine("-f foo.txt -f bar.csv").getSelectedFiles()) + () -> assertEquals(List.of("foo.txt"), type.parseArgLine("-f foo.txt").getSelectedFiles()), + () -> assertEquals(List.of("foo.txt"), type.parseArgLine("--f foo.txt").getSelectedFiles()), + () -> assertEquals(List.of("foo.txt"), type.parseArgLine("-select-file foo.txt").getSelectedFiles()), + () -> assertEquals(List.of("foo.txt"), type.parseArgLine("-select-file=foo.txt").getSelectedFiles()), + () -> assertEquals(List.of("foo.txt"), type.parseArgLine("--select-file foo.txt").getSelectedFiles()), + () -> assertEquals(List.of("foo.txt"), type.parseArgLine("--select-file=foo.txt").getSelectedFiles()), + () -> assertEquals(List.of("foo.txt", "bar.csv"), type.parseArgLine("-f foo.txt -f bar.csv").getSelectedFiles()) ); // @formatter:on } @@ -356,13 +352,13 @@ void parseInvalidFileSelectors() { void parseValidDirectorySelectors(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList("foo/bar"), type.parseArgLine("-d foo/bar").getSelectedDirectories()), - () -> assertEquals(singletonList("foo/bar"), type.parseArgLine("--d foo/bar").getSelectedDirectories()), - () -> assertEquals(singletonList("foo/bar"), type.parseArgLine("-select-directory foo/bar").getSelectedDirectories()), - () -> assertEquals(singletonList("foo/bar"), type.parseArgLine("-select-directory=foo/bar").getSelectedDirectories()), - () -> assertEquals(singletonList("foo/bar"), type.parseArgLine("--select-directory foo/bar").getSelectedDirectories()), - () -> assertEquals(singletonList("foo/bar"), type.parseArgLine("--select-directory=foo/bar").getSelectedDirectories()), - () -> assertEquals(asList("foo/bar", "bar/qux"), type.parseArgLine("-d foo/bar -d bar/qux").getSelectedDirectories()) + () -> assertEquals(List.of("foo/bar"), type.parseArgLine("-d foo/bar").getSelectedDirectories()), + () -> assertEquals(List.of("foo/bar"), type.parseArgLine("--d foo/bar").getSelectedDirectories()), + () -> assertEquals(List.of("foo/bar"), type.parseArgLine("-select-directory foo/bar").getSelectedDirectories()), + () -> assertEquals(List.of("foo/bar"), type.parseArgLine("-select-directory=foo/bar").getSelectedDirectories()), + () -> assertEquals(List.of("foo/bar"), type.parseArgLine("--select-directory foo/bar").getSelectedDirectories()), + () -> assertEquals(List.of("foo/bar"), type.parseArgLine("--select-directory=foo/bar").getSelectedDirectories()), + () -> assertEquals(List.of("foo/bar", "bar/qux"), type.parseArgLine("-d foo/bar -d bar/qux").getSelectedDirectories()) ); // @formatter:on } @@ -377,13 +373,13 @@ void parseInvalidDirectorySelectors() { void parseValidModuleSelectors(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("-o com.acme.foo").getSelectedModules()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("--o com.acme.foo").getSelectedModules()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("-select-module com.acme.foo").getSelectedModules()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("-select-module=com.acme.foo").getSelectedModules()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("--select-module com.acme.foo").getSelectedModules()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("--select-module=com.acme.foo").getSelectedModules()), - () -> assertEquals(asList("com.acme.foo", "com.example.bar"), type.parseArgLine("-o com.acme.foo -o com.example.bar").getSelectedModules()) + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("-o com.acme.foo").getSelectedModules()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("--o com.acme.foo").getSelectedModules()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("-select-module com.acme.foo").getSelectedModules()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("-select-module=com.acme.foo").getSelectedModules()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("--select-module com.acme.foo").getSelectedModules()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("--select-module=com.acme.foo").getSelectedModules()), + () -> assertEquals(List.of("com.acme.foo", "com.example.bar"), type.parseArgLine("-o com.acme.foo -o com.example.bar").getSelectedModules()) ); // @formatter:on } @@ -398,13 +394,13 @@ void parseInvalidModuleSelectors() { void parseValidPackageSelectors(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("-p com.acme.foo").getSelectedPackages()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("--p com.acme.foo").getSelectedPackages()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("-select-package com.acme.foo").getSelectedPackages()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("-select-package=com.acme.foo").getSelectedPackages()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("--select-package com.acme.foo").getSelectedPackages()), - () -> assertEquals(singletonList("com.acme.foo"), type.parseArgLine("--select-package=com.acme.foo").getSelectedPackages()), - () -> assertEquals(asList("com.acme.foo", "com.example.bar"), type.parseArgLine("-p com.acme.foo -p com.example.bar").getSelectedPackages()) + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("-p com.acme.foo").getSelectedPackages()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("--p com.acme.foo").getSelectedPackages()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("-select-package com.acme.foo").getSelectedPackages()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("-select-package=com.acme.foo").getSelectedPackages()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("--select-package com.acme.foo").getSelectedPackages()), + () -> assertEquals(List.of("com.acme.foo"), type.parseArgLine("--select-package=com.acme.foo").getSelectedPackages()), + () -> assertEquals(List.of("com.acme.foo", "com.example.bar"), type.parseArgLine("-p com.acme.foo -p com.example.bar").getSelectedPackages()) ); // @formatter:on } @@ -419,13 +415,13 @@ void parseInvalidPackageSelectors() { void parseValidClassSelectors(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList("com.acme.Foo"), type.parseArgLine("-c com.acme.Foo").getSelectedClasses()), - () -> assertEquals(singletonList("com.acme.Foo"), type.parseArgLine("--c com.acme.Foo").getSelectedClasses()), - () -> assertEquals(singletonList("com.acme.Foo"), type.parseArgLine("-select-class com.acme.Foo").getSelectedClasses()), - () -> assertEquals(singletonList("com.acme.Foo"), type.parseArgLine("-select-class=com.acme.Foo").getSelectedClasses()), - () -> assertEquals(singletonList("com.acme.Foo"), type.parseArgLine("--select-class com.acme.Foo").getSelectedClasses()), - () -> assertEquals(singletonList("com.acme.Foo"), type.parseArgLine("--select-class=com.acme.Foo").getSelectedClasses()), - () -> assertEquals(asList("com.acme.Foo", "com.example.Bar"), type.parseArgLine("-c com.acme.Foo -c com.example.Bar").getSelectedClasses()) + () -> assertEquals(List.of("com.acme.Foo"), type.parseArgLine("-c com.acme.Foo").getSelectedClasses()), + () -> assertEquals(List.of("com.acme.Foo"), type.parseArgLine("--c com.acme.Foo").getSelectedClasses()), + () -> assertEquals(List.of("com.acme.Foo"), type.parseArgLine("-select-class com.acme.Foo").getSelectedClasses()), + () -> assertEquals(List.of("com.acme.Foo"), type.parseArgLine("-select-class=com.acme.Foo").getSelectedClasses()), + () -> assertEquals(List.of("com.acme.Foo"), type.parseArgLine("--select-class com.acme.Foo").getSelectedClasses()), + () -> assertEquals(List.of("com.acme.Foo"), type.parseArgLine("--select-class=com.acme.Foo").getSelectedClasses()), + () -> assertEquals(List.of("com.acme.Foo", "com.example.Bar"), type.parseArgLine("-c com.acme.Foo -c com.example.Bar").getSelectedClasses()) ); // @formatter:on } @@ -440,13 +436,13 @@ void parseInvalidClassSelectors() { void parseValidMethodSelectors(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList("com.acme.Foo#m()"), type.parseArgLine("-m com.acme.Foo#m()").getSelectedMethods()), - () -> assertEquals(singletonList("com.acme.Foo#m()"), type.parseArgLine("--m com.acme.Foo#m()").getSelectedMethods()), - () -> assertEquals(singletonList("com.acme.Foo#m()"), type.parseArgLine("-select-method com.acme.Foo#m()").getSelectedMethods()), - () -> assertEquals(singletonList("com.acme.Foo#m()"), type.parseArgLine("-select-method=com.acme.Foo#m()").getSelectedMethods()), - () -> assertEquals(singletonList("com.acme.Foo#m()"), type.parseArgLine("--select-method com.acme.Foo#m()").getSelectedMethods()), - () -> assertEquals(singletonList("com.acme.Foo#m()"), type.parseArgLine("--select-method=com.acme.Foo#m()").getSelectedMethods()), - () -> assertEquals(asList("com.acme.Foo#m()", "com.example.Bar#method(java.lang.Object)"), + () -> assertEquals(List.of("com.acme.Foo#m()"), type.parseArgLine("-m com.acme.Foo#m()").getSelectedMethods()), + () -> assertEquals(List.of("com.acme.Foo#m()"), type.parseArgLine("--m com.acme.Foo#m()").getSelectedMethods()), + () -> assertEquals(List.of("com.acme.Foo#m()"), type.parseArgLine("-select-method com.acme.Foo#m()").getSelectedMethods()), + () -> assertEquals(List.of("com.acme.Foo#m()"), type.parseArgLine("-select-method=com.acme.Foo#m()").getSelectedMethods()), + () -> assertEquals(List.of("com.acme.Foo#m()"), type.parseArgLine("--select-method com.acme.Foo#m()").getSelectedMethods()), + () -> assertEquals(List.of("com.acme.Foo#m()"), type.parseArgLine("--select-method=com.acme.Foo#m()").getSelectedMethods()), + () -> assertEquals(List.of("com.acme.Foo#m()", "com.example.Bar#method(java.lang.Object)"), type.parseArgLine("-m com.acme.Foo#m() -m com.example.Bar#method(java.lang.Object)").getSelectedMethods()) ); // @formatter:on @@ -462,13 +458,13 @@ void parseInvalidMethodSelectors() { void parseValidClasspathResourceSelectors(ArgsType type) { // @formatter:off assertAll( - () -> assertEquals(singletonList("/foo.csv"), type.parseArgLine("-r /foo.csv").getSelectedClasspathResources()), - () -> assertEquals(singletonList("/foo.csv"), type.parseArgLine("--r /foo.csv").getSelectedClasspathResources()), - () -> assertEquals(singletonList("/foo.csv"), type.parseArgLine("-select-resource /foo.csv").getSelectedClasspathResources()), - () -> assertEquals(singletonList("/foo.csv"), type.parseArgLine("-select-resource=/foo.csv").getSelectedClasspathResources()), - () -> assertEquals(singletonList("/foo.csv"), type.parseArgLine("--select-resource /foo.csv").getSelectedClasspathResources()), - () -> assertEquals(singletonList("/foo.csv"), type.parseArgLine("--select-resource=/foo.csv").getSelectedClasspathResources()), - () -> assertEquals(asList("/foo.csv", "bar.json"), type.parseArgLine("-r /foo.csv -r bar.json").getSelectedClasspathResources()) + () -> assertEquals(List.of("/foo.csv"), type.parseArgLine("-r /foo.csv").getSelectedClasspathResources()), + () -> assertEquals(List.of("/foo.csv"), type.parseArgLine("--r /foo.csv").getSelectedClasspathResources()), + () -> assertEquals(List.of("/foo.csv"), type.parseArgLine("-select-resource /foo.csv").getSelectedClasspathResources()), + () -> assertEquals(List.of("/foo.csv"), type.parseArgLine("-select-resource=/foo.csv").getSelectedClasspathResources()), + () -> assertEquals(List.of("/foo.csv"), type.parseArgLine("--select-resource /foo.csv").getSelectedClasspathResources()), + () -> assertEquals(List.of("/foo.csv"), type.parseArgLine("--select-resource=/foo.csv").getSelectedClasspathResources()), + () -> assertEquals(List.of("/foo.csv", "bar.json"), type.parseArgLine("-r /foo.csv -r bar.json").getSelectedClasspathResources()) ); // @formatter:on } @@ -485,16 +481,16 @@ void parseClasspathScanningEntries(ArgsType type) { // @formatter:off assertAll( () -> assertTrue(type.parseArgLine("--scan-class-path").isScanClasspath()), - () -> assertEquals(emptyList(), type.parseArgLine("--scan-class-path").getSelectedClasspathEntries()), + () -> assertEquals(List.of(), type.parseArgLine("--scan-class-path").getSelectedClasspathEntries()), () -> assertTrue(type.parseArgLine("--scan-classpath").isScanClasspath()), - () -> assertEquals(emptyList(), type.parseArgLine("--scan-classpath").getSelectedClasspathEntries()), + () -> assertEquals(List.of(), type.parseArgLine("--scan-classpath").getSelectedClasspathEntries()), () -> assertTrue(type.parseArgLine("--scan-class-path .").isScanClasspath()), - () -> assertEquals(singletonList(dir), type.parseArgLine("--scan-class-path .").getSelectedClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("--scan-class-path=.").getSelectedClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("-scan-class-path .").getSelectedClasspathEntries()), - () -> assertEquals(singletonList(dir), type.parseArgLine("-scan-class-path=.").getSelectedClasspathEntries()), - () -> assertEquals(asList(dir, Paths.get("src/test/java")), type.parseArgLine("--scan-class-path . --scan-class-path src/test/java").getSelectedClasspathEntries()), - () -> assertEquals(asList(dir, Paths.get("src/test/java")), type.parseArgLine("--scan-class-path ." + File.pathSeparator + "src/test/java").getSelectedClasspathEntries()) + () -> assertEquals(List.of(dir), type.parseArgLine("--scan-class-path .").getSelectedClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("--scan-class-path=.").getSelectedClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("-scan-class-path .").getSelectedClasspathEntries()), + () -> assertEquals(List.of(dir), type.parseArgLine("-scan-class-path=.").getSelectedClasspathEntries()), + () -> assertEquals(List.of(dir, Paths.get("src/test/java")), type.parseArgLine("--scan-class-path . --scan-class-path src/test/java").getSelectedClasspathEntries()), + () -> assertEquals(List.of(dir, Paths.get("src/test/java")), type.parseArgLine("--scan-class-path ." + File.pathSeparator + "src/test/java").getSelectedClasspathEntries()) ); // @formatter:on } @@ -568,12 +564,12 @@ public void close() { } private void assertOptionWithMissingRequiredArgumentThrowsException(String... options) { - assertAll(stream(options).map( + assertAll(Stream.of(options).map( opt -> () -> assertThrows(JUnitException.class, () -> ArgsType.args.parseArgLine(opt)))); } private void assertParses(String name, Predicate property, String... argLines) { - stream(argLines).forEach(argLine -> { + Stream.of(argLines).forEach(argLine -> { CommandLineOptions options = null; try { options = ArgsType.args.parseArgLine(argLine); @@ -595,8 +591,7 @@ CommandLineOptions parseArgLine(String argLine) { CommandLineOptions parseArgLine(String argLine) throws IOException { var atFile = Files.createTempFile("junit-launcher-args", ".txt"); try { - var lines = Arrays.asList(split(argLine)); - Files.write(atFile, lines); + Files.write(atFile, List.of(split(argLine))); return createParser().parse("@" + atFile); } finally { diff --git a/platform-tests/src/test/java/org/junit/platform/console/tasks/ConsoleTestExecutorTests.java b/platform-tests/src/test/java/org/junit/platform/console/tasks/ConsoleTestExecutorTests.java index df1ab72617a5..b78479d7a3aa 100644 --- a/platform-tests/src/test/java/org/junit/platform/console/tasks/ConsoleTestExecutorTests.java +++ b/platform-tests/src/test/java/org/junit/platform/console/tasks/ConsoleTestExecutorTests.java @@ -10,8 +10,6 @@ package org.junit.platform.console.tasks; -import static java.util.Collections.emptyList; -import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertSame; @@ -22,6 +20,7 @@ import java.io.PrintWriter; import java.io.StringWriter; import java.nio.file.Paths; +import java.util.List; import org.junit.jupiter.api.Test; import org.junit.platform.console.ConsoleLauncherExecutionResult; @@ -151,7 +150,7 @@ void hasStatusCode0ForNoTestsAndNotFailIfNoTestsFound() throws Exception { @Test void usesCustomClassLoaderIfAdditionalClassPathEntriesArePresent() throws Exception { - options.setAdditionalClasspathEntries(singletonList(Paths.get("."))); + options.setAdditionalClasspathEntries(List.of(Paths.get("."))); var oldClassLoader = getDefaultClassLoader(); dummyTestEngine.addTest("failingTest", @@ -165,7 +164,7 @@ void usesCustomClassLoaderIfAdditionalClassPathEntriesArePresent() throws Except @Test void usesSameClassLoaderIfNoAdditionalClassPathEntriesArePresent() throws Exception { - options.setAdditionalClasspathEntries(emptyList()); + options.setAdditionalClasspathEntries(List.of()); var oldClassLoader = getDefaultClassLoader(); dummyTestEngine.addTest("failingTest", diff --git a/platform-tests/src/test/java/org/junit/platform/console/tasks/DiscoveryRequestCreatorTests.java b/platform-tests/src/test/java/org/junit/platform/console/tasks/DiscoveryRequestCreatorTests.java index cf7dc7a23d12..7543298649e7 100644 --- a/platform-tests/src/test/java/org/junit/platform/console/tasks/DiscoveryRequestCreatorTests.java +++ b/platform-tests/src/test/java/org/junit/platform/console/tasks/DiscoveryRequestCreatorTests.java @@ -10,8 +10,6 @@ package org.junit.platform.console.tasks; -import static java.util.Arrays.asList; -import static java.util.Collections.singletonList; import static java.util.stream.Collectors.toMap; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.entry; @@ -21,6 +19,7 @@ import java.io.File; import java.net.URI; import java.nio.file.Paths; +import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.stream.Stream; @@ -65,7 +64,7 @@ void convertsScanClasspathOptionWithoutExplicitRootDirectories() { @Test void convertsScanClasspathOptionWithExplicitRootDirectories() { options.setScanClasspath(true); - options.setSelectedClasspathEntries(asList(Paths.get("."), Paths.get(".."))); + options.setSelectedClasspathEntries(List.of(Paths.get("."), Paths.get(".."))); var request = convert(); @@ -79,7 +78,7 @@ void convertsScanClasspathOptionWithExplicitRootDirectories() { @Test void convertsScanClasspathOptionWithAdditionalClasspathEntries() { options.setScanClasspath(true); - options.setAdditionalClasspathEntries(asList(Paths.get("."), Paths.get(".."))); + options.setAdditionalClasspathEntries(List.of(Paths.get("."), Paths.get(".."))); var request = convert(); @@ -93,7 +92,7 @@ void convertsScanClasspathOptionWithAdditionalClasspathEntries() { @Test void doesNotSupportScanClasspathAndExplicitSelectors() { options.setScanClasspath(true); - options.setSelectedClasses(singletonList("SomeTest")); + options.setSelectedClasses(List.of("SomeTest")); Throwable cause = assertThrows(PreconditionViolationException.class, this::convert); @@ -114,7 +113,7 @@ void convertsDefaultIncludeClassNamePatternOption() { @Test void convertsExplicitIncludeClassNamePatternOption() { options.setScanClasspath(true); - options.setIncludedClassNamePatterns(asList("Foo.*Bar", "Bar.*Foo")); + options.setIncludedClassNamePatterns(List.of("Foo.*Bar", "Bar.*Foo")); var request = convert(); @@ -126,9 +125,9 @@ void convertsExplicitIncludeClassNamePatternOption() { @Test void includeSelectedClassesAndMethodsRegardlessOfClassNamePatterns() { - options.setSelectedClasses(singletonList("SomeTest")); - options.setSelectedMethods(asList("com.acme.Foo#m()")); - options.setIncludedClassNamePatterns(asList("Foo.*Bar")); + options.setSelectedClasses(List.of("SomeTest")); + options.setSelectedMethods(List.of("com.acme.Foo#m()")); + options.setIncludedClassNamePatterns(List.of("Foo.*Bar")); var request = convert(); @@ -142,7 +141,7 @@ void includeSelectedClassesAndMethodsRegardlessOfClassNamePatterns() { @Test void convertsExcludeClassNamePatternOption() { options.setScanClasspath(true); - options.setExcludedClassNamePatterns(asList("Foo.*Bar", "Bar.*Foo")); + options.setExcludedClassNamePatterns(List.of("Foo.*Bar", "Bar.*Foo")); var request = convert(); @@ -155,8 +154,8 @@ void convertsExcludeClassNamePatternOption() { @Test void convertsPackageOptions() { options.setScanClasspath(true); - options.setIncludedPackages(asList("org.junit.included1", "org.junit.included2", "org.junit.included3")); - options.setExcludedPackages(asList("org.junit.excluded1")); + options.setIncludedPackages(List.of("org.junit.included1", "org.junit.included2", "org.junit.included3")); + options.setExcludedPackages(List.of("org.junit.excluded1")); var request = convert(); var packageNameFilters = request.getFiltersByType(PackageNameFilter.class); @@ -171,8 +170,8 @@ void convertsPackageOptions() { @Test void convertsTagOptions() { options.setScanClasspath(true); - options.setIncludedTagExpressions(asList("fast", "medium", "slow")); - options.setExcludedTagExpressions(asList("slow")); + options.setIncludedTagExpressions(List.of("fast", "medium", "slow")); + options.setExcludedTagExpressions(List.of("slow")); var request = convert(); var postDiscoveryFilters = request.getPostDiscoveryFilters(); @@ -185,8 +184,8 @@ void convertsTagOptions() { @Test void convertsEngineOptions() { options.setScanClasspath(true); - options.setIncludedEngines(asList("engine1", "engine2", "engine3")); - options.setExcludedEngines(singletonList("engine2")); + options.setIncludedEngines(List.of("engine1", "engine2", "engine3")); + options.setExcludedEngines(List.of("engine2")); var request = convert(); var engineFilters = request.getEngineFilters(); @@ -198,7 +197,7 @@ void convertsEngineOptions() { @Test void convertsUriSelectors() { - options.setSelectedUris(asList(URI.create("a"), URI.create("b"))); + options.setSelectedUris(List.of(URI.create("a"), URI.create("b"))); var request = convert(); var uriSelectors = request.getSelectorsByType(UriSelector.class); @@ -208,7 +207,7 @@ void convertsUriSelectors() { @Test void convertsFileSelectors() { - options.setSelectedFiles(asList("foo.txt", "bar.csv")); + options.setSelectedFiles(List.of("foo.txt", "bar.csv")); var request = convert(); var fileSelectors = request.getSelectorsByType(FileSelector.class); @@ -218,7 +217,7 @@ void convertsFileSelectors() { @Test void convertsDirectorySelectors() { - options.setSelectedDirectories(asList("foo/bar", "bar/qux")); + options.setSelectedDirectories(List.of("foo/bar", "bar/qux")); var request = convert(); var directorySelectors = request.getSelectorsByType(DirectorySelector.class); @@ -228,7 +227,7 @@ void convertsDirectorySelectors() { @Test void convertsPackageSelectors() { - options.setSelectedPackages(asList("com.acme.foo", "com.example.bar")); + options.setSelectedPackages(List.of("com.acme.foo", "com.example.bar")); var request = convert(); var packageSelectors = request.getSelectorsByType(PackageSelector.class); @@ -239,7 +238,7 @@ void convertsPackageSelectors() { @Test void convertsClassSelectors() { - options.setSelectedClasses(asList("com.acme.Foo", "com.example.Bar")); + options.setSelectedClasses(List.of("com.acme.Foo", "com.example.Bar")); var request = convert(); var classSelectors = request.getSelectorsByType(ClassSelector.class); @@ -250,7 +249,7 @@ void convertsClassSelectors() { @Test void convertsMethodSelectors() { - options.setSelectedMethods(asList("com.acme.Foo#m()", "com.example.Bar#method(java.lang.Object)")); + options.setSelectedMethods(List.of("com.acme.Foo#m()", "com.example.Bar#method(java.lang.Object)")); var request = convert(); var methodSelectors = request.getSelectorsByType(MethodSelector.class); @@ -266,7 +265,7 @@ void convertsMethodSelectors() { @Test void convertsClasspathResourceSelectors() { - options.setSelectedClasspathResources(asList("foo.csv", "com/example/bar.json")); + options.setSelectedClasspathResources(List.of("foo.csv", "com/example/bar.json")); var request = convert(); var classpathResourceSelectors = request.getSelectorsByType(ClasspathResourceSelector.class); diff --git a/platform-tests/src/test/java/org/junit/platform/console/tasks/TreePrinterTests.java b/platform-tests/src/test/java/org/junit/platform/console/tasks/TreePrinterTests.java index d4fa5dea23a5..e7487fb9a994 100644 --- a/platform-tests/src/test/java/org/junit/platform/console/tasks/TreePrinterTests.java +++ b/platform-tests/src/test/java/org/junit/platform/console/tasks/TreePrinterTests.java @@ -22,8 +22,6 @@ import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import org.junit.jupiter.api.Test; @@ -43,7 +41,7 @@ class TreePrinterTests { private List actual() { try { out.flush(); - return Arrays.asList(stream.toString(charset.name()).split("\\R")); + return List.of(stream.toString(charset.name()).split("\\R")); } catch (UnsupportedEncodingException e) { throw new AssertionError(charset.name() + " is an unsupported encoding?!", e); @@ -53,7 +51,7 @@ private List actual() { @Test void emptyTree() { new TreePrinter(out, Theme.UNICODE, true).print(new TreeNode("")); - assertIterableEquals(Collections.singletonList("╷"), actual()); + assertIterableEquals(List.of("╷"), actual()); } @Test @@ -65,7 +63,7 @@ void emptyEngines() { root.addChild(new TreeNode(identifier("e-3", "engine three")).setResult(aborted(null))); new TreePrinter(out, Theme.UNICODE, true).print(root); assertIterableEquals( // - Arrays.asList( // + List.of( // "╷", // "├─ engine zero ↷ none", // "├─ engine one ✔", // @@ -80,7 +78,7 @@ void printNodeHandlesNullMessageThrowableGracefully() { var result = TestExecutionResult.failed(new NullPointerException()); var node = new TreeNode(identifier("NPE", "test()")).setResult(result); new TreePrinter(out, Theme.ASCII, true).print(node); - assertLinesMatch(Arrays.asList(".", "+-- test() [X] java.lang.NullPointerException"), actual()); + assertLinesMatch(List.of(".", "+-- test() [X] java.lang.NullPointerException"), actual()); } @Test diff --git a/platform-tests/src/test/java/org/junit/platform/engine/discovery/DiscoverySelectorsTests.java b/platform-tests/src/test/java/org/junit/platform/engine/discovery/DiscoverySelectorsTests.java index cd3d1705410a..c66a17059cf0 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/discovery/DiscoverySelectorsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/discovery/DiscoverySelectorsTests.java @@ -11,8 +11,6 @@ package org.junit.platform.engine.discovery; import static java.lang.String.join; -import static java.util.Collections.emptyList; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -35,9 +33,8 @@ import java.net.URI; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.Arrays; -import java.util.HashSet; import java.util.List; +import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -222,7 +219,7 @@ void selectModuleByNamePreconditions() { @Test void selectModulesByNames() { - var selectors = selectModules(new HashSet<>(Arrays.asList("a", "b"))); + var selectors = selectModules(Set.of("a", "b")); var names = selectors.stream().map(ModuleSelector::getModuleName).collect(Collectors.toList()); assertThat(names).containsExactlyInAnyOrder("b", "a"); } @@ -230,7 +227,7 @@ void selectModulesByNames() { @Test void selectModulesByNamesPreconditions() { assertViolatesPrecondition(() -> selectModules(null)); - assertViolatesPrecondition(() -> selectModules(new HashSet<>(Arrays.asList("a", " ")))); + assertViolatesPrecondition(() -> selectModules(Set.of("a", " "))); } @Test @@ -616,21 +613,21 @@ void selectMethodByClassAndNameForSpockSpec() { @Test void selectClasspathRootsWithNonExistingDirectory() { - var selectors = selectClasspathRoots(singleton(Paths.get("some", "local", "path"))); + var selectors = selectClasspathRoots(Set.of(Paths.get("some", "local", "path"))); assertThat(selectors).isEmpty(); } @Test void selectClasspathRootsWithNonExistingJarFile() { - var selectors = selectClasspathRoots(singleton(Paths.get("some.jar"))); + var selectors = selectClasspathRoots(Set.of(Paths.get("some.jar"))); assertThat(selectors).isEmpty(); } @Test void selectClasspathRootsWithExistingDirectory(@TempDir Path tempDir) { - var selectors = selectClasspathRoots(singleton(tempDir)); + var selectors = selectClasspathRoots(Set.of(tempDir)); assertThat(selectors).extracting(ClasspathRootSelector::getClasspathRoot).containsExactly(tempDir.toUri()); } @@ -640,7 +637,7 @@ void selectClasspathRootsWithExistingJarFile() throws Exception { var jarUri = getClass().getResource("/jartest.jar").toURI(); var jarFile = Paths.get(jarUri); - var selectors = selectClasspathRoots(singleton(jarFile)); + var selectors = selectClasspathRoots(Set.of(jarFile)); assertThat(selectors).extracting(ClasspathRootSelector::getClasspathRoot).containsExactly(jarUri); } @@ -680,7 +677,7 @@ void selectDoubleNestedClassByClassNames() { @Test void selectNestedClassPreconditions() { assertViolatesPrecondition(() -> selectNestedClass(null, "ClassName")); - assertViolatesPrecondition(() -> selectNestedClass(emptyList(), "ClassName")); + assertViolatesPrecondition(() -> selectNestedClass(List.of(), "ClassName")); assertViolatesPrecondition(() -> selectNestedClass(List.of("ClassName"), null)); assertViolatesPrecondition(() -> selectNestedClass(List.of("ClassName"), "")); assertViolatesPrecondition(() -> selectNestedClass(List.of("ClassName"), " ")); @@ -750,8 +747,8 @@ void selectDoubleNestedMethodByEnclosingClassNamesAndMethodName() throws Excepti void selectNestedMethodPreconditions() { assertViolatesPrecondition(() -> selectNestedMethod(null, "ClassName", "methodName")); assertViolatesPrecondition(() -> selectNestedMethod(null, "ClassName", "methodName", "int")); - assertViolatesPrecondition(() -> selectNestedMethod(emptyList(), "ClassName", "methodName")); - assertViolatesPrecondition(() -> selectNestedMethod(emptyList(), "ClassName", "methodName", "int")); + assertViolatesPrecondition(() -> selectNestedMethod(List.of(), "ClassName", "methodName")); + assertViolatesPrecondition(() -> selectNestedMethod(List.of(), "ClassName", "methodName", "int")); assertViolatesPrecondition(() -> selectNestedMethod(List.of("ClassName"), null, "methodName")); assertViolatesPrecondition(() -> selectNestedMethod(List.of("ClassName"), null, "methodName", "int")); assertViolatesPrecondition(() -> selectNestedMethod(List.of("ClassName"), " ", "methodName")); diff --git a/platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/CompositeTestSourceTests.java b/platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/CompositeTestSourceTests.java index 526386711d3b..059fc277bfec 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/CompositeTestSourceTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/support/descriptor/CompositeTestSourceTests.java @@ -15,14 +15,11 @@ import java.io.File; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.stream.Stream; import org.junit.jupiter.api.Test; import org.junit.platform.commons.PreconditionViolationException; -import org.junit.platform.engine.TestSource; /** * Unit tests for {@link CompositeTestSource}. @@ -35,7 +32,7 @@ class CompositeTestSourceTests extends AbstractTestSourceTests { Stream createSerializableInstances() { var fileSource = FileSource.from(new File("sample.instance")); var classSource = ClassSource.from(getClass()); - List sources = new ArrayList<>(Arrays.asList(fileSource, classSource)); + var sources = List.of(fileSource, classSource); return Stream.of(CompositeTestSource.from(sources)); } @@ -46,14 +43,14 @@ void createCompositeTestSourceFromNullList() { @Test void createCompositeTestSourceFromEmptyList() { - assertThrows(PreconditionViolationException.class, () -> CompositeTestSource.from(Collections.emptyList())); + assertThrows(PreconditionViolationException.class, () -> CompositeTestSource.from(List.of())); } @Test void createCompositeTestSourceFromClassAndFileSources() { var fileSource = FileSource.from(new File("example.test")); var classSource = ClassSource.from(getClass()); - List sources = new ArrayList<>(Arrays.asList(fileSource, classSource)); + var sources = new ArrayList<>(List.of(fileSource, classSource)); var compositeTestSource = CompositeTestSource.from(sources); assertThat(compositeTestSource.getSources().size()).isEqualTo(2); @@ -69,8 +66,8 @@ void createCompositeTestSourceFromClassAndFileSources() { @Test void equalsAndHashCode() { - List sources1 = Collections.singletonList(ClassSource.from(Number.class)); - List sources2 = Collections.singletonList(ClassSource.from(String.class)); + var sources1 = List.of(ClassSource.from(Number.class)); + var sources2 = List.of(ClassSource.from(String.class)); assertEqualsAndHashCode(CompositeTestSource.from(sources1), CompositeTestSource.from(sources1), CompositeTestSource.from(sources2)); } diff --git a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/CompositeLockTests.java b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/CompositeLockTests.java index ba253affcf6a..0ae2ec0aedcb 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/CompositeLockTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/CompositeLockTests.java @@ -10,13 +10,13 @@ package org.junit.platform.engine.support.hierarchical; -import static java.util.Arrays.asList; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.inOrder; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; +import java.util.List; import java.util.concurrent.CountDownLatch; import java.util.concurrent.locks.Lock; @@ -34,7 +34,7 @@ void acquiresAllLocksInOrder() throws Exception { var lock1 = mock(Lock.class); var lock2 = mock(Lock.class); - new CompositeLock(asList(lock1, lock2)).acquire(); + new CompositeLock(List.of(lock1, lock2)).acquire(); var inOrder = inOrder(lock1, lock2); inOrder.verify(lock1).lockInterruptibly(); @@ -47,7 +47,7 @@ void releasesAllLocksInReverseOrder() throws Exception { var lock1 = mock(Lock.class); var lock2 = mock(Lock.class); - new CompositeLock(asList(lock1, lock2)).acquire().close(); + new CompositeLock(List.of(lock1, lock2)).acquire().close(); var inOrder = inOrder(lock1, lock2); inOrder.verify(lock2).unlock(); @@ -64,7 +64,7 @@ void releasesLocksInReverseOrderWhenInterruptedDuringAcquire() throws Exception var thread = new Thread(() -> { try { - new CompositeLock(asList(firstLock, secondLock, unavailableLock)).acquire(); + new CompositeLock(List.of(firstLock, secondLock, unavailableLock)).acquire(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); diff --git a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/HierarchicalTestExecutorTests.java b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/HierarchicalTestExecutorTests.java index aeac3287abad..20167699afeb 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/HierarchicalTestExecutorTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/HierarchicalTestExecutorTests.java @@ -10,7 +10,6 @@ package org.junit.platform.engine.support.hierarchical; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -30,6 +29,7 @@ import static org.mockito.Mockito.when; import java.util.Map; +import java.util.Set; import java.util.concurrent.CompletableFuture; import java.util.concurrent.CountDownLatch; @@ -660,7 +660,7 @@ void dynamicTestDescriptorsMustNotDeclareExclusiveResources() { var child = spy(new MyLeaf(leafUniqueId)); var dynamicTestDescriptor = spy(new MyLeaf(leafUniqueId.append("dynamic", "child"))); when(dynamicTestDescriptor.getExclusiveResources()).thenReturn( - singleton(new ExclusiveResource("foo", LockMode.READ))); + Set.of(new ExclusiveResource("foo", LockMode.READ))); when(child.execute(any(), any())).thenAnswer(execute(dynamicTestDescriptor)); root.addChild(child); diff --git a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/LockManagerTests.java b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/LockManagerTests.java index 25e359e2ed0d..dac88f8367ff 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/LockManagerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/LockManagerTests.java @@ -10,9 +10,6 @@ package org.junit.platform.engine.support.hierarchical; -import static java.util.Arrays.asList; -import static java.util.Collections.emptySet; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.platform.engine.support.hierarchical.ExclusiveResource.GLOBAL_KEY; import static org.junit.platform.engine.support.hierarchical.ExclusiveResource.LockMode.READ; @@ -20,6 +17,7 @@ import java.util.Collection; import java.util.List; +import java.util.Set; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantReadWriteLock.ReadLock; import java.util.concurrent.locks.ReentrantReadWriteLock.WriteLock; @@ -38,7 +36,7 @@ class LockManagerTests { @Test void returnsNopLockWithoutExclusiveResources() { - Collection resources = emptySet(); + Collection resources = Set.of(); var locks = getLocks(resources, NopLock.class); @@ -47,7 +45,7 @@ void returnsNopLockWithoutExclusiveResources() { @Test void returnsSingleLockForSingleExclusiveResource() { - Collection resources = singleton(new ExclusiveResource("foo", READ)); + Collection resources = Set.of(new ExclusiveResource("foo", READ)); var locks = getLocks(resources, SingleLock.class); @@ -57,7 +55,7 @@ void returnsSingleLockForSingleExclusiveResource() { @Test void returnsCompositeLockForMultipleDifferentExclusiveResources() { - Collection resources = asList( // + Collection resources = List.of( // new ExclusiveResource("a", READ), // new ExclusiveResource("b", READ_WRITE)); @@ -70,7 +68,7 @@ void returnsCompositeLockForMultipleDifferentExclusiveResources() { @Test void reusesSameLockForExclusiveResourceWithSameKey() { - Collection resources = singleton(new ExclusiveResource("foo", READ)); + Collection resources = Set.of(new ExclusiveResource("foo", READ)); var locks1 = getLocks(resources, SingleLock.class); var locks2 = getLocks(resources, SingleLock.class); @@ -82,7 +80,7 @@ void reusesSameLockForExclusiveResourceWithSameKey() { @Test void returnsWriteLockForExclusiveResourceWithBothLockModes() { - Collection resources = asList( // + Collection resources = List.of( // new ExclusiveResource("bar", READ), // new ExclusiveResource("foo", READ), // new ExclusiveResource("foo", READ_WRITE), // @@ -98,7 +96,7 @@ void returnsWriteLockForExclusiveResourceWithBothLockModes() { @ParameterizedTest @EnumSource void globalLockComesFirst(LockMode globalLockMode) { - Collection resources = asList( // + Collection resources = List.of( // new ExclusiveResource("___foo", READ), // new ExclusiveResource("foo", READ_WRITE), // new ExclusiveResource(GLOBAL_KEY, globalLockMode), // @@ -114,7 +112,7 @@ void globalLockComesFirst(LockMode globalLockMode) { } private Lock getSingleLock(String globalResourceLockKey, LockMode read) { - return getLocks(singleton(new ExclusiveResource(globalResourceLockKey, read)), SingleLock.class).get(0); + return getLocks(Set.of(new ExclusiveResource(globalResourceLockKey, read)), SingleLock.class).get(0); } private List getLocks(Collection resources, Class type) { diff --git a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/NodeTreeWalkerIntegrationTests.java b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/NodeTreeWalkerIntegrationTests.java index 63ad8e7a60aa..88c397b59e1c 100644 --- a/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/NodeTreeWalkerIntegrationTests.java +++ b/platform-tests/src/test/java/org/junit/platform/engine/support/hierarchical/NodeTreeWalkerIntegrationTests.java @@ -10,7 +10,6 @@ package org.junit.platform.engine.support.hierarchical; -import static java.util.Collections.emptyList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.platform.commons.util.CollectionUtils.getOnlyElement; import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass; @@ -51,7 +50,7 @@ void pullUpExclusiveChildResourcesToTestClass() { assertThat(advisor.getForcedExecutionMode(testClassDescriptor)).isEmpty(); var testMethodDescriptor = getOnlyElement(testClassDescriptor.getChildren()); - assertThat(advisor.getResourceLock(testMethodDescriptor)).extracting(allLocks()).isEqualTo(emptyList()); + assertThat(advisor.getResourceLock(testMethodDescriptor)).extracting(allLocks()).isEqualTo(List.of()); assertThat(advisor.getForcedExecutionMode(testMethodDescriptor)).contains(SAME_THREAD); } @@ -79,7 +78,7 @@ void leavesResourceLockOnTestMethodWhenClassDoesNotUseResource() { assertThat(advisor.getForcedExecutionMode(nestedTestClassDescriptor)).isEmpty(); var nestedTestMethodDescriptor = getOnlyElement(nestedTestClassDescriptor.getChildren()); - assertThat(advisor.getResourceLock(nestedTestMethodDescriptor)).extracting(allLocks()).isEqualTo(emptyList()); + assertThat(advisor.getResourceLock(nestedTestMethodDescriptor)).extracting(allLocks()).isEqualTo(List.of()); assertThat(advisor.getForcedExecutionMode(nestedTestMethodDescriptor)).contains(SAME_THREAD); } diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/TestIdentifierTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/TestIdentifierTests.java index 8eacd6eecf57..9d4ca7878b0c 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/TestIdentifierTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/TestIdentifierTests.java @@ -10,13 +10,14 @@ package org.junit.platform.launcher; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.platform.commons.util.SerializationUtils.serializeAndDeserialize; +import java.util.Set; + import org.junit.jupiter.api.Test; import org.junit.platform.engine.TestDescriptor; import org.junit.platform.engine.TestTag; @@ -57,13 +58,13 @@ void inheritsTypeFromDescriptor() { void serialization() throws Exception { var identifier = serializeAndDeserialize(// new TestIdentifier("uniqueId", "displayName", ClassSource.from(TestIdentifierTests.class), - singleton(TestTag.create("aTag")), TestDescriptor.Type.TEST, "parentId", "reportingName")); + Set.of(TestTag.create("aTag")), TestDescriptor.Type.TEST, "parentId", "reportingName")); assertEquals("uniqueId", identifier.getUniqueId()); assertEquals("displayName", identifier.getDisplayName()); assertEquals("reportingName", identifier.getLegacyReportingName()); assertThat(identifier.getSource()).contains(ClassSource.from(TestIdentifierTests.class)); - assertEquals(singleton(TestTag.create("aTag")), identifier.getTags()); + assertEquals(Set.of(TestTag.create("aTag")), identifier.getTags()); assertEquals(TestDescriptor.Type.TEST, identifier.getType()); assertTrue(identifier.isTest()); assertFalse(identifier.isContainer()); diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/TestPlanTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/TestPlanTests.java index 33844ba6ceb0..f7f77f4e017a 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/TestPlanTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/TestPlanTests.java @@ -10,9 +10,10 @@ package org.junit.platform.launcher; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; +import java.util.Set; + import org.junit.jupiter.api.Test; import org.junit.platform.engine.UniqueId; import org.junit.platform.engine.support.descriptor.AbstractTestDescriptor; @@ -32,7 +33,7 @@ public Type getType() { } }); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); assertThat(testPlan.containsTests()).as("contains tests").isFalse(); } @@ -47,7 +48,7 @@ public Type getType() { } }); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); assertThat(testPlan.containsTests()).as("contains tests").isTrue(); } @@ -67,7 +68,7 @@ public boolean mayRegisterTests() { } }); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); assertThat(testPlan.containsTests()).as("contains tests").isTrue(); } diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherConfigurationParametersTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherConfigurationParametersTests.java index 29f144b96b2b..217a3705b006 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherConfigurationParametersTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherConfigurationParametersTests.java @@ -10,8 +10,6 @@ package org.junit.platform.launcher.core; -import static java.util.Collections.emptyMap; -import static java.util.Collections.singletonMap; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -52,14 +50,14 @@ void reset() { @Test void constructorPreconditions() { assertThrows(PreconditionViolationException.class, () -> fromMap(null)); - assertThrows(PreconditionViolationException.class, () -> fromMapAndFile(emptyMap(), null)); - assertThrows(PreconditionViolationException.class, () -> fromMapAndFile(emptyMap(), "")); - assertThrows(PreconditionViolationException.class, () -> fromMapAndFile(emptyMap(), " ")); + assertThrows(PreconditionViolationException.class, () -> fromMapAndFile(Map.of(), null)); + assertThrows(PreconditionViolationException.class, () -> fromMapAndFile(Map.of(), "")); + assertThrows(PreconditionViolationException.class, () -> fromMapAndFile(Map.of(), " ")); } @Test void getPreconditions() { - ConfigurationParameters configParams = fromMap(emptyMap()); + ConfigurationParameters configParams = fromMap(Map.of()); assertThrows(PreconditionViolationException.class, () -> configParams.get(null)); assertThrows(PreconditionViolationException.class, () -> configParams.get("")); assertThrows(PreconditionViolationException.class, () -> configParams.get(" ")); @@ -67,7 +65,7 @@ void getPreconditions() { @Test void noConfigParams() { - ConfigurationParameters configParams = fromMap(emptyMap()); + ConfigurationParameters configParams = fromMap(Map.of()); assertThat(configParams.size()).isEqualTo(0); assertThat(configParams.get(KEY)).isEmpty(); assertThat(configParams.toString()).doesNotContain(KEY); @@ -75,7 +73,7 @@ void noConfigParams() { @Test void explicitConfigParam() { - ConfigurationParameters configParams = fromMap(singletonMap(KEY, CONFIG_PARAM)); + ConfigurationParameters configParams = fromMap(Map.of(KEY, CONFIG_PARAM)); assertThat(configParams.get(KEY)).contains(CONFIG_PARAM); assertThat(configParams.toString()).contains(CONFIG_PARAM); } @@ -83,14 +81,14 @@ void explicitConfigParam() { @Test void systemProperty() { System.setProperty(KEY, SYSTEM_PROPERTY); - ConfigurationParameters configParams = fromMap(emptyMap()); + ConfigurationParameters configParams = fromMap(Map.of()); assertThat(configParams.get(KEY)).contains(SYSTEM_PROPERTY); assertThat(configParams.toString()).doesNotContain(KEY); } @Test void configFile() { - ConfigurationParameters configParams = fromMapAndFile(emptyMap(), CONFIG_FILE_NAME); + ConfigurationParameters configParams = fromMapAndFile(Map.of(), CONFIG_FILE_NAME); assertThat(configParams.get(KEY)).contains(CONFIG_FILE); assertThat(configParams.toString()).contains(CONFIG_FILE); } @@ -98,14 +96,14 @@ void configFile() { @Test void explicitConfigParamOverridesSystemProperty() { System.setProperty(KEY, SYSTEM_PROPERTY); - ConfigurationParameters configParams = fromMap(singletonMap(KEY, CONFIG_PARAM)); + ConfigurationParameters configParams = fromMap(Map.of(KEY, CONFIG_PARAM)); assertThat(configParams.get(KEY)).contains(CONFIG_PARAM); assertThat(configParams.toString()).contains(CONFIG_PARAM); } @Test void explicitConfigParamOverridesConfigFile() { - ConfigurationParameters configParams = fromMapAndFile(singletonMap(KEY, CONFIG_PARAM), CONFIG_FILE_NAME); + ConfigurationParameters configParams = fromMapAndFile(Map.of(KEY, CONFIG_PARAM), CONFIG_FILE_NAME); assertThat(configParams.get(KEY)).contains(CONFIG_PARAM); assertThat(configParams.toString()).contains(CONFIG_PARAM); } @@ -113,7 +111,7 @@ void explicitConfigParamOverridesConfigFile() { @Test void systemPropertyOverridesConfigFile() { System.setProperty(KEY, SYSTEM_PROPERTY); - ConfigurationParameters configParams = fromMapAndFile(emptyMap(), CONFIG_FILE_NAME); + ConfigurationParameters configParams = fromMapAndFile(Map.of(), CONFIG_FILE_NAME); assertThat(configParams.get(KEY)).contains(SYSTEM_PROPERTY); assertThat(configParams.toString()).contains(CONFIG_FILE); } @@ -130,13 +128,13 @@ void getValueInExtensionContext() { @Test void getWithSuccessfulTransformer() { - ConfigurationParameters configParams = fromMap(singletonMap(KEY, "42")); + ConfigurationParameters configParams = fromMap(Map.of(KEY, "42")); assertThat(configParams.get(KEY, Integer::valueOf)).contains(42); } @Test void getWithErroneousTransformer() { - ConfigurationParameters configParams = fromMap(singletonMap(KEY, "42")); + ConfigurationParameters configParams = fromMap(Map.of(KEY, "42")); var exception = assertThrows(JUnitException.class, () -> configParams.get(KEY, input -> { throw new RuntimeException("foo"); })); diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilderTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilderTests.java index 0b7634f48d39..a3d6833987c4 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilderTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/core/LauncherDiscoveryRequestBuilderTests.java @@ -10,7 +10,6 @@ package org.junit.platform.launcher.core; -import static java.util.Collections.singletonMap; import static java.util.stream.Collectors.toList; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; @@ -290,7 +289,7 @@ void multipleConfigurationParametersAddedDirectly_areStoredInDiscoveryRequest() void configurationParameterAddedByMap_isStoredInDiscoveryRequest() { // @formatter:off var discoveryRequest = request() - .configurationParameters(singletonMap("key", "value")) + .configurationParameters(Map.of("key", "value")) .build(); // @formatter:on diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/core/TestExecutionListenerRegistryTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/core/TestExecutionListenerRegistryTests.java index 43fa30e1d431..35d999c0ba4f 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/core/TestExecutionListenerRegistryTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/core/TestExecutionListenerRegistryTests.java @@ -14,7 +14,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.mock; -import java.util.Collections; +import java.util.Set; import java.util.logging.Level; import java.util.logging.LogRecord; @@ -96,7 +96,7 @@ void shouldNotThrowExceptionButLogIfTesPlanExecutionStartedListenerMethodFails( LogRecordListener logRecordListener) { var testDescriptor = getDemoMethodTestDescriptor(); - compositeTestExecutionListener.testPlanExecutionStarted(TestPlan.from(Collections.singleton(testDescriptor))); + compositeTestExecutionListener.testPlanExecutionStarted(TestPlan.from(Set.of(testDescriptor))); assertThatTestListenerErrorLogged(logRecordListener, ThrowingTestExecutionListener.class, "testPlanExecutionStarted"); @@ -107,7 +107,7 @@ void shouldNotThrowExceptionButLogIfTesPlanExecutionFinishedListenerMethodFails( LogRecordListener logRecordListener) { var testDescriptor = getDemoMethodTestDescriptor(); - compositeTestExecutionListener.testPlanExecutionFinished(TestPlan.from(Collections.singleton(testDescriptor))); + compositeTestExecutionListener.testPlanExecutionFinished(TestPlan.from(Set.of(testDescriptor))); assertThatTestListenerErrorLogged(logRecordListener, ThrowingTestExecutionListener.class, "testPlanExecutionFinished"); diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/listeners/SummaryGenerationTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/listeners/SummaryGenerationTests.java index e3e088e352fc..56fda7ca14d8 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/listeners/SummaryGenerationTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/listeners/SummaryGenerationTests.java @@ -18,7 +18,7 @@ import java.io.PrintWriter; import java.io.StringWriter; -import java.util.Collections; +import java.util.List; import java.util.Optional; import org.junit.jupiter.api.Test; @@ -36,7 +36,7 @@ class SummaryGenerationTests { private final SummaryGeneratingListener listener = new SummaryGeneratingListener(); - private final TestPlan testPlan = TestPlan.from(Collections.emptyList()); + private final TestPlan testPlan = TestPlan.from(List.of()); @Test void emptyReport() { diff --git a/platform-tests/src/test/java/org/junit/platform/launcher/tagexpression/TagExpressionsTests.java b/platform-tests/src/test/java/org/junit/platform/launcher/tagexpression/TagExpressionsTests.java index 76317c319023..64c68a997519 100644 --- a/platform-tests/src/test/java/org/junit/platform/launcher/tagexpression/TagExpressionsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/launcher/tagexpression/TagExpressionsTests.java @@ -10,7 +10,6 @@ package org.junit.platform.launcher.tagexpression; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.platform.engine.TestTag.create; @@ -21,7 +20,6 @@ import static org.junit.platform.launcher.tagexpression.TagExpressions.or; import static org.junit.platform.launcher.tagexpression.TagExpressions.tag; -import java.util.Collections; import java.util.Set; import org.junit.jupiter.api.Test; @@ -49,8 +47,8 @@ void rejectInvalidTestTags() { void tagEvaluation() { var tagExpression = tag("foo"); - assertThat(tagExpression.evaluate(singleton(create("foo")))).isTrue(); - assertThat(tagExpression.evaluate(singleton(create("not_foo")))).isFalse(); + assertThat(tagExpression.evaluate(Set.of(create("foo")))).isTrue(); + assertThat(tagExpression.evaluate(Set.of(create("not_foo")))).isFalse(); } @Test @@ -62,8 +60,8 @@ void justConcatenateNot() { @Test void notEvaluation() { - assertThat(not(True).evaluate(emptyTestTags())).isFalse(); - assertThat(not(False).evaluate(emptyTestTags())).isTrue(); + assertThat(not(True).evaluate(Set.of())).isFalse(); + assertThat(not(False).evaluate(Set.of())).isTrue(); } @Test @@ -73,9 +71,9 @@ void encloseAndWithParenthesis() { @Test void andEvaluation() { - assertThat(and(True, True).evaluate(emptyTestTags())).isTrue(); - assertThat(and(True, False).evaluate(emptyTestTags())).isFalse(); - assertThat(and(False, onEvaluateThrow()).evaluate(emptyTestTags())).isFalse(); + assertThat(and(True, True).evaluate(Set.of())).isTrue(); + assertThat(and(True, False).evaluate(Set.of())).isFalse(); + assertThat(and(False, onEvaluateThrow()).evaluate(Set.of())).isFalse(); } @Test @@ -85,20 +83,20 @@ void encloseOrWithParenthesis() { @Test void orEvaluation() { - assertThat(or(False, False).evaluate(emptyTestTags())).isFalse(); - assertThat(or(True, onEvaluateThrow()).evaluate(emptyTestTags())).isTrue(); - assertThat(or(False, True).evaluate(emptyTestTags())).isTrue(); + assertThat(or(False, False).evaluate(Set.of())).isFalse(); + assertThat(or(True, onEvaluateThrow()).evaluate(Set.of())).isTrue(); + assertThat(or(False, True).evaluate(Set.of())).isTrue(); } @Test void anyEvaluation() { - assertThat(any().evaluate(emptyTestTags())).isFalse(); + assertThat(any().evaluate(Set.of())).isFalse(); assertThat(any().evaluate(Set.of(TestTag.create("foo")))).isTrue(); } @Test void noneEvaluation() { - assertThat(none().evaluate(emptyTestTags())).isTrue(); + assertThat(none().evaluate(Set.of())).isTrue(); assertThat(none().evaluate(Set.of(TestTag.create("foo")))).isFalse(); } @@ -108,7 +106,4 @@ private TagExpression onEvaluateThrow() { }; } - private static Set emptyTestTags() { - return Collections.emptySet(); - } } diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/legacy/LegacyReportingUtilsTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/legacy/LegacyReportingUtilsTests.java index 18dfc914de42..1f9343c58a96 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/legacy/LegacyReportingUtilsTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/legacy/LegacyReportingUtilsTests.java @@ -10,9 +10,10 @@ package org.junit.platform.reporting.legacy; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; +import java.util.Set; + import org.junit.jupiter.api.Test; import org.junit.platform.engine.TestDescriptor; import org.junit.platform.engine.TestSource; @@ -69,13 +70,13 @@ void legacyReportingClassNameForDescendantOfTestIdentifierWithClassSourceIsClass } private String getClassName(UniqueId uniqueId) { - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); return LegacyReportingUtils.getClassName(testPlan, testPlan.getTestIdentifier(uniqueId.toString())); } @SuppressWarnings("deprecation") private String getClassNameFromOldLocation(UniqueId uniqueId) { - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); return org.junit.platform.launcher.listeners.LegacyReportingUtils.getClassName(testPlan, testPlan.getTestIdentifier(uniqueId.toString())); } diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListenerTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListenerTests.java index 6b2927a09584..bf834c0ed939 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListenerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/LegacyXmlReportGeneratingListenerTests.java @@ -10,8 +10,6 @@ package org.junit.platform.reporting.legacy.xml; -import static java.util.Collections.emptySet; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -37,6 +35,7 @@ import java.time.ZonedDateTime; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Set; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.TestReporter; @@ -335,12 +334,12 @@ void writesHostNameAndTimestamp(@TempDir Path tempDirectory) throws Exception { @Test void printsExceptionWhenReportsDirCannotBeCreated(@TempDir Path tempDirectory) throws Exception { var reportsDir = tempDirectory.resolve("dummy.txt"); - Files.write(reportsDir, singleton("content")); + Files.write(reportsDir, Set.of("content")); var out = new StringWriter(); var listener = new LegacyXmlReportGeneratingListener(reportsDir, new PrintWriter(out)); - listener.testPlanExecutionStarted(TestPlan.from(emptySet())); + listener.testPlanExecutionStarted(TestPlan.from(Set.of())); assertThat(out.toString()).containsSubsequence("Could not create reports directory", "FileAlreadyExistsException", "at "); @@ -356,7 +355,7 @@ void printsExceptionWhenReportCouldNotBeWritten(@TempDir Path tempDirectory) thr var out = new StringWriter(); var listener = new LegacyXmlReportGeneratingListener(tempDirectory, new PrintWriter(out)); - listener.testPlanExecutionStarted(TestPlan.from(singleton(engineDescriptor))); + listener.testPlanExecutionStarted(TestPlan.from(Set.of(engineDescriptor))); listener.executionFinished(TestIdentifier.from(engineDescriptor), successful()); assertThat(out.toString()).containsSubsequence("Could not write XML report", "Exception", "at "); @@ -367,7 +366,7 @@ void writesReportEntriesToSystemOutElement(@TempDir Path tempDirectory, TestRepo throws Exception { var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine"); engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test")); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var out = new StringWriter(); var listener = new LegacyXmlReportGeneratingListener(tempDirectory, new PrintWriter(out)); diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/XmlReportDataTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/XmlReportDataTests.java index b23157d56dc6..ca13a6782cb9 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/XmlReportDataTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/XmlReportDataTests.java @@ -10,12 +10,12 @@ package org.junit.platform.reporting.legacy.xml; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.platform.engine.TestExecutionResult.failed; import static org.junit.platform.engine.TestExecutionResult.successful; import java.time.Clock; +import java.util.Set; import org.junit.jupiter.api.Test; import org.junit.platform.engine.UniqueId; @@ -32,7 +32,7 @@ class XmlReportDataTests { void resultOfTestIdentifierWithoutAnyReportedEventsIsEmpty() { var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine"); engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test")); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); var result = reportData.getResult(testPlan.getTestIdentifier("[child:test]")); @@ -44,7 +44,7 @@ void resultOfTestIdentifierWithoutAnyReportedEventsIsEmpty() { void resultOfTestIdentifierWithoutReportedEventsIsFailureOfAncestor() { var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine"); engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test")); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); var failureOfAncestor = failed(new RuntimeException("failed!")); @@ -59,7 +59,7 @@ void resultOfTestIdentifierWithoutReportedEventsIsFailureOfAncestor() { void resultOfTestIdentifierWithoutReportedEventsIsEmptyWhenAncestorWasSuccessful() { var engineDescriptor = new EngineDescriptor(UniqueId.forEngine("engine"), "Engine"); engineDescriptor.addChild(new TestDescriptorStub(UniqueId.root("child", "test"), "test")); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); reportData.markFinished(testPlan.getTestIdentifier("[engine:engine]"), successful()); diff --git a/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/XmlReportWriterTests.java b/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/XmlReportWriterTests.java index bf0b797a958b..c47dae5d1239 100644 --- a/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/XmlReportWriterTests.java +++ b/platform-tests/src/test/java/org/junit/platform/reporting/legacy/xml/XmlReportWriterTests.java @@ -10,7 +10,6 @@ package org.junit.platform.reporting.legacy.xml; -import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.params.provider.Arguments.arguments; @@ -25,6 +24,7 @@ import java.io.Writer; import java.time.Clock; import java.util.Map; +import java.util.Set; import java.util.stream.Stream; import org.junit.jupiter.api.Test; @@ -48,7 +48,7 @@ class XmlReportWriterTests { @Test void writesTestsuiteElementsWithoutTestcaseElementsWithoutAnyTests() throws Exception { - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); @@ -69,7 +69,7 @@ void writesReportEntry() throws Exception { var uniqueId = engineDescriptor.getUniqueId().append("test", "test"); var testDescriptor = new TestDescriptorStub(uniqueId, "successfulTest"); engineDescriptor.addChild(testDescriptor); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); reportData.addReportEntry(TestIdentifier.from(testDescriptor), ReportEntry.from("myKey", "myValue")); @@ -93,7 +93,7 @@ void writesCapturedOutput() throws Exception { var uniqueId = engineDescriptor.getUniqueId().append("test", "test"); var testDescriptor = new TestDescriptorStub(uniqueId, "successfulTest"); engineDescriptor.addChild(testDescriptor); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); var reportEntry = ReportEntry.from(Map.of( // @@ -134,7 +134,7 @@ void writesCapturedOutput() throws Exception { void writesEmptySkippedElementForSkippedTestWithoutReason() throws Exception { var uniqueId = engineDescriptor.getUniqueId().append("test", "test"); engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "skippedTest")); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); reportData.markSkipped(testPlan.getTestIdentifier(uniqueId.toString()), null); @@ -166,7 +166,7 @@ public String getLegacyReportingName() { return "failedTest"; } }); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(null)); @@ -187,7 +187,7 @@ public String getLegacyReportingName() { void omitsMessageAttributeForFailedTestWithThrowableWithoutMessage() throws Exception { var uniqueId = engineDescriptor.getUniqueId().append("test", "test"); engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "failedTest")); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); reportData.markFinished(testPlan.getTestIdentifier(uniqueId.toString()), failed(new NullPointerException())); @@ -208,7 +208,7 @@ void omitsMessageAttributeForFailedTestWithThrowableWithoutMessage() throws Exce void writesValidXmlEvenIfExceptionMessageContainsCData() throws Exception { var uniqueId = engineDescriptor.getUniqueId().append("test", "test"); engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test")); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); var assertionError = new AssertionError(""); @@ -231,7 +231,7 @@ void writesValidXmlEvenIfExceptionMessageContainsCData() throws Exception { void escapesInvalidCharactersInSystemPropertiesAndExceptionMessages(TestInfo testInfo) throws Exception { var uniqueId = engineDescriptor.getUniqueId().append("test", "test"); engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test")); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); var assertionError = new AssertionError("expected: but was: "); @@ -257,7 +257,7 @@ void escapesInvalidCharactersInSystemPropertiesAndExceptionMessages(TestInfo tes void doesNotReopenCDataWithinCDataContent() throws Exception { var uniqueId = engineDescriptor.getUniqueId().append("test", "test"); engineDescriptor.addChild(new TestDescriptorStub(uniqueId, "test")); - var testPlan = TestPlan.from(singleton(engineDescriptor)); + var testPlan = TestPlan.from(Set.of(engineDescriptor)); var reportData = new XmlReportData(testPlan, Clock.systemDefaultZone()); var assertionError = new AssertionError(""); diff --git a/platform-tests/src/test/java/org/junit/platform/runner/JUnitPlatformRunnerTests.java b/platform-tests/src/test/java/org/junit/platform/runner/JUnitPlatformRunnerTests.java index bbde830b43c5..2f9b6075a8ea 100644 --- a/platform-tests/src/test/java/org/junit/platform/runner/JUnitPlatformRunnerTests.java +++ b/platform-tests/src/test/java/org/junit/platform/runner/JUnitPlatformRunnerTests.java @@ -10,9 +10,6 @@ package org.junit.platform.runner; -import static java.util.Arrays.asList; -import static java.util.Collections.emptySet; -import static java.util.Collections.singleton; import static java.util.stream.Collectors.toSet; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.fail; @@ -40,6 +37,7 @@ import java.util.Arrays; import java.util.List; +import java.util.Set; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; @@ -434,7 +432,7 @@ void convertsTestIdentifiersIntoDescriptions() { TestDescriptor container2 = new TestDescriptorStub(UniqueId.root("root", "container2"), "container2"); container2.addChild(new TestDescriptorStub(UniqueId.root("root", "test2a"), "test2a")); container2.addChild(new TestDescriptorStub(UniqueId.root("root", "test2b"), "test2b")); - var testPlan = TestPlan.from(asList(container1, container2)); + var testPlan = TestPlan.from(List.of(container1, container2)); var launcher = mock(Launcher.class); when(launcher.discover(any())).thenReturn(testPlan); @@ -471,11 +469,11 @@ void appliesFilter() throws Exception { TestDescriptor originalParent2 = new TestDescriptorStub(UniqueId.root("root", "parent2"), "parent2"); originalParent2.addChild(new TestDescriptorStub(UniqueId.root("root", "leaf2a"), "leaf2a")); originalParent2.addChild(new TestDescriptorStub(UniqueId.root("root", "leaf2b"), "leaf2b")); - var fullTestPlan = TestPlan.from(asList(originalParent1, originalParent2)); + var fullTestPlan = TestPlan.from(List.of(originalParent1, originalParent2)); TestDescriptor filteredParent = new TestDescriptorStub(UniqueId.root("root", "parent2"), "parent2"); filteredParent.addChild(new TestDescriptorStub(UniqueId.root("root", "leaf2b"), "leaf2b")); - var filteredTestPlan = TestPlan.from(singleton(filteredParent)); + var filteredTestPlan = TestPlan.from(Set.of(filteredParent)); var launcher = mock(Launcher.class); var captor = ArgumentCaptor.forClass(LauncherDiscoveryRequest.class); @@ -497,7 +495,7 @@ void appliesFilter() throws Exception { @Test void throwsNoTestsRemainExceptionWhenNoTestIdentifierMatchesFilter() { - var testPlan = TestPlan.from(singleton(new TestDescriptorStub(UniqueId.root("root", "test"), "test"))); + var testPlan = TestPlan.from(Set.of(new TestDescriptorStub(UniqueId.root("root", "test"), "test"))); var launcher = mock(Launcher.class); when(launcher.discover(any())).thenReturn(testPlan); @@ -735,7 +733,7 @@ private TestDescriptor testDescriptorWithTags(String... tag) { private LauncherDiscoveryRequest instantiateRunnerAndCaptureGeneratedRequest(Class testClass) { var launcher = mock(Launcher.class); var captor = ArgumentCaptor.forClass(LauncherDiscoveryRequest.class); - when(launcher.discover(captor.capture())).thenReturn(TestPlan.from(emptySet())); + when(launcher.discover(captor.capture())).thenReturn(TestPlan.from(Set.of())); new JUnitPlatform(testClass, launcher);