Search in sources :

Example 11 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldHandleFailureInParametrisedStep.

@Test
public void shouldHandleFailureInParametrisedStep() {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    InjectableStepsFactory stepsFactory = new InstanceStepsFactory(new MostUsefulConfiguration(), stepsInstance);
    StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, null, new ParameterControls(), null, new SilentStepMonitor());
    // When
    Method method = null;
    StepResult stepResult = stepCreator.createParametrisedStep(method, "When I fail", "I fail", null).perform(null);
    // Then
    assertThat(stepResult, instanceOf(Failed.class));
}
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) Test(org.junit.Test)

Example 12 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldHandleTargetInvocationFailureInParametrisedStep.

@Test
public void shouldHandleTargetInvocationFailureInParametrisedStep() throws IntrospectionException {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    InjectableStepsFactory stepsFactory = new InstanceStepsFactory(new MostUsefulConfiguration(), stepsInstance);
    StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, null, new ParameterControls(), null, new SilentStepMonitor());
    // When
    Method method = SomeSteps.methodFor("aFailingMethod");
    StepResult stepResult = stepCreator.createParametrisedStep(method, "When I fail", "I fail", null).perform(null);
    // Then
    assertThat(stepResult, instanceOf(Failed.class));
}
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) Test(org.junit.Test)

Example 13 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldHandleObjectAlreadyStoredFailure.

private void shouldHandleObjectAlreadyStoredFailure(Method duplicateStoreMethod) throws IntrospectionException {
    // Given
    setupContext();
    SomeSteps stepsInstance = new SomeSteps();
    InjectableStepsFactory stepsFactory = new InstanceStepsFactory(new MostUsefulConfiguration(), stepsInstance);
    StepCreator stepCreator = new StepCreator(stepsInstance.getClass(), stepsFactory, stepsContext, null, new ParameterControls(), mock(StepMatcher.class), new SilentStepMonitor());
    // When
    Method method = SomeSteps.methodFor("aMethodStoringAString");
    StepResult stepResult = stepCreator.createParametrisedStep(method, "When I store in context", "I store in context", new HashMap<String, String>()).perform(null);
    StepResult stepResultSecondWrite = stepCreator.createParametrisedStep(duplicateStoreMethod, "And I store in context", "I store in context", new HashMap<String, String>()).perform(null);
    // Then
    assertThat(stepResult, instanceOf(Successful.class));
    assertThat(stepResultSecondWrite, instanceOf(Failed.class));
    Throwable cause = stepResultSecondWrite.getFailure().getCause();
    assertThat(cause, instanceOf(ObjectAlreadyStoredException.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) Successful(org.jbehave.core.steps.AbstractStepResult.Successful) ObjectAlreadyStoredException(org.jbehave.core.steps.context.StepsContext.ObjectAlreadyStoredException)

Example 14 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class StepsBehaviour method shouldAllowLocalizationOfSteps.

@Test
public void shouldAllowLocalizationOfSteps() {
    Configuration configuration = new MostUsefulConfiguration();
    configuration.useKeywords(new LocalizedKeywords(new Locale("it")));
    LocalizedSteps steps = new LocalizedSteps(configuration);
    List<StepCandidate> candidates = steps.listCandidates();
    assertThat(candidates.size(), equalTo(3));
    findCandidate(candidates, "GIVEN un dato che").createMatchedStep("Dato che un dato che", tableRow).perform(null);
    findCandidate(candidates, "WHEN un quando").createMatchedStep("Quando un quando", tableRow).perform(null);
    findCandidate(candidates, "THEN un allora").createMatchedStep("Allora un allora", tableRow).perform(null);
    assertThat(steps.givens, equalTo(1));
    assertThat(steps.whens, equalTo(1));
    assertThat(steps.thens, equalTo(1));
}
Also used : Locale(java.util.Locale) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Configuration(org.jbehave.core.configuration.Configuration) MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) LocalizedKeywords(org.jbehave.core.i18n.LocalizedKeywords) Test(org.junit.Test)

Example 15 with MostUsefulConfiguration

use of org.jbehave.core.configuration.MostUsefulConfiguration in project jbehave-core by jbehave.

the class InstanceStepsFactoryBehaviour method shouldDetermineIfStepsInstanceHasAnnotatedMethods.

@Test
public void shouldDetermineIfStepsInstanceHasAnnotatedMethods() {
    InstanceStepsFactory factory = new InstanceStepsFactory(new MostUsefulConfiguration());
    assertThat(factory.hasAnnotatedMethods(MySteps.class), is(true));
    assertThat(factory.hasAnnotatedMethods(NoAnnotatedMethods.class), is(false));
}
Also used : MostUsefulConfiguration(org.jbehave.core.configuration.MostUsefulConfiguration) Test(org.junit.Test)

Aggregations

MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)66 Test (org.junit.Test)52 Configuration (org.jbehave.core.configuration.Configuration)14 CandidateSteps (org.jbehave.core.steps.CandidateSteps)14 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)11 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)8 TableTransformers (org.jbehave.core.model.TableTransformers)8 Method (java.lang.reflect.Method)7 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)7 ParameterConverters (org.jbehave.core.steps.ParameterConverters)7 SimpleDateFormat (java.text.SimpleDateFormat)5 HashMap (java.util.HashMap)5 InjectableEmbedder (org.jbehave.core.InjectableEmbedder)5 UsingEmbedder (org.jbehave.core.annotations.UsingEmbedder)5 BeforeOrAfterFailed (org.jbehave.core.failures.BeforeOrAfterFailed)5 Failed (org.jbehave.core.steps.AbstractStepResult.Failed)5 ApplicationContext (org.springframework.context.ApplicationContext)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 OutputStream (java.io.OutputStream)4 PrintStream (java.io.PrintStream)4