use of org.jbehave.core.parsers.StepMatcher 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.StepMatcher in project jbehave-core by jbehave.
the class StepCreatorBehaviour method assertThatParametrisedStepHasMarkedNamedParameterValues.
private void assertThatParametrisedStepHasMarkedNamedParameterValues(String firstParameterValue, String secondParameterValue) throws IntrospectionException {
// Given
SomeSteps stepsInstance = new SomeSteps();
StepMatcher stepMatcher = mock(StepMatcher.class);
StepCreator stepCreator = stepCreatorUsing(stepsInstance, stepMatcher, new ParameterControls().useDelimiterNamedParameters(false));
Map<String, String> parameters = new HashMap<>();
parameters.put("theme", firstParameterValue);
parameters.put("variant", secondParameterValue);
// When
when(stepMatcher.parameterNames()).thenReturn(parameters.keySet().toArray(new String[parameters.size()]));
when(stepMatcher.parameter(1)).thenReturn(parameters.get(firstParameterValue));
when(stepMatcher.parameter(2)).thenReturn(parameters.get(secondParameterValue));
StepResult stepResult = stepCreator.createParametrisedStep(SomeSteps.methodFor("aMethodWithANamedParameter"), "When I use parameters <theme> and <variant>", "I use parameters <theme> and <variant>", 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.StepMatcher in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldMatchParametersByDelimitedNameWithDistinctNamedAnnotations.
@SuppressWarnings("unchecked")
@Test
public void shouldMatchParametersByDelimitedNameWithDistinctNamedAnnotations() throws Exception {
// Given
SomeSteps stepsInstance = new SomeSteps();
parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
StepMatcher stepMatcher = mock(StepMatcher.class);
ParameterControls parameterControls = new ParameterControls().useDelimiterNamedParameters(true);
StepCreator stepCreator = stepCreatorUsing(stepsInstance, stepMatcher, parameterControls);
Map<String, String> params = new HashMap<>();
params.put("t", "distinct theme");
params.put("v", "distinct variant");
when(stepMatcher.parameterNames()).thenReturn(params.keySet().toArray(new String[params.size()]));
when(stepMatcher.parameter(1)).thenReturn("<t>");
when(stepMatcher.parameter(2)).thenReturn("<v>");
// When
Step step = stepCreator.createParametrisedStep(SomeSteps.methodFor("aMethodWithANamedParameter"), "When I use parameters <t> and <v>", "I use parameters <t> and <v>", params);
step.perform(null);
// Then
Map<String, String> results = (Map<String, String>) stepsInstance.args;
assertThat(results.get("theme"), equalTo("distinct theme"));
assertThat(results.get("variant"), equalTo("distinct variant"));
}
use of org.jbehave.core.parsers.StepMatcher in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldMatchParametersByDelimitedNameWithNoNamedAnnotations.
@Test
public void shouldMatchParametersByDelimitedNameWithNoNamedAnnotations() throws Exception {
// Given
SomeSteps stepsInstance = new SomeSteps();
parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
StepMatcher stepMatcher = mock(StepMatcher.class);
ParameterControls parameterControls = new ParameterControls().useDelimiterNamedParameters(true);
StepCreator stepCreator = stepCreatorUsing(stepsInstance, stepMatcher, parameterControls);
Map<String, String> params = Collections.singletonMap("param", "value");
when(stepMatcher.parameterNames()).thenReturn(params.keySet().toArray(new String[params.size()]));
when(stepMatcher.parameter(1)).thenReturn("<param>");
// When
Step step = stepCreator.createParametrisedStep(SomeSteps.methodFor("aMethodWithoutNamedAnnotation"), "When a parameter <param> is set", "a parameter <param> is set", params);
step.perform(null);
// Then
assertThat((String) stepsInstance.args, equalTo("value"));
}
use of org.jbehave.core.parsers.StepMatcher 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));
}
Aggregations