1717
1818import static org .assertj .core .api .Assertions .assertThat ;
1919
20+ import java .io .File ;
2021import java .io .IOException ;
22+ import java .util .Locale ;
2123
2224import 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,26 @@ private void writePomWithJavaLicenseHeaderStep() throws IOException {
8076 " <file>${basedir}/license.txt</file>" ,
8177 "</licenseHeader>" );
8278 }
79+
80+ private String getHookContent (String resourceFile ) {
81+ final var executorFile = executorWrapperFile ();
82+ final var executorPath = executorFile .exists () ? executorFile .getName () : "mvn" ;
83+ return getTestResource (resourceFile )
84+ .replace ("${executor}" , "./" + executorPath )
85+ .replace ("${checkCommand}" , "spotless:check" )
86+ .replace ("${applyCommand}" , "spotless:apply" );
87+ }
88+
89+ private File executorWrapperFile () {
90+ if (System .getProperty ("os.name" ).toLowerCase (Locale .ROOT ).startsWith ("win" )) {
91+ final var bat = newFile ("mvnw.bat" );
92+ if (bat .exists ()) {
93+ return bat ;
94+ }
95+
96+ return newFile ("mvnw.cmd" );
97+ }
98+
99+ return newFile ("mvnw" );
100+ }
83101}
0 commit comments