MCPcopy Create free account
hub / github.com/apache/tomcat / testFormat

Method testFormat

test/org/apache/juli/TestJsonFormatter.java:33–56  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

31public class TestJsonFormatter {
32
33 @Test
34 public void testFormat() throws Exception {
35
36 Formatter formatter = new JsonFormatter();
37 LogRecord logRecord = new LogRecord(Level.FINE, "Test log message");
38 logRecord.setSourceClassName("org.apache.juli.TestJsonFormatter");
39 logRecord.setSourceMethodName("testFormat");
40 try {
41 throw new IllegalStateException("Bad state");
42 } catch (IllegalStateException e) {
43 logRecord.setThrown(e);
44 }
45
46 String result = formatter.format(logRecord);
47
48 // Verify JSON content
49 Assert.assertTrue(result.startsWith("{"));
50 JSONParser parser = new JSONParser(new StringReader(result));
51 LinkedHashMap<String,Object> json = parser.object();
52 Assert.assertEquals(json.get("method"), "testFormat");
53 @SuppressWarnings("unchecked")
54 ArrayList<Object> trace = (ArrayList<Object>) json.get("throwable");
55 Assert.assertEquals(trace.get(0), "java.lang.IllegalStateException: Bad state");
56 }
57
58 @Test
59 public void testEscaping() {

Callers

nothing calls this directly

Calls 4

formatMethod · 0.95
objectMethod · 0.95
getMethod · 0.65
startsWithMethod · 0.45

Tested by

no test coverage detected