Polish hamcrest use it test integration
- Rename expectVariableMatcher to expectVariableWith. - Change other variable expects internally to use hamcrest. - Fixes #483
This commit is contained in:
@@ -35,6 +35,7 @@ import java.util.concurrent.TimeUnit;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.collection.IsMapContaining;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.statemachine.StateMachine;
|
||||
import org.springframework.statemachine.state.State;
|
||||
@@ -262,16 +263,17 @@ public class StateMachineTestPlan<S, E> {
|
||||
for (StateMachine<S, E> stateMachine : stateMachines.values()) {
|
||||
Map<Object, Object> variables = stateMachine.getExtendedState().getVariables();
|
||||
for (Object key : step.expectVariableKeys) {
|
||||
assertThat("Key " + key + " doesn't exist in extended state variables",
|
||||
variables.containsKey(key), is(true));
|
||||
org.hamcrest.MatcherAssert.assertThat(
|
||||
"Key [" + key + "] doesn't exist in extended state variables", variables,
|
||||
IsMapContaining.hasKey(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!step.expectVariableKeysMatchers.isEmpty()) {
|
||||
if (!step.expectVariableMatchers.isEmpty()) {
|
||||
for (StateMachine<S, E> stateMachine : stateMachines.values()) {
|
||||
Map<Object, Object> variables = stateMachine.getExtendedState().getVariables();
|
||||
for (Matcher<Map<? extends Object, ?>> matcher : step.expectVariableKeysMatchers) {
|
||||
for (Matcher<Map<? extends Object, ?>> matcher : step.expectVariableMatchers) {
|
||||
org.hamcrest.MatcherAssert.assertThat(variables, matcher);
|
||||
}
|
||||
}
|
||||
@@ -281,10 +283,10 @@ public class StateMachineTestPlan<S, E> {
|
||||
for (StateMachine<S, E> stateMachine : stateMachines.values()) {
|
||||
Map<Object, Object> variables = stateMachine.getExtendedState().getVariables();
|
||||
for (Entry<Object, Object> entry : step.expectVariables.entrySet()) {
|
||||
assertThat("Key " + entry.getKey() + " doesn't exist in extended state variables",
|
||||
variables.containsKey(entry.getKey()), is(true));
|
||||
assertThat("Variable " + entry.getKey() + " doesn't match in extended state variables",
|
||||
variables.get(entry.getKey()), is(entry.getValue()));
|
||||
org.hamcrest.MatcherAssert.assertThat(
|
||||
"Entry with key=[" + entry.getKey() + "] value=[" + entry.getValue()
|
||||
+ "] doesn't exist in extended state variables",
|
||||
variables, IsMapContaining.hasEntry(entry.getKey(), entry.getValue()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,7 +130,7 @@ public class StateMachineTestPlanBuilder<S, E> {
|
||||
Integer expectStateMachineStopped;
|
||||
Integer expectExtendedStateChanged;
|
||||
final Collection<Object> expectVariableKeys = new ArrayList<Object>();
|
||||
final Collection<Matcher<Map<? extends Object, ?>>> expectVariableKeysMatchers = new ArrayList<>();
|
||||
final Collection<Matcher<Map<? extends Object, ?>>> expectVariableMatchers = new ArrayList<>();
|
||||
final Map<Object, Object> expectVariables = new HashMap<Object, Object>();
|
||||
|
||||
/**
|
||||
@@ -278,8 +278,8 @@ public class StateMachineTestPlanBuilder<S, E> {
|
||||
* @param matcher the matcher
|
||||
* @return the state machine test plan step builder
|
||||
*/
|
||||
public StateMachineTestPlanStepBuilder expectVariableMatcher(Matcher<Map<? extends Object, ?>> matcher) {
|
||||
this.expectVariableKeysMatchers.add(matcher);
|
||||
public StateMachineTestPlanStepBuilder expectVariableWith(Matcher<Map<? extends Object, ?>> matcher) {
|
||||
this.expectVariableMatchers.add(matcher);
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -472,7 +472,7 @@ public class StateMachineTestPlanBuilder<S, E> {
|
||||
sendEventParallel, expectStates, expectStateChanged, expectStateEntered, expectStateExited,
|
||||
expectEventNotAccepted, expectTransition, expectTransitionStarted, expectTransitionEnded,
|
||||
expectStateMachineStarted, expectStateMachineStopped, expectVariableKeys,
|
||||
expectVariableKeysMatchers, expectVariables, expectExtendedStateChanged,
|
||||
expectVariableMatchers, expectVariables, expectExtendedStateChanged,
|
||||
expectStatesEntrered, expectStatesExited));
|
||||
return StateMachineTestPlanBuilder.this;
|
||||
}
|
||||
@@ -499,7 +499,7 @@ public class StateMachineTestPlanBuilder<S, E> {
|
||||
Integer expectStateMachineStopped;
|
||||
Integer expectExtendedStateChanged;
|
||||
final Collection<Object> expectVariableKeys;
|
||||
final Collection<Matcher<Map<? extends Object, ?>>> expectVariableKeysMatchers;
|
||||
final Collection<Matcher<Map<? extends Object, ?>>> expectVariableMatchers;
|
||||
final Map<Object, Object> expectVariables;
|
||||
|
||||
public StateMachineTestPlanStep(List<E> sendEvent, List<Message<E>> sendMessage, Object sendEventMachineId,
|
||||
@@ -507,7 +507,7 @@ public class StateMachineTestPlanBuilder<S, E> {
|
||||
Integer expectStateChanged, Integer expectStateEntered, Integer expectStateExited,
|
||||
Integer expectEventNotAccepted, Integer expectTransition, Integer expectTransitionStarted,
|
||||
Integer expectTransitionEnded, Integer expectStateMachineStarted, Integer expectStateMachineStopped,
|
||||
Collection<Object> expectVariableKeys, Collection<Matcher<Map<? extends Object, ?>>> expectVariableKeysMatchers,
|
||||
Collection<Object> expectVariableKeys, Collection<Matcher<Map<? extends Object, ?>>> expectVariableMatchers,
|
||||
Map<Object, Object> expectVariables,
|
||||
Integer expectExtendedStateChanged, Collection<S> expectStatesEntrered,
|
||||
Collection<S> expectStatesExited) {
|
||||
@@ -527,7 +527,7 @@ public class StateMachineTestPlanBuilder<S, E> {
|
||||
this.expectStateMachineStarted = expectStateMachineStarted;
|
||||
this.expectStateMachineStopped = expectStateMachineStopped;
|
||||
this.expectVariableKeys = expectVariableKeys;
|
||||
this.expectVariableKeysMatchers = expectVariableKeysMatchers;
|
||||
this.expectVariableMatchers = expectVariableMatchers;
|
||||
this.expectVariables = expectVariables;
|
||||
this.expectExtendedStateChanged = expectExtendedStateChanged;
|
||||
this.expectStatesEntrered = expectStatesEntrered;
|
||||
|
||||
@@ -125,10 +125,10 @@ public class StateMachineTestingTests extends AbstractStateMachineTests {
|
||||
.expectState("S1")
|
||||
.expectVariable("V1Key")
|
||||
.expectVariable("V1Key", "V1Value")
|
||||
.expectVariableMatcher(IsMapContaining.hasKey("V1Key"))
|
||||
.expectVariableMatcher(IsMapContaining.hasValue("V1Value"))
|
||||
.expectVariableMatcher(IsMapContaining.hasEntry("V1Key", "V1Value"))
|
||||
.expectVariableMatcher(not(IsMapContaining.hasKey("V2Key")))
|
||||
.expectVariableWith(IsMapContaining.hasKey("V1Key"))
|
||||
.expectVariableWith(IsMapContaining.hasValue("V1Value"))
|
||||
.expectVariableWith(IsMapContaining.hasEntry("V1Key", "V1Value"))
|
||||
.expectVariableWith(not(IsMapContaining.hasKey("V2Key")))
|
||||
.and()
|
||||
.step()
|
||||
.sendEvent("E2")
|
||||
@@ -138,12 +138,12 @@ public class StateMachineTestingTests extends AbstractStateMachineTests {
|
||||
.expectVariable("V1Key", "V1Value")
|
||||
.expectVariable("V2Key")
|
||||
.expectVariable("V2Key", "V2Value")
|
||||
.expectVariableMatcher(IsMapContaining.hasKey("V1Key"))
|
||||
.expectVariableMatcher(IsMapContaining.hasValue("V1Value"))
|
||||
.expectVariableMatcher(IsMapContaining.hasEntry("V1Key", "V1Value"))
|
||||
.expectVariableMatcher(IsMapContaining.hasKey("V2Key"))
|
||||
.expectVariableMatcher(IsMapContaining.hasValue("V2Value"))
|
||||
.expectVariableMatcher(IsMapContaining.hasEntry("V2Key", "V2Value"))
|
||||
.expectVariableWith(IsMapContaining.hasKey("V1Key"))
|
||||
.expectVariableWith(IsMapContaining.hasValue("V1Value"))
|
||||
.expectVariableWith(IsMapContaining.hasEntry("V1Key", "V1Value"))
|
||||
.expectVariableWith(IsMapContaining.hasKey("V2Key"))
|
||||
.expectVariableWith(IsMapContaining.hasValue("V2Value"))
|
||||
.expectVariableWith(IsMapContaining.hasEntry("V2Key", "V2Value"))
|
||||
.and()
|
||||
.build();
|
||||
|
||||
|
||||
@@ -48,10 +48,10 @@ public class DocsTestSampleTests {
|
||||
.expectStates("S1")
|
||||
.expectVariable("key1")
|
||||
.expectVariable("key1", "value1")
|
||||
.expectVariableMatcher(hasKey("key1"))
|
||||
.expectVariableMatcher(hasValue("value1"))
|
||||
.expectVariableMatcher(hasEntry("key1", "value1"))
|
||||
.expectVariableMatcher(not(hasKey("key2")))
|
||||
.expectVariableWith(hasKey("key1"))
|
||||
.expectVariableWith(hasValue("value1"))
|
||||
.expectVariableWith(hasEntry("key1", "value1"))
|
||||
.expectVariableWith(not(hasKey("key2")))
|
||||
.and()
|
||||
.build();
|
||||
plan.test();
|
||||
|
||||
Reference in New Issue
Block a user