"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "log4j-core/src/test/java/org/apache/logging/log4j/core/impl/MutableLogEventTest.java" between
apache-log4j-2.11.1-src.tar.gz and apache-log4j-2.11.2-src.tar.gz

About: Apache Log4j 2 is a logging library for Java. Source distribution (Java).

MutableLogEventTest.java  (apache-log4j-2.11.1-src):MutableLogEventTest.java  (apache-log4j-2.11.2-src)
skipping to change at line 66 skipping to change at line 66
result.putValue("a", "1"); result.putValue("a", "1");
result.putValue("b", "2"); result.putValue("b", "2");
return result; return result;
} }
@BeforeClass @BeforeClass
public static void setupClass() { public static void setupClass() {
try { try {
Class.forName("java.io.ObjectInputFilter"); Class.forName("java.io.ObjectInputFilter");
useObjectInputStream = true; useObjectInputStream = true;
} catch (ClassNotFoundException ex) { } catch (final ClassNotFoundException ex) {
// Ignore the exception // Ignore the exception
} }
} }
@Test @Test
public void testToImmutable() { public void testToImmutable() {
final LogEvent logEvent = new MutableLogEvent(); final LogEvent logEvent = new MutableLogEvent();
Assert.assertNotSame(logEvent, logEvent.toImmutable()); Assert.assertNotSame(logEvent, logEvent.toImmutable());
} }
skipping to change at line 119 skipping to change at line 119
assertEquals("tid", source.getThreadId(), mutable.getThreadId()); assertEquals("tid", source.getThreadId(), mutable.getThreadId());
assertEquals("tname", source.getThreadName(), mutable.getThreadName()); assertEquals("tname", source.getThreadName(), mutable.getThreadName());
assertEquals("tpriority", source.getThreadPriority(), mutable.getThreadP riority()); assertEquals("tpriority", source.getThreadPriority(), mutable.getThreadP riority());
assertEquals("throwns", source.getThrown(), mutable.getThrown()); assertEquals("throwns", source.getThrown(), mutable.getThrown());
assertEquals("proxy", source.getThrownProxy(), mutable.getThrownProxy()) ; assertEquals("proxy", source.getThrownProxy(), mutable.getThrownProxy()) ;
assertEquals("millis", source.getTimeMillis(), mutable.getTimeMillis()); assertEquals("millis", source.getTimeMillis(), mutable.getTimeMillis());
} }
@Test @Test
public void testInitFromReusableCopiesFormatString() { public void testInitFromReusableCopiesFormatString() {
Message message = ReusableMessageFactory.INSTANCE.newMessage("msg in a { }", "bottle"); final Message message = ReusableMessageFactory.INSTANCE.newMessage("msg in a {}", "bottle");
final Log4jLogEvent source = Log4jLogEvent.newBuilder() // final Log4jLogEvent source = Log4jLogEvent.newBuilder() //
.setContextData(CONTEXT_DATA) // .setContextData(CONTEXT_DATA) //
.setContextStack(STACK) // .setContextStack(STACK) //
.setEndOfBatch(true) // .setEndOfBatch(true) //
.setIncludeLocation(true) // .setIncludeLocation(true) //
.setLevel(Level.FATAL) // .setLevel(Level.FATAL) //
.setLoggerFqcn("a.b.c.d.e") // .setLoggerFqcn("a.b.c.d.e") //
.setLoggerName("my name is Logger") // .setLoggerName("my name is Logger") //
.setMarker(MarkerManager.getMarker("on your marks")) // .setMarker(MarkerManager.getMarker("on your marks")) //
.setMessage(message) // .setMessage(message) //
skipping to change at line 141 skipping to change at line 141
.setSource(new StackTraceElement("myclass", "mymethod", "myfile" , 123)) // .setSource(new StackTraceElement("myclass", "mymethod", "myfile" , 123)) //
.setThreadId(100).setThreadName("threadname").setThreadPriority( 10) // .setThreadId(100).setThreadName("threadname").setThreadPriority( 10) //
.setThrown(new RuntimeException("run")) // .setThrown(new RuntimeException("run")) //
.setTimeMillis(987654321) .setTimeMillis(987654321)
.build(); .build();
final MutableLogEvent mutable = new MutableLogEvent(); final MutableLogEvent mutable = new MutableLogEvent();
mutable.initFrom(source); mutable.initFrom(source);
assertEquals("format", "msg in a {}", mutable.getFormat()); assertEquals("format", "msg in a {}", mutable.getFormat());
assertEquals("formatted", "msg in a bottle", mutable.getFormattedMessage ()); assertEquals("formatted", "msg in a bottle", mutable.getFormattedMessage ());
assertEquals("parameters", new String[] {"bottle"}, mutable.getParameter s()); assertEquals("parameters", new String[] {"bottle"}, mutable.getParameter s());
Message memento = mutable.memento(); final Message memento = mutable.memento();
assertEquals("format", "msg in a {}", memento.getFormat()); assertEquals("format", "msg in a {}", memento.getFormat());
assertEquals("formatted", "msg in a bottle", memento.getFormattedMessage ()); assertEquals("formatted", "msg in a bottle", memento.getFormattedMessage ());
assertEquals("parameters", new String[] {"bottle"}, memento.getParameter s()); assertEquals("parameters", new String[] {"bottle"}, memento.getParameter s());
Message eventMementoMessage = mutable.createMemento().getMessage(); final Message eventMementoMessage = mutable.createMemento().getMessage() ;
assertEquals("format", "msg in a {}", eventMementoMessage.getFormat()); assertEquals("format", "msg in a {}", eventMementoMessage.getFormat());
assertEquals("formatted", "msg in a bottle", eventMementoMessage.getForm attedMessage()); assertEquals("formatted", "msg in a bottle", eventMementoMessage.getForm attedMessage());
assertEquals("parameters", new String[] {"bottle"}, eventMementoMessage. getParameters()); assertEquals("parameters", new String[] {"bottle"}, eventMementoMessage. getParameters());
Message log4JLogEventMessage = new Log4jLogEvent.Builder(mutable).build( ).getMessage(); final Message log4JLogEventMessage = new Log4jLogEvent.Builder(mutable). build().getMessage();
assertEquals("format", "msg in a {}", log4JLogEventMessage.getFormat()); assertEquals("format", "msg in a {}", log4JLogEventMessage.getFormat());
assertEquals("formatted", "msg in a bottle", log4JLogEventMessage.getFor mattedMessage()); assertEquals("formatted", "msg in a bottle", log4JLogEventMessage.getFor mattedMessage());
assertEquals("parameters", new String[] {"bottle"}, log4JLogEventMessage .getParameters()); assertEquals("parameters", new String[] {"bottle"}, log4JLogEventMessage .getParameters());
} }
@Test @Test
public void testInitFromReusableObjectCopiesParameter() {
final Object param = new Object();
final Message message = ReusableMessageFactory.INSTANCE.newMessage(param
);
final Log4jLogEvent source = Log4jLogEvent.newBuilder()
.setContextData(CONTEXT_DATA)
.setContextStack(STACK)
.setEndOfBatch(true)
.setIncludeLocation(true)
.setLevel(Level.FATAL)
.setLoggerFqcn("a.b.c.d.e")
.setLoggerName("my name is Logger")
.setMarker(MarkerManager.getMarker("on your marks"))
.setMessage(message)
.setNanoTime(1234567)
.setSource(new StackTraceElement("myclass", "mymethod", "myfile"
, 123))
.setThreadId(100).setThreadName("threadname")
.setThreadPriority(10)
.setThrown(new RuntimeException("run"))
.setTimeMillis(987654321)
.build();
final MutableLogEvent mutable = new MutableLogEvent();
mutable.initFrom(source);
assertNull("format", mutable.getFormat());
assertEquals("formatted", param.toString(), mutable.getFormattedMessage(
));
assertEquals("parameters", new Object[] {param}, mutable.getParameters()
);
final Message memento = mutable.memento();
assertNull("format", memento.getFormat());
assertEquals("formatted", param.toString(), memento.getFormattedMessage(
));
assertEquals("parameters", new Object[] {param}, memento.getParameters()
);
}
@Test
public void testClear() { public void testClear() {
final MutableLogEvent mutable = new MutableLogEvent(); final MutableLogEvent mutable = new MutableLogEvent();
assertEquals("context data", 0, mutable.getContextData().size()); assertEquals("context data", 0, mutable.getContextData().size());
assertNull("context stack", mutable.getContextStack()); assertNull("context stack", mutable.getContextStack());
assertFalse("end of batch", mutable.isEndOfBatch()); assertFalse("end of batch", mutable.isEndOfBatch());
assertFalse("incl loc", mutable.isIncludeLocation()); assertFalse("incl loc", mutable.isIncludeLocation());
assertSame("level", Level.OFF, mutable.getLevel()); assertSame("level", Level.OFF, mutable.getLevel());
assertNull("fqcn", mutable.getLoggerFqcn()); assertNull("fqcn", mutable.getLoggerFqcn());
assertNull("logger", mutable.getLoggerName()); assertNull("logger", mutable.getLoggerName());
assertNull("marker", mutable.getMarker()); assertNull("marker", mutable.getMarker());
 End of changes. 6 change blocks. 
5 lines changed or deleted 43 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)