diff --git a/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java b/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java index 58ddc85..f1ba5fd 100644 --- a/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java +++ b/src/test/java/org/apache/maven/plugins/jlink/JLinkMojoTest.java @@ -24,20 +24,25 @@ import org.apache.maven.shared.utils.cli.Commandline; import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; public class JLinkMojoTest { - @Test - void double_quote_every_argument() throws Exception { + private JLinkMojo mojo = new JLinkMojo(); + + @BeforeEach + public void setUp() throws NoSuchFieldException, IllegalAccessException { // given - JLinkMojo mojo = new JLinkMojo(); Field stripDebug = mojo.getClass().getDeclaredField("stripDebug"); stripDebug.setAccessible(true); stripDebug.set(mojo, Boolean.TRUE); + } + @Test + void double_quote_every_argument() throws Exception { // when List jlinkArgs = mojo.createJlinkArgs(List.of(), List.of()); @@ -46,16 +51,8 @@ void double_quote_every_argument() throws Exception { } @Test - void single_quotes_shell_command() throws Exception { - - Assumptions.assumeFalse("windows".equals(System.getProperty("os.name"))); - // TODO add a test for Windows - - // given - JLinkMojo mojo = new JLinkMojo(); - Field stripDebug = mojo.getClass().getDeclaredField("stripDebug"); - stripDebug.setAccessible(true); - stripDebug.set(mojo, Boolean.TRUE); + void single_quotes_shell_command_unix() throws Exception { + Assumptions.assumeFalse(System.getProperty("os.name").startsWith("Windows")); // when List jlinkArgs = mojo.createJlinkArgs(List.of("foo", "bar"), List.of("mvn", "jlink")); @@ -66,4 +63,19 @@ void single_quotes_shell_command() throws Exception { .isEqualTo( "/bin/sh -c '/path/to/jlink \"--strip-debug\" \"--module-path\" \"foo:bar\" \"--add-modules\" \"mvn,jlink\"'"); } + + @Test + void single_quotes_shell_command_windows() throws Exception { + Assumptions.assumeTrue(System.getProperty("os.name").startsWith("Windows")); + + // when + List jlinkArgs = mojo.createJlinkArgs(List.of("foo", "bar"), List.of("mvn", "jlink")); + Commandline cmdLine = JLinkExecutor.createJLinkCommandLine(new File("/path/to/jlink"), jlinkArgs); + + // then + assertThat(cmdLine.toString()).startsWith("cmd.exe "); + assertThat(cmdLine.toString()) + .contains( + "\\path\\to\\jlink \"-strip-debug\" \"module-path\" \"foo;bar\" \"-add-modules\" \"mvn,jlink"); + } }