diff --git a/README.md b/README.md index ef287be..62b3ca1 100644 --- a/README.md +++ b/README.md @@ -49,6 +49,7 @@ logCapture.assertLoggedInOrder( * [Cucumber example](#cucumber-example) * [Cucumber feature file](#cucumber-feature-file) * [Changes](#changes) + * [3.6.1](#361) * [3.6.0](#360) * [3.5.0](#350) * [3.4.1](#341) @@ -72,7 +73,7 @@ Add log-capture as a test dependency to your project. If you use Maven, add this de.dm.infrastructure log-capture - 3.6.0 + 3.6.1 test ``` @@ -308,6 +309,10 @@ And with MDC logging context ## Changes +### 3.6.1 + +* Fixed a misleading and wrong assertion message. The assertion itself was correct, but the message always said all matchers did not match when only a subset did not match. + ### 3.6.0 * Removed ExpectedKeyValue again due to an [API change in Logstash without a workaround](https://github.com/logfellow/logstash-logback-encoder/issues/788) diff --git a/src/main/java/de/dm/infrastructure/logcapture/LogAsserter.java b/src/main/java/de/dm/infrastructure/logcapture/LogAsserter.java index e9f79a0..5a4cf47 100644 --- a/src/main/java/de/dm/infrastructure/logcapture/LogAsserter.java +++ b/src/main/java/de/dm/infrastructure/logcapture/LogAsserter.java @@ -202,11 +202,13 @@ private static void throwAssertionForPartiallyMatchingLoggedEvent(Optional + logCapture.assertLogged( + error("some error", + mdc("key", "a value"), + exception().expectedMessageRegex("an exception that was not logged").build()) + )); + + assertThat(assertionError).hasMessage("Expected log message has occurred, but never with the expected Exception: Level: ERROR, Regex: \"some error\"" + + lineSeparator() + " expected exception: message (regex): \"an exception that was not logged\"" + + lineSeparator() + " actual exception: message: \"an exception that was logged\", message: java.lang.RuntimeException" + + lineSeparator()); + } } diff --git a/src/test/java/de/dm/infrastructure/logcapture/FluentApiTest.java b/src/test/java/de/dm/infrastructure/logcapture/FluentApiTest.java index d52874c..dc0a107 100644 --- a/src/test/java/de/dm/infrastructure/logcapture/FluentApiTest.java +++ b/src/test/java/de/dm/infrastructure/logcapture/FluentApiTest.java @@ -164,12 +164,6 @@ void mdcForAllAndSingleMdcFails() { assertThat(assertionError).hasMessage( "Expected log message has occurred, but never with the expected MDC value: Level: WARN, Regex: \"bye world\"" + - lineSeparator() + " captured message: \"bye world\"" + - lineSeparator() + " expected MDC key: key" + - lineSeparator() + " expected MDC value: \".*value.*\"" + - lineSeparator() + " captured MDC values:" + - lineSeparator() + " key: \"value\"" + - lineSeparator() + "Expected log message has occurred, but never with the expected MDC value: Level: WARN, Regex: \"bye world\"" + lineSeparator() + " captured message: \"bye world\"" + lineSeparator() + " expected MDC key: another_key" + lineSeparator() + " expected MDC value: \".*another_value.*\"" +