Skip to content

Commit 26e3991

Browse files
committed
tests fix
1 parent d0b6d4c commit 26e3991

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ public void should_create_pre_hook_file_when_hook_file_does_not_exists() throws
4141
assertThat(output).contains("Git pre-push hook not found, creating it");
4242
assertThat(output).contains("Git pre-push hook installed successfully to the file " + newFile(".git/hooks/pre-push"));
4343

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);
44+
assertFile(".git/hooks/pre-push").hasContent(getHookContent());
4945
}
5046

5147
@Test
@@ -67,11 +63,7 @@ public void should_append_to_existing_pre_hook_file_when_hook_file_exists() thro
6763
assertThat(output).contains("Installing git pre-push hook");
6864
assertThat(output).contains("Git pre-push hook installed successfully to the file " + newFile(".git/hooks/pre-push"));
6965

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);
66+
assertFile(".git/hooks/pre-push").hasContent(getHookContent());
7567
}
7668

7769
private void writePomWithJavaLicenseHeaderStep() throws IOException {
@@ -80,4 +72,18 @@ private void writePomWithJavaLicenseHeaderStep() throws IOException {
8072
" <file>${basedir}/license.txt</file>",
8173
"</licenseHeader>");
8274
}
75+
76+
private String getHookContent() {
77+
String executorPath = "./" + newFile("mvnw").getName();
78+
if (newFile("mvnw.bat").exists()) {
79+
executorPath = newFile("mvnw.bat").getName();
80+
} else if (newFile("mvnw.cmd").exists()) {
81+
executorPath = newFile("mvnw.cmd").getName();
82+
}
83+
84+
return getTestResource("git_pre_hook/pre-push.existing-installed-end-tpl")
85+
.replace("${executor}", "./" + executorPath)
86+
.replace("${checkCommand}", "spotless:check")
87+
.replace("${applyCommand}", "spotless:apply");
88+
}
8389
}

0 commit comments

Comments
 (0)