use of org.jbehave.core.parsers.RegexStepMatcher in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldStoreAndReadObjects.
private void shouldStoreAndReadObjects(Method methodStoring, boolean resetContext) throws IntrospectionException {
// Given
if (resetContext) {
setupContext();
}
SomeSteps stepsInstance = new SomeSteps();
InjectableStepsFactory stepsFactory = new InstanceStepsFactory(new MostUsefulConfiguration(), stepsInstance);
StepMatcher stepMatcher = new RegexStepMatcher(StepType.WHEN, "I read from context", Pattern.compile("I read from context"), new String[] {});
StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, null, new ParameterControls(), stepMatcher, new SilentStepMonitor());
// When
Method methodRead = SomeSteps.methodFor("aMethodReadingFromContext");
StepResult stepResult = stepCreator.createParametrisedStep(methodStoring, "When I store in context", "I store in context", new HashMap<String, String>()).perform(null);
StepResult stepResultRead = stepCreator.createParametrisedStep(methodRead, "And I read from context", "I read from context", new HashMap<String, String>()).perform(null);
// Then
assertThat(stepResult, instanceOf(Successful.class));
assertThat(stepResultRead, instanceOf(Successful.class));
assertThat(stepsInstance.args, instanceOf(String.class));
assertThat((String) stepsInstance.args, is("someValue"));
}
use of org.jbehave.core.parsers.RegexStepMatcher in project jbehave-core by jbehave.
the class StepCreatorBehaviour method assertThatParametrisedStepHasMarkedParsedParametersValues.
private void assertThatParametrisedStepHasMarkedParsedParametersValues(String firstParameterValue, String secondParameterValue) throws IntrospectionException {
// Given
SomeSteps stepsInstance = new SomeSteps();
StepMatcher stepMatcher = new RegexStepMatcher(StepType.WHEN, "I use parameters $theme and $variant", Pattern.compile("When I use parameters (.*) and (.*)"), new String[] { "theme", "variant" });
StepCreator stepCreator = stepCreatorUsing(stepsInstance, stepMatcher, new ParameterControls());
Map<String, String> parameters = new HashMap<>();
// When
StepResult stepResult = stepCreator.createParametrisedStep(SomeSteps.methodFor("aMethodWithANamedParameter"), "When I use parameters " + firstParameterValue + " and " + secondParameterValue, "When I use parameters " + firstParameterValue + " and " + secondParameterValue, parameters).perform(null);
// Then
assertThat(stepResult, instanceOf(Successful.class));
String expected = "When I use parameters " + PARAMETER_VALUE_START + firstParameterValue + PARAMETER_VALUE_END + " and " + PARAMETER_VALUE_START + secondParameterValue + PARAMETER_VALUE_END;
assertThat(stepResult.parametrisedStep(), equalTo(expected));
}
use of org.jbehave.core.parsers.RegexStepMatcher in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldHandleObjectNotStoredFailure.
@Test
public void shouldHandleObjectNotStoredFailure() throws IntrospectionException {
// Given
setupContext();
SomeSteps stepsInstance = new SomeSteps();
InjectableStepsFactory stepsFactory = new InstanceStepsFactory(new MostUsefulConfiguration(), stepsInstance);
StepMatcher stepMatcher = new RegexStepMatcher(StepType.WHEN, "I read from context", Pattern.compile("I read from context"), new String[] {});
StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, null, new ParameterControls(), stepMatcher, new SilentStepMonitor());
// When
Method method = SomeSteps.methodFor("aMethodReadingFromContext");
StepResult stepResult = stepCreator.createParametrisedStep(method, "When I read from context", "I read from context", new HashMap<String, String>()).perform(null);
// Then
assertThat(stepResult, instanceOf(Failed.class));
Throwable cause = stepResult.getFailure().getCause();
assertThat(cause, instanceOf(ObjectNotStoredException.class));
}
Aggregations