Refactor support for testing executable files

Previously, hasExecutableFile only checked if the
file exists and not if it was executable. This commit
ensures that the file exists and is executable using
ExecTask as Unzip and Untar do not preserve file permissions.

See gh-937
This commit is contained in:
HaiTao Zhang
2019-06-28 10:45:51 -07:00
committed by Madhura Bhave
parent f16971fcd3
commit 292e47e98b
2 changed files with 72 additions and 14 deletions

View File

@@ -16,6 +16,7 @@
package io.spring.initializr.generator.spring.test;
import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Properties;
@@ -192,8 +193,14 @@ public class ProjectAssert {
}
public ProjectAssert hasExecutableFile(String... localPaths) {
if (runningOnWindows()) {
for (String localPath : localPaths) {
assertFile(localPath, true);
}
return this;
}
for (String localPath : localPaths) {
assertFile(localPath, true);
assertExecutable(localPath, true);
}
return this;
}
@@ -210,6 +217,19 @@ public class ProjectAssert {
return this;
}
public ProjectAssert assertExecutable(String localPath, boolean exist) {
Path candidate = this.projectStructure.resolve(localPath);
assertThat(Files.exists(candidate)).describedAs("Invalid presence (%s) exist for %s", exist, localPath)
.isEqualTo(exist);
assertThat(Files.isExecutable(candidate)).describedAs("File (%s) is not an executable", localPath)
.isEqualTo(exist);
return this;
}
private boolean runningOnWindows() {
return File.separatorChar == '\\';
}
private Properties properties(String localPath) {
Path file = this.projectStructure.resolve(localPath);
try {