2011-12-29 17:17:01 +00:00
|
|
|
import java.io.File;
|
|
|
|
|
|
|
|
public class Files {
|
|
|
|
private static void expect(boolean v) {
|
|
|
|
if (! v) throw new RuntimeException();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void isAbsoluteTest(boolean absolutePath) {
|
|
|
|
File file = new File("test.txt");
|
|
|
|
if (absolutePath) {
|
|
|
|
file = file.getAbsoluteFile();
|
|
|
|
}
|
|
|
|
|
|
|
|
boolean isAbsolute = file.isAbsolute();
|
|
|
|
|
|
|
|
if (absolutePath) {
|
|
|
|
expect(isAbsolute);
|
|
|
|
} else {
|
|
|
|
expect(!isAbsolute);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2012-02-09 21:04:42 +00:00
|
|
|
|
|
|
|
private static void setExecutableTestWithPermissions(boolean executable) {
|
|
|
|
File file = File.createTempFile("avian.", null);
|
|
|
|
file.setExecutable(executable);
|
|
|
|
if (executable) {
|
|
|
|
expect(file.canExecute());
|
|
|
|
} else {
|
|
|
|
// Commented out because this will fail on Windows - both on Avian and on OpenJDK
|
|
|
|
// The implementation for Windows considers canExecute() to be the same as canRead()
|
|
|
|
// expect(!file.canExecute());
|
|
|
|
}
|
|
|
|
}
|
2011-12-29 17:17:01 +00:00
|
|
|
|
|
|
|
public static void main(String[] args) {
|
|
|
|
isAbsoluteTest(true);
|
|
|
|
isAbsoluteTest(false);
|
2012-02-09 21:04:42 +00:00
|
|
|
setExecutableTestWithPermissions(true);
|
|
|
|
setExecutableTestWithPermissions(false);
|
2011-12-29 17:17:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|