diff --git a/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceMojoTest.java b/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceMojoTest.java index 79214711a5..98c01821a7 100644 --- a/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceMojoTest.java +++ b/eo-maven-plugin/src/test/java/org/eolang/maven/UnplaceMojoTest.java @@ -32,6 +32,7 @@ import java.util.Map; import java.util.Set; import java.util.UUID; +import java.util.stream.Stream; import org.cactoos.text.TextOf; import org.eolang.maven.tojos.PlacedTojo; import org.eolang.maven.tojos.PlacedTojos; @@ -41,6 +42,9 @@ import org.hamcrest.io.FileMatchers; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.Arguments; +import org.junit.jupiter.params.provider.MethodSource; /** * Test case for {@link UnplaceMojo}. @@ -124,61 +128,42 @@ void keepsJarBecauseItIsStillInUse(@TempDir final Path temp) throws IOException ); } - @Test - void unplacesWithKeepAndRemoveBinariesParamTogether(@TempDir final Path temp) throws Exception { - final Path placed = UnplaceMojoTest.placeClass(temp, UnplaceMojoTest.clazz(temp)); - final Map res = UnplaceMojoTest.fakeResult( - temp, placed, KeepRemoveBinaries.KEEP_REMOVE - ); - MatcherAssert.assertThat( - res.values().stream().noneMatch(UnplaceMojoTest::isClass), - Matchers.is(true) - ); - MatcherAssert.assertThat( - new TextOf(res.get(placed.getFileName().toString())).asString(), - Matchers.allOf( - Matchers.not(Matchers.containsString("false")), - Matchers.containsString("true") - ) - ); - } - - @Test - void unplacesWithRemoveBinariesParam(@TempDir final Path temp) throws Exception { - final Path placed = UnplaceMojoTest.placeClass(temp, UnplaceMojoTest.clazz(temp)); - final Map res = UnplaceMojoTest.fakeResult( - temp, placed, KeepRemoveBinaries.REMOVE - ); - MatcherAssert.assertThat( - res.values().stream().noneMatch(UnplaceMojoTest::isClass), - Matchers.is(true) - ); - MatcherAssert.assertThat( - new TextOf(res.get(placed.getFileName().toString())).asString(), - Matchers.allOf( - Matchers.not(Matchers.containsString("false")), - Matchers.containsString("true") - ) - ); - } - - @Test - void unplacesWithKeepBinariesParam(@TempDir final Path temp) throws Exception { + @ParameterizedTest + @MethodSource("testArgsProvider") + void unplacesWithKeepOrRemoveBinariesParam(final String[] params, @TempDir final Path temp) + throws Exception { final Path placed = UnplaceMojoTest.placeClass(temp, UnplaceMojoTest.clazz(temp)); - final Map res = UnplaceMojoTest.fakeResult( - temp, placed, KeepRemoveBinaries.KEEP - ); - MatcherAssert.assertThat( - res.values().stream().anyMatch(UnplaceMojoTest::isClass), - Matchers.is(true) - ); - MatcherAssert.assertThat( - new TextOf(res.get(placed.getFileName().toString())).asString(), - Matchers.allOf( - Matchers.containsString("false"), - Matchers.not(Matchers.containsString("true")) - ) - ); + final FakeMaven maven = new FakeMaven(temp) + .with("placed", placed.toFile()); + for (final String param : params) { + maven.with(param, UnplaceMojoTest.GLOB_PATTERN); + } + final Map res = maven.execute(UnplaceMojo.class).result(); + if (params.length == 1 && "keepBinaries".equals(params[0])) { + MatcherAssert.assertThat( + res.values().stream().anyMatch(UnplaceMojoTest::isClass), + Matchers.is(true) + ); + MatcherAssert.assertThat( + new TextOf(res.get(placed.getFileName().toString())).asString(), + Matchers.allOf( + Matchers.containsString("false"), + Matchers.not(Matchers.containsString("true")) + ) + ); + } else { + MatcherAssert.assertThat( + res.values().stream().noneMatch(UnplaceMojoTest::isClass), + Matchers.is(true) + ); + MatcherAssert.assertThat( + new TextOf(res.get(placed.getFileName().toString())).asString(), + Matchers.allOf( + Matchers.not(Matchers.containsString("false")), + Matchers.containsString("true") + ) + ); + } } @Test @@ -291,53 +276,16 @@ private static boolean isClass(final Path path) { } /** - * Set of parameters for {@link FakeMaven}. - */ - private enum KeepRemoveBinaries { - /** - * {@code "keepBinaries"} param. - */ - KEEP, - - /** - * {@code "removeBinaries"} param. - */ - REMOVE, - - /** - * {@code "keepBinaries"} and {@code "removeBinaries"} params. - */ - KEEP_REMOVE - } - - /** - * Instantiates {@link FakeMaven} with given parameters, executes it and return result. + * Input arguments for unit tests. * - * @param temp Test temporary directory. - * @param placed Path to the placed tojos file. - * @param action Action to be performed with binaries. - * @return The result map with all files and folders that was created or compiled during fake - * mojo execution. + * @return Stream of arguments. */ - private static Map fakeResult( - final Path temp, final Path placed, final KeepRemoveBinaries action) throws IOException { - final FakeMaven maven = new FakeMaven(temp) - .with("placed", placed.toFile()); - switch (action) { - case KEEP: - maven.with("keepBinaries", UnplaceMojoTest.GLOB_PATTERN); - break; - case REMOVE: - maven.with("removeBinaries", UnplaceMojoTest.GLOB_PATTERN); - break; - case KEEP_REMOVE: - maven.with("keepBinaries", UnplaceMojoTest.GLOB_PATTERN) - .with("removeBinaries", UnplaceMojoTest.GLOB_PATTERN); - break; - default: - throw new IllegalArgumentException("No such option"); - } - return maven.execute(UnplaceMojo.class).result(); + private static Stream testArgsProvider() { + return Stream.of( + Arguments.of((Object) new String[]{"keepBinaries"}), + Arguments.of((Object) new String[]{"removeBinaries"}), + Arguments.of((Object) new String[]{"keepBinaries", "removeBinaries"}) + ); } }