Updated tests to work on jdk9+
This commit is contained in:
@@ -18,6 +18,18 @@ import static org.junit.Assert.fail;
|
|||||||
public class LoggerTest {
|
public class LoggerTest {
|
||||||
|
|
||||||
private static Path output = new File("output.log").toPath();
|
private static Path output = new File("output.log").toPath();
|
||||||
|
private static int majorJavaVersion = LoggerTest.getMajorJavaVersion();
|
||||||
|
private static String internalPackage = majorJavaVersion <= 8 ? "sun" : "java.base/jdk.internal";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLogException() {
|
||||||
|
Logger.log(new Exception("custom exception"));
|
||||||
|
verifyOutput(new String[]{
|
||||||
|
"[SEVERE][Test-LoggerTest] java.lang.Exception: custom exception",
|
||||||
|
"[SEVERE][Test-LoggerTest] \t fr.klemek.logger.LoggerTest.testLogException(LoggerTest.java:26)",
|
||||||
|
"[SEVERE][Test-LoggerTest] \t " + internalPackage + ".reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() throws IOException {
|
public void setUp() throws IOException {
|
||||||
@@ -61,23 +73,26 @@ public class LoggerTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testLogException() {
|
|
||||||
Logger.log(new Exception("custom exception"));
|
|
||||||
verifyOutput(new String[]{
|
|
||||||
"[SEVERE][Test-LoggerTest] java.lang.Exception: custom exception",
|
|
||||||
"[SEVERE][Test-LoggerTest] \t fr.klemek.logger.LoggerTest.testLogException(LoggerTest.java:66)",
|
|
||||||
"[SEVERE][Test-LoggerTest] \t sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testLogExceptionMessage() {
|
public void testLogExceptionMessage() {
|
||||||
Logger.log(new Exception("custom exception"), "custom message");
|
Logger.log(new Exception("custom exception"), "custom message");
|
||||||
verifyOutput(new String[]{
|
verifyOutput(new String[]{
|
||||||
"[SEVERE][Test-LoggerTest] custom message: java.lang.Exception: custom exception",
|
"[SEVERE][Test-LoggerTest] custom message: java.lang.Exception: custom exception",
|
||||||
"[SEVERE][Test-LoggerTest] \t fr.klemek.logger.LoggerTest.testLogExceptionMessage(LoggerTest.java:76)",
|
"[SEVERE][Test-LoggerTest] \t fr.klemek.logger.LoggerTest.testLogExceptionMessage(LoggerTest.java:78)",
|
||||||
"[SEVERE][Test-LoggerTest] \t sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
|
"[SEVERE][Test-LoggerTest] \t " + internalPackage + ".reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testLogExceptionCause() {
|
||||||
|
Logger.log(new Exception("custom exception", new Exception("custom cause")));
|
||||||
|
verifyOutput(new String[]{
|
||||||
|
"[SEVERE][Test-LoggerTest] java.lang.Exception: custom exception",
|
||||||
|
"[SEVERE][Test-LoggerTest] \t fr.klemek.logger.LoggerTest.testLogExceptionCause(LoggerTest.java:88)",
|
||||||
|
"[SEVERE][Test-LoggerTest] \t " + internalPackage + ".reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
|
||||||
|
"[SEVERE][Test-LoggerTest] Caused by: java.lang.Exception: custom cause",
|
||||||
|
"[SEVERE][Test-LoggerTest] \t fr.klemek.logger.LoggerTest.testLogExceptionCause(LoggerTest.java:88)",
|
||||||
|
"[SEVERE][Test-LoggerTest] \t " + internalPackage + ".reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,17 +112,9 @@ public class LoggerTest {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
private static int getMajorJavaVersion() {
|
||||||
public void testLogExceptionCause() {
|
String[] javaVersionElements = System.getProperty("java.runtime.version").split("\\.|_|-b");
|
||||||
Logger.log(new Exception("custom exception", new Exception("custom cause")));
|
return Integer.parseInt(javaVersionElements[1]);
|
||||||
verifyOutput(new String[]{
|
|
||||||
"[SEVERE][Test-LoggerTest] java.lang.Exception: custom exception",
|
|
||||||
"[SEVERE][Test-LoggerTest] \t fr.klemek.logger.LoggerTest.testLogExceptionCause(LoggerTest.java:102)",
|
|
||||||
"[SEVERE][Test-LoggerTest] \t sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)",
|
|
||||||
"[SEVERE][Test-LoggerTest] Caused by: java.lang.Exception: custom cause",
|
|
||||||
"[SEVERE][Test-LoggerTest] \t fr.klemek.logger.LoggerTest.testLogExceptionCause(LoggerTest.java:102)",
|
|
||||||
"[SEVERE][Test-LoggerTest] \t sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)"
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|||||||
Reference in New Issue
Block a user