Search in sources :

Example 1 with RegexStepMatcher

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"));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) HashMap(java.util.HashMap) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Method(java.lang.reflect.Method) Matchers.anyString(org.mockito.Matchers.anyString) Successful(org.jbehave.core.steps.AbstractStepResult.Successful) RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher)

Example 2 with RegexStepMatcher

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));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) HashMap(java.util.HashMap) RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) Matchers.anyString(org.mockito.Matchers.anyString) Successful(org.jbehave.core.steps.AbstractStepResult.Successful)

Example 3 with RegexStepMatcher

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));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) HashMap(java.util.HashMap) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) BeforeOrAfterFailed(org.jbehave.core.failures.BeforeOrAfterFailed) Failed(org.jbehave.core.steps.AbstractStepResult.Failed) Method(java.lang.reflect.Method) RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) ObjectNotStoredException(org.jbehave.core.steps.context.StepsContext.ObjectNotStoredException) Test(org.junit.Test)

Aggregations

HashMap (java.util.HashMap)3 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)3 StepMatcher (org.jbehave.core.parsers.StepMatcher)3 Method (java.lang.reflect.Method)2 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)2 Successful (org.jbehave.core.steps.AbstractStepResult.Successful)2 Matchers.anyString (org.mockito.Matchers.anyString)2 BeforeOrAfterFailed (org.jbehave.core.failures.BeforeOrAfterFailed)1 Failed (org.jbehave.core.steps.AbstractStepResult.Failed)1 ObjectNotStoredException (org.jbehave.core.steps.context.StepsContext.ObjectNotStoredException)1 Test (org.junit.Test)1