Skip to content

Commit 1d811c5

Browse files
committed
tests fix
1 parent d0b6d4c commit 1d811c5

1 file changed

Lines changed: 18 additions & 10 deletions

File tree

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

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,8 @@ 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+
final var hookContent = getHookContent("git_pre_hook/pre-push.created-tpl");
45+
assertFile(".git/hooks/pre-push").hasContent(hookContent);
4946
}
5047

5148
@Test
@@ -67,11 +64,8 @@ public void should_append_to_existing_pre_hook_file_when_hook_file_exists() thro
6764
assertThat(output).contains("Installing git pre-push hook");
6865
assertThat(output).contains("Git pre-push hook installed successfully to the file " + newFile(".git/hooks/pre-push"));
6966

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);
67+
final var hookContent = getHookContent("git_pre_hook/pre-push.existing-installed-end-tpl");
68+
assertFile(".git/hooks/pre-push").hasContent(hookContent);
7569
}
7670

7771
private void writePomWithJavaLicenseHeaderStep() throws IOException {
@@ -80,4 +74,18 @@ private void writePomWithJavaLicenseHeaderStep() throws IOException {
8074
" <file>${basedir}/license.txt</file>",
8175
"</licenseHeader>");
8276
}
77+
78+
private String getHookContent(String resourceFile) {
79+
String executorPath = "./" + newFile("mvnw").getName();
80+
if (newFile("mvnw.bat").exists()) {
81+
executorPath = newFile("mvnw.bat").getName();
82+
} else if (newFile("mvnw.cmd").exists()) {
83+
executorPath = newFile("mvnw.cmd").getName();
84+
}
85+
86+
return getTestResource(resourceFile)
87+
.replace("${executor}", "./" + executorPath)
88+
.replace("${checkCommand}", "spotless:check")
89+
.replace("${applyCommand}", "spotless:apply");
90+
}
8391
}

0 commit comments

Comments
 (0)