Skip to content

Commit cbe5b74

Browse files
committed
tests fix
1 parent d0b6d4c commit cbe5b74

File tree

1 file changed

+26
-10
lines changed

1 file changed

+26
-10
lines changed

plugin-maven/src/test/java/com/diffplug/spotless/maven/SpotlessInstallPrePushHookMojoTest.java

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@
1717

1818
import static org.assertj.core.api.Assertions.assertThat;
1919

20+
import java.io.File;
2021
import java.io.IOException;
22+
import java.util.Locale;
2123

2224
import org.junit.jupiter.api.Test;
2325

@@ -41,11 +43,8 @@ public void should_create_pre_hook_file_when_hook_file_does_not_exists() throws
4143
assertThat(output).contains("Git pre-push hook not found, creating it");
4244
assertThat(output).contains("Git pre-push hook installed successfully to the file " + newFile(".git/hooks/pre-push"));
4345

44-
final var content = getTestResource("git_pre_hook/pre-push.created-tpl")
45-
.replace("${executor}", newFile("mvnw").getAbsolutePath())
46-
.replace("${checkCommand}", "spotless:check")
47-
.replace("${applyCommand}", "spotless:apply");
48-
assertFile(".git/hooks/pre-push").hasContent(content);
46+
final var hookContent = getHookContent("git_pre_hook/pre-push.created-tpl");
47+
assertFile(".git/hooks/pre-push").hasContent(hookContent);
4948
}
5049

5150
@Test
@@ -67,11 +66,8 @@ public void should_append_to_existing_pre_hook_file_when_hook_file_exists() thro
6766
assertThat(output).contains("Installing git pre-push hook");
6867
assertThat(output).contains("Git pre-push hook installed successfully to the file " + newFile(".git/hooks/pre-push"));
6968

70-
final var content = getTestResource("git_pre_hook/pre-push.existing-installed-end-tpl")
71-
.replace("${executor}", newFile("mvnw").getAbsolutePath())
72-
.replace("${checkCommand}", "spotless:check")
73-
.replace("${applyCommand}", "spotless:apply");
74-
assertFile(".git/hooks/pre-push").hasContent(content);
69+
final var hookContent = getHookContent("git_pre_hook/pre-push.existing-installed-end-tpl");
70+
assertFile(".git/hooks/pre-push").hasContent(hookContent);
7571
}
7672

7773
private void writePomWithJavaLicenseHeaderStep() throws IOException {
@@ -80,4 +76,24 @@ private void writePomWithJavaLicenseHeaderStep() throws IOException {
8076
" <file>${basedir}/license.txt</file>",
8177
"</licenseHeader>");
8278
}
79+
80+
private String getHookContent(String resourceFile) {
81+
return getTestResource(resourceFile)
82+
.replace("${executor}", "./" + executorWrapperFile().getName())
83+
.replace("${checkCommand}", "spotless:check")
84+
.replace("${applyCommand}", "spotless:apply");
85+
}
86+
87+
private File executorWrapperFile() {
88+
if (System.getProperty("os.name").toLowerCase(Locale.ROOT).startsWith("win")) {
89+
final var bat = newFile("mvnw.bat");
90+
if (bat.exists()) {
91+
return bat;
92+
}
93+
94+
return newFile("mvnw.cmd");
95+
}
96+
97+
return newFile("mvnw");
98+
}
8399
}

0 commit comments

Comments
 (0)