Sorry, the pull request that caused this had a follow-up that I just merged in today.
On 3 March 2016 at 10:21, Ralph Goers <[email protected]> wrote: > This test is still failing. > > Ralph > > > On Mar 2, 2016, at 10:34 PM, Ralph Goers <[email protected]> > wrote: > > > > It appears that the newly added testEventMapMessage is not working. > > > > Ralph > > > >> On Mar 2, 2016, at 8:08 PM, [email protected] wrote: > >> > >> Repository: logging-log4j2 > >> Updated Branches: > >> refs/heads/master 60d1ccd93 -> a57fc35b9 > >> > >> > >> LOG4J2-1227 > >> Test if the event is null before using it, to avoid > NullPointerException. > >> Add some unit tests. > >> Submitted by: Olivier Lemasle <[email protected]> > >> > >> > >> Project: http://git-wip-us.apache.org/repos/asf/logging-log4j2/repo > >> Commit: > http://git-wip-us.apache.org/repos/asf/logging-log4j2/commit/33ee4bfd > >> Tree: > http://git-wip-us.apache.org/repos/asf/logging-log4j2/tree/33ee4bfd > >> Diff: > http://git-wip-us.apache.org/repos/asf/logging-log4j2/diff/33ee4bfd > >> > >> Branch: refs/heads/master > >> Commit: 33ee4bfd0aa1f58a705771222132a42d1dfb328c > >> Parents: 13b0dd8 > >> Author: Olivier Lemasle <[email protected]> > >> Authored: Mon Dec 21 16:53:36 2015 +0100 > >> Committer: Olivier Lemasle <[email protected]> > >> Committed: Mon Dec 21 16:53:36 2015 +0100 > >> > >> ---------------------------------------------------------------------- > >> .../logging/log4j/core/lookup/MapLookup.java | 2 +- > >> .../log4j/core/lookup/MapLookupTest.java | 25 > ++++++++++++++++++++ > >> 2 files changed, 26 insertions(+), 1 deletion(-) > >> ---------------------------------------------------------------------- > >> > >> > >> > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java > >> ---------------------------------------------------------------------- > >> diff --git > a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java > b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java > >> index c369a0b..c00645e 100644 > >> --- > a/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java > >> +++ > b/log4j-core/src/main/java/org/apache/logging/log4j/core/lookup/MapLookup.java > >> @@ -118,7 +118,7 @@ public class MapLookup implements StrLookup { > >> > >> @Override > >> public String lookup(final LogEvent event, final String key) { > >> - final boolean isMapMessage = event.getMessage() instanceof > MapMessage; > >> + final boolean isMapMessage = event != null && > event.getMessage() instanceof MapMessage; > >> if (map == null && !isMapMessage) { > >> return null; > >> } > >> > >> > http://git-wip-us.apache.org/repos/asf/logging-log4j2/blob/33ee4bfd/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java > >> ---------------------------------------------------------------------- > >> diff --git > a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java > b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java > >> index be550e3..5f26d15 100644 > >> --- > a/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java > >> +++ > b/log4j-core/src/test/java/org/apache/logging/log4j/core/lookup/MapLookupTest.java > >> @@ -20,6 +20,9 @@ import static org.junit.Assert.assertEquals; > >> > >> import java.util.HashMap; > >> > >> +import org.apache.logging.log4j.core.LogEvent; > >> +import org.apache.logging.log4j.core.impl.Log4jLogEvent; > >> +import org.apache.logging.log4j.message.MapMessage; > >> import org.junit.Test; > >> > >> /** > >> @@ -64,4 +67,26 @@ public class MapLookupTest { > >> assertEquals(null, lookup.lookup("foo.txt")); > >> } > >> > >> + @Test > >> + public void testEventMapMessage() { > >> + final HashMap<String, String> map = new HashMap<>(); > >> + map.put("A", "B"); > >> + final HashMap<String, String> eventMap = new HashMap<>(); > >> + eventMap.put("A1", "B1"); > >> + final MapMessage message = new MapMessage(eventMap); > >> + final LogEvent event = Log4jLogEvent.newBuilder() > >> + .setMessage(message) > >> + .build(); > >> + final MapLookup lookup = new MapLookup(map); > >> + assertEquals("B", lookup.lookup(event, "A")); > >> + assertEquals("B1", lookup.lookup(event, "A")); > >> + } > >> + > >> + @Test > >> + public void testNullEvent() { > >> + final HashMap<String, String> map = new HashMap<>(); > >> + map.put("A", "B"); > >> + final MapLookup lookup = new MapLookup(map); > >> + assertEquals("B", lookup.lookup(null, "A")); > >> + } > >> } > >> > >> > > > > > > > > --------------------------------------------------------------------- > > To unsubscribe, e-mail: [email protected] > > For additional commands, e-mail: [email protected] > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > > -- Matt Sicker <[email protected]>
