Skip to content

Commit

Permalink
feat(#5): refactor tests a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed Nov 22, 2023
1 parent 329edf7 commit 45c1d80
Showing 1 changed file with 20 additions and 25 deletions.
45 changes: 20 additions & 25 deletions src/test/java/com/yegor256/JhomeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,49 +58,44 @@ void findsCorrectHome() {
}

@Test
void findsJava() {
final Path java = new Jhome().java();
MatcherAssert.assertThat(
"java binary filename should be 'java'",
java,
Matchers.hasToString(Matchers.endsWith("java"))
);
void findsJavaOnAnyOs() {
MatcherAssert.assertThat(
"java binary file doesn't exist. If you run this test, then you should have a JDK installed",
java.toFile(),
new Jhome().java().toFile(),
FileMatchers.anExistingFile()
);
}

/**
* Here we restrict the test to run only on Java 9+.
* Since before Java 9, the "javac" binary was shipped separately in JDK.
* JRE pack did not contain it.
*/
@Test
@DisabledOnOs(OS.WINDOWS)
void findsRealFile() {
@EnabledForJreRange(min = JRE.JAVA_9)
void findsJavacOnAnyOs() {
MatcherAssert.assertThat(
new Jhome().path("bin/java").toFile().exists(),
Matchers.is(true)
"javac binary file doesn't exist. If you run this test, then you should have a JDK installed",
new Jhome().javac().toFile(),
FileMatchers.anExistingFile()
);
}

@Test
@EnabledForJreRange(min = JRE.JAVA_9)
void findsJavac() {
final Path javac = new Jhome().javac();
MatcherAssert.assertThat(
"java compiler filename should be 'javac'",
javac,
Matchers.hasToString(Matchers.endsWith("javac"))
);
@DisabledOnOs(OS.WINDOWS)
void findsRealFileOnUnixOs() {
MatcherAssert.assertThat(
"javac binary file doesn't exist. If you run this test, then you should have a JDK installed",
javac.toFile(),
FileMatchers.anExistingFile()
"java binary file doesn't exist. If you run this test, then you should have a JDK or JRE installed",
new Jhome().path("bin/java").toFile().exists(),
Matchers.is(true)
);
}

@EnabledOnOs(OS.WINDOWS)
void findsRealExeFile() {
void findsRealExeFileOnWindowsOs() {
MatcherAssert.assertThat(
new Jhome().path("bin\\java.exe").toFile().exists(),
"java.exe binary file doesn't exist. If you run this test, then you should have a JDK or JRE installed",
new Jhome().java().toFile().exists(),
Matchers.is(true)
);
}
Expand Down

0 comments on commit 45c1d80

Please sign in to comment.