MessageEvent { public static MessageEvent fromMessage(final Map<String, Object> eventMap) { final List<?> arguments = (List<?>) eventMap.get("message"); return from((Map<?, ?>) arguments.get(0)); } MessageEvent(final String message, final LogLevel level, final String timestamp); static MessageEvent fromMessage(final Map<String, Object> eventMap); static MessageEvent fromLogMessage(final Map<String, Object> eventMap); String getMessage(); LogLevel getLevel(); String getTimestamp(); @Override boolean equals(final Object obj); @Override int hashCode();  }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_message1() { final Map<String, Object> eventMap = ImmutableMap.of(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_message2() { final Map<String, Object> eventMap = ImmutableMap.of("message", "m"); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_message3() { final Map<String, Object> eventMap = ImmutableMap.of("message", newArrayList()); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_message4() { final Map<String, Object> eventMap = ImmutableMap.of("message", newArrayList("m")); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_message5() { final ImmutableMap<String, ? extends Object> template = ImmutableMap.of("message", "msg", "level", "error", "timestamp", "ts"); final Set<Set<String>> allKeysCombinations = newHashSet( Sets.powerSet(newHashSet("message", "level", "timestamp"))); allKeysCombinations.remove(newHashSet("message", "level", "timestamp")); for (final Set<String> combination : allKeysCombinations) { final Map<String, Object> attributes = new HashMap<>(); for (final String key : combination) { attributes.put(key, template.get(key)); } final Map<String, Object> eventMap = ImmutableMap.of("message", newArrayList(attributes)); assertThatIllegalArgumentException().isThrownBy(() -> MessageEvent.fromMessage(eventMap)) .withMessage("Message event has to have the content, timestamp and level") .withNoCause(); } }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_message6() { final Map<String, Object> eventMap = ImmutableMap.of("message", newArrayList(ImmutableMap.of("message", "msg", "timestamp", "ts", "level", "unknown"))); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_message7() { final Map<String, Object> eventMap = ImmutableMap.of("log_message", newArrayList(ImmutableMap.of("message", "msg", "timestamp", "ts", "level", "error"))); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_logMessage1() { final Map<String, Object> eventMap = ImmutableMap.of(); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_logMessage2() { final Map<String, Object> eventMap = ImmutableMap.of("log_message", "m"); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_logMessage3() { final Map<String, Object> eventMap = ImmutableMap.of("log_message", newArrayList()); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_logMessage4() { final Map<String, Object> eventMap = ImmutableMap.of("log_message", newArrayList("m")); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }
@Test public void exceptionIsThrownForWronglyConstructedJsonDictionary_logMessage6() { final Map<String, Object> eventMap = ImmutableMap.of("log_message", newArrayList(ImmutableMap.of("message", "msg", "timestamp", "ts", "level", "unknown"))); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> MessageEvent.fromMessage(eventMap)); }