From 45c1d800d7bd68932427108f2d6eba10a55094f2 Mon Sep 17 00:00:00 2001 From: volodya-lombrozo Date: Wed, 22 Nov 2023 11:28:21 +0300 Subject: [PATCH] feat(#5): refactor tests a bit --- src/test/java/com/yegor256/JhomeTest.java | 45 ++++++++++------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/test/java/com/yegor256/JhomeTest.java b/src/test/java/com/yegor256/JhomeTest.java index a1dac64..c86e9ad 100644 --- a/src/test/java/com/yegor256/JhomeTest.java +++ b/src/test/java/com/yegor256/JhomeTest.java @@ -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) ); }