Skip to content

Commit

Permalink
Loosend ResultValidator generic to <? extends Iterable> instead of List
Browse files Browse the repository at this point in the history
Some Hamcrest matchers only guarantee Iterable and were unusable with the
Axon ResultValidator API.

Issue #AXON-214 Fixed
  • Loading branch information
abuijze committed Feb 21, 2014
1 parent 9d424c8 commit 8bcf159
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

import org.hamcrest.Matcher;

import java.util.List;

/**
* Interface describing the operations available on the "validate result" (a.k.a. "then") stage of the test execution.
* The underlying fixture expects a test to have been executed succesfully using a {@link
Expand Down Expand Up @@ -60,7 +58,7 @@ public interface ResultValidator {
* @param matcher The matcher to match with the actually published events
* @return the current ResultValidator, for fluent interfacing
*/
ResultValidator expectEventsMatching(Matcher<List<?>> matcher);
ResultValidator expectEventsMatching(Matcher<? extends Iterable<?>> matcher);

/**
* Expect the given set of events to have been published on the events bus. If you expect the same events to be
Expand All @@ -87,7 +85,7 @@ public interface ResultValidator {
* @param matcher The matcher which validates the actual list of published events.
* @return the current ResultValidator, for fluent interfacing
*/
ResultValidator expectPublishedEventsMatching(Matcher<List<?>> matcher);
ResultValidator expectPublishedEventsMatching(Matcher<? extends Iterable<?>> matcher);

/**
* Expect the given set of events to have been stored in the event store. If you expect the same events to be
Expand All @@ -113,7 +111,7 @@ public interface ResultValidator {
* @param matcher The matcher which validates the actual list of stored events.
* @return the current ResultValidator, for fluent interfacing
*/
ResultValidator expectStoredEventsMatching(Matcher<List<?>> matcher);
ResultValidator expectStoredEventsMatching(Matcher<? extends Iterable<?>> matcher);

/**
* Expect the command handler to return the given <code>expectedReturnValue</code> after execution. The actual and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import static org.hamcrest.CoreMatchers.*;

Expand Down Expand Up @@ -66,7 +65,7 @@ public ResultValidator expectEvents(Object... expectedEvents) {
}

@Override
public ResultValidator expectEventsMatching(Matcher<List<?>> matcher) {
public ResultValidator expectEventsMatching(Matcher<? extends Iterable<?>> matcher) {
if (publishedEvents.size() != storedEvents.size()) {
reporter.reportDifferenceInStoredVsPublished(storedEvents, publishedEvents, actualException);
}
Expand All @@ -91,7 +90,7 @@ public ResultValidator expectPublishedEvents(Object... expectedEvents) {
}

@Override
public ResultValidator expectPublishedEventsMatching(Matcher<List<?>> matcher) {
public ResultValidator expectPublishedEventsMatching(Matcher<? extends Iterable<?>> matcher) {
if (!matcher.matches(publishedEvents)) {
reporter.reportWrongEvent(publishedEvents, descriptionOf(matcher), actualException);
}
Expand Down Expand Up @@ -120,7 +119,7 @@ public ResultValidator expectStoredEvents(Object... expectedEvents) {
}

@Override
public ResultValidator expectStoredEventsMatching(Matcher<List<?>> matcher) {
public ResultValidator expectStoredEventsMatching(Matcher<? extends Iterable<?>> matcher) {
if (!matcher.matches(storedEvents)) {
reporter.reportWrongEvent(storedEvents, descriptionOf(matcher), actualException);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ private Matchers() {
* @param matcher The mather to match against the Message payloads
* @return a Matcher that matches against the Message payloads
*/
public static Matcher<List<?>> payloadsMatching(final Matcher<List<?>> matcher) {
public static Matcher<List<?>> payloadsMatching(final Matcher<? extends Iterable<?>> matcher) {
return new PayloadsMatcher(matcher);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
* @since 2.0
*/
public class PayloadsMatcher extends BaseMatcher<List<?>> {
private final Matcher<List<?>> matcher;
private final Matcher<? extends Iterable<?>> matcher;

/**
* Constructs an instance that uses the given <code>matcher</code> to match the payloads.
*
* @param matcher The matcher to match the payloads with
*/
public PayloadsMatcher(Matcher<List<?>> matcher) {
public PayloadsMatcher(Matcher<? extends Iterable<?>> matcher) {
this.matcher = matcher;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public EventValidator(EventBus eventBus) {
*
* @param matcher The matcher that will validate the actual events
*/
public void assertPublishedEventsMatching(Matcher<List<?>> matcher) {
public void assertPublishedEventsMatching(Matcher<? extends Iterable<?>> matcher) {
if (!matcher.matches(publishedEvents)) {
StringDescription expectedDescription = new StringDescription();
StringDescription actualDescription = new StringDescription();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
import org.joda.time.DateTime;
import org.joda.time.Duration;

import java.util.List;

/**
* Interface towards an object that contains the results of a Fixture execution. It provides methods to assert that
* certain actions have taken place.
Expand Down Expand Up @@ -151,7 +149,7 @@ public interface FixtureExecutionResult {
* @param matcher The matcher that describes the expected list of commands
* @return the FixtureExecutionResult for method chaining
*/
FixtureExecutionResult expectDispatchedCommandsMatching(Matcher<List<?>> matcher);
FixtureExecutionResult expectDispatchedCommandsMatching(Matcher<? extends Iterable<?>> matcher);

/**
* Asserts that the sagas did not dispatch any commands. Only commands as a result of the event in the "when" stage
Expand All @@ -176,7 +174,7 @@ public interface FixtureExecutionResult {
* @param matcher The matcher that defines the expected list of published events.
* @return the FixtureExecutionResult for method chaining
*/
FixtureExecutionResult expectPublishedEventsMatching(Matcher<List<?>> matcher);
FixtureExecutionResult expectPublishedEventsMatching(Matcher<? extends Iterable<?>> matcher);

/**
* Assert that the saga published events on the EventBus in the exact sequence of the given <code>expected</code>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public FixtureExecutionResult expectDispatchedCommandsEqualTo(Object... expected
}

@Override
public FixtureExecutionResult expectDispatchedCommandsMatching(Matcher<List<?>> matcher) {
public FixtureExecutionResult expectDispatchedCommandsMatching(Matcher<? extends Iterable<?>> matcher) {
commandValidator.assertDispatchedMatching(matcher);
return this;
}
Expand All @@ -148,7 +148,7 @@ public FixtureExecutionResult expectNoScheduledEvents() {
}

@Override
public FixtureExecutionResult expectPublishedEventsMatching(Matcher<List<?>> matcher) {
public FixtureExecutionResult expectPublishedEventsMatching(Matcher<? extends Iterable<?>> matcher) {
eventValidator.assertPublishedEventsMatching(matcher);
return this;
}
Expand Down

0 comments on commit 8bcf159

Please sign in to comment.