use of org.jbehave.core.parsers.StepMatcher in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldFailIfMatchedParametersAreNotFound.
@Test(expected = ParameterNotFound.class)
public void shouldFailIfMatchedParametersAreNotFound() {
// Given
SomeSteps stepsInstance = new SomeSteps();
StepMatcher stepMatcher = mock(StepMatcher.class);
MostUsefulConfiguration configuration = new MostUsefulConfiguration();
InjectableStepsFactory stepsFactory = new InstanceStepsFactory(configuration, stepsInstance);
StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, configuration.parameterConverters(), new ParameterControls(), stepMatcher, new SilentStepMonitor());
// When
when(stepMatcher.parameterNames()).thenReturn(new String[] {});
stepCreator.matchedParameter("unknown");
// Then .. fail as expected
}
use of org.jbehave.core.parsers.StepMatcher 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));
}
use of org.jbehave.core.parsers.StepMatcher in project jbehave-core by jbehave.
the class StepCreatorBehaviour method shouldMatchParametersByNamedAnnotationsIfConfiguredToNotUseDelimiterNamedParamters.
@SuppressWarnings("unchecked")
@Test
public void shouldMatchParametersByNamedAnnotationsIfConfiguredToNotUseDelimiterNamedParamters() throws Exception {
// Given
SomeSteps stepsInstance = new SomeSteps();
parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
StepMatcher stepMatcher = mock(StepMatcher.class);
ParameterControls parameterControls = new ParameterControls().useDelimiterNamedParameters(false);
StepCreator stepCreator = stepCreatorUsing(stepsInstance, stepMatcher, parameterControls);
Map<String, String> params = new HashMap<>();
params.put("theme", "a theme");
params.put("variant", "a 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("a theme"));
assertThat(results.get("variant"), equalTo("a variant"));
}
Aggregations