/** * Tests formatting of a multi-line message. */ @Test @DependsOnMethod("testlevelWidth") public void testMultilines() { final LogRecord record = new LogRecord(Level.INFO, "First line\n Indented line\nLast line\n"); final String formatted = formatter.format(record); assertMultilinesEquals(localize(Level.INFO, "INFO\t First line\n" + "\t Indented line\n" + "\t Last line\n"), formatted); }
/** * Tests formatting a log record which contains an exception. */ @Test @DependsOnMethod("testlevelWidth") public void testException() { final LogRecord record = new LogRecord(Level.WARNING, "An exception occured."); final Exception exception = new Exception(); exception.setStackTrace(new StackTraceElement[] { new StackTraceElement("org.apache.sis.NonExistent", "foo", "NonExistent.java", 10), new StackTraceElement("org.junit.WhoKnows", "main", "WhoKnows.java", 20) }); record.setThrown(exception); String formatted = formatter.format(record); assertMultilinesEquals(localize(Level.WARNING, "WARNING\t An exception occured.\n" + "\t Caused by: java.lang.Exception\n" + "\t at org.apache.sis.NonExistent.foo(NonExistent.java:10)\n" + "\t at org.junit.WhoKnows.main(WhoKnows.java:20)\n"), formatted); /* * Remove the message and try again. */ record.setMessage(null); formatted = formatter.format(record); assertMultilinesEquals(localize(Level.WARNING, "WARNING\t java.lang.Exception\n" + "\t at org.apache.sis.NonExistent.foo(NonExistent.java:10)\n" + "\t at org.junit.WhoKnows.main(WhoKnows.java:20)\n"), formatted); } }