Search in sources :

Example 1 with Failed

use of org.jbehave.core.steps.AbstractStepResult.Failed in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldHandleTargetInvocationFailureInBeforeOrAfterStep.

@Test
public void shouldHandleTargetInvocationFailureInBeforeOrAfterStep() throws IntrospectionException {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    MostUsefulConfiguration configuration = new MostUsefulConfiguration();
    InjectableStepsFactory stepsFactory = new InstanceStepsFactory(configuration, stepsInstance);
    StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, configuration.parameterConverters(), new ParameterControls(), null, new SilentStepMonitor());
    // When
    Method method = SomeSteps.methodFor("aFailingBeforeScenarioMethod");
    StepResult stepResult = stepCreator.createBeforeOrAfterStep(method, Meta.EMPTY).perform(null);
    // Then
    assertThat(stepResult, instanceOf(Failed.class));
    assertThat(stepResult.getFailure(), instanceOf(UUIDExceptionWrapper.class));
    Throwable cause = stepResult.getFailure().getCause();
    assertThat(cause, instanceOf(BeforeOrAfterFailed.class));
    assertThat(cause.getMessage(), org.hamcrest.Matchers.equalTo("Method aFailingBeforeScenarioMethod (annotated with @BeforeScenario in class org.jbehave.core.steps.SomeSteps) failed: java.lang.RuntimeException"));
}
Also used : MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) BeforeOrAfterFailed(org.jbehave.core.failures.BeforeOrAfterFailed) Failed(org.jbehave.core.steps.AbstractStepResult.Failed) Method(java.lang.reflect.Method) BeforeOrAfterFailed(org.jbehave.core.failures.BeforeOrAfterFailed) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Aggregations

Method (java.lang.reflect.Method)1 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)1 BeforeOrAfterFailed (org.jbehave.core.failures.BeforeOrAfterFailed)1 UUIDExceptionWrapper (org.jbehave.core.failures.UUIDExceptionWrapper)1 Failed (org.jbehave.core.steps.AbstractStepResult.Failed)1 Test (org.junit.Test)1