Implement and use `Matcher#describeMismatch` throughout `axon-test` module
See original GitHub issueWhen using the Hamcrest Matcher based validation logic in ResultValidator
, like expectEventsMatching(Matcher<? extends List<? super EventMessage<?>>> matcher)
, it is hard to see the actual mismatch, if something goes wrong.
This is due to the following implementation:
It would be better to request the Matcher
to describe the mismatch using the describeMismatch(Object item, Description description)
method. This will result in a message that highlights the actual mismatch, not the whole matching logic.
I would suggest to change the implementation to:
public ResultValidator<T> expectEventsMatching(Matcher<? extends List<? super EventMessage<?>>> matcher) {
if (!matcher.matches(publishedEvents)) {
final StringDescription description = descriptionOf(matcher);
description.appendText("\nMismatch:\n");
matcher.describeMismatch(item, description);
reporter.reportWrongEvent(publishedEvents, descriptionOf(publishedEvents, matcher), actualException);
}
return this;
}
private StringDescription descriptionOf(Object item, Matcher<?> matcher) {
StringDescription description = new StringDescription();
matcher.describeMismatch(item, description);
return description;
}
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
org.hamcrest.Matcher.describeMismatch" when running test in ...
With this 4.13 junit library and hamcrest, it uses hamcrest.MatcherAssert when asserting and throws exception- enter image description here.
Read more >Using Hamcrest for testing - Tutorial - Vogella.com
To use Hamcrest matchers in your test you use the assertThat statement followed by one or several matchers. The usage of Hamcrest matchers...
Read more >Mixing JUnit, Hamcrest and Mockito: Explaining java.lang ...
Matcher present on the classpath to which org.junit.Assert.assertThat delegates. If you run this from Eclipse or IntelliJ, there's a high chance ...
Read more >org.hamcrest.Matcher.describeMismatch" when running test in ...
I'm using JUnit-dep 4.10 and Hamcrest 1.3.RC2. I've created a custom matcher that looks like the following: public static class MyMatcher extends ...
Read more >Blog - Think Code AB
The setup is version controlled and thus traceable. Here is an example where I use this this tool chain: Jenkins; Docker; Java; Maven;...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I’ve created a PR, @smcvb. In this, I implemented the usage of the
describeMismatch
mechanic of Hamcrest Matchers. All changes should be backwards compatible. In the Reporter class, I’ve added a new method, that will receive themismatch
in addition to the description. The old method is not used anywhere in the codebase, thus I’ve deprected that method. Thus, it should be possible to accept the PR and still maintain backwards compatibility.Thank you for your reply, @smcvb! I’m absolutely aware, that the number of changes to be made, are quite substantial, to have it consistent. Especially when trying to main a backwards compatible API within the custom matcher implementations. I’m currently giving that a shot, but do not count on me delivering a PR for the whole story anytime soon.
But what I can provide is a pull request that will only address the
expectEventsMatching
implementation by adding the output ofdescribeMismatch
as an additional information. This would not affect the backwards compatibility. For the Matcher-Implementations provided by axon, this still wouldn’t yield any substantial improvements. But when usingMatcher
s implemented by Hamcrest (or custom ones) that support thedescribeMismatch
, this would massively improve the output quality.