Search in sources :

Example 16 with TableTransformers

use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldInjectExceptionThatHappenedIfTargetMethodExpectsIt.

@Test
public void shouldInjectExceptionThatHappenedIfTargetMethodExpectsIt() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, mock(StepMatcher.class), new ParameterControls());
    // When
    Step stepWithMeta = stepCreator.createBeforeOrAfterStep(SomeSteps.methodFor("aMethodThatExpectsUUIDExceptionWrapper"), mock(Meta.class));
    UUIDExceptionWrapper occurredFailure = new UUIDExceptionWrapper();
    StepResult stepResult = stepWithMeta.perform(occurredFailure);
    // Then
    assertThat(stepResult, instanceOf(Silent.class));
    assertThat((UUIDExceptionWrapper) stepsInstance.args, is(occurredFailure));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) Meta(org.jbehave.core.model.Meta) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Silent(org.jbehave.core.steps.AbstractStepResult.Silent) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) TableTransformers(org.jbehave.core.model.TableTransformers) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 17 with TableTransformers

use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldInjectNoFailureIfNoExceptionHappenedAndTargetMethodExpectsIt.

@Test
public void shouldInjectNoFailureIfNoExceptionHappenedAndTargetMethodExpectsIt() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, mock(StepMatcher.class), new ParameterControls());
    // When
    Step stepWithMeta = stepCreator.createBeforeOrAfterStep(SomeSteps.methodFor("aMethodThatExpectsUUIDExceptionWrapper"), mock(Meta.class));
    UUIDExceptionWrapper occurredFailure = new UUIDExceptionWrapper();
    StepResult stepResult = stepWithMeta.perform(occurredFailure);
    // Then
    assertThat(stepResult, instanceOf(Silent.class));
    assertThat((UUIDExceptionWrapper) stepsInstance.args, is(occurredFailure));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) Meta(org.jbehave.core.model.Meta) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Silent(org.jbehave.core.steps.AbstractStepResult.Silent) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) TableTransformers(org.jbehave.core.model.TableTransformers) UUIDExceptionWrapper(org.jbehave.core.failures.UUIDExceptionWrapper) Test(org.junit.Test)

Example 18 with TableTransformers

use of org.jbehave.core.model.TableTransformers 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"));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) HashMap(java.util.HashMap) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Matchers.anyString(org.mockito.Matchers.anyString) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) HashMap(java.util.HashMap) Map(java.util.Map) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 19 with TableTransformers

use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.

the class ParameterConvertersBehaviour method shouldConvertMultilineTableToParameters.

@Test
public void shouldConvertMultilineTableToParameters() {
    ParameterConverter converter = new ExamplesTableParametersConverter(new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()));
    Type type = new TypeLiteral<List<MyParameters>>() {
    }.getType();
    assertThatTypesAreAccepted(converter, type);
    String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
    @SuppressWarnings("unchecked") List<MyParameters> parameters = (List<MyParameters>) converter.convertValue(value, type);
    assertThat(parameters.size(), is(2));
    MyParameters row1 = parameters.get(0);
    assertThat(row1.col1, is("row11"));
    assertThat(row1.col2, is("row12"));
    MyParameters row2 = parameters.get(1);
    assertThat(row2.col1, is("row21"));
    assertThat(row2.col2, is("row22"));
}
Also used : Type(java.lang.reflect.Type) AbstractParameterConverter(org.jbehave.core.steps.ParameterConverters.AbstractParameterConverter) ParameterConverter(org.jbehave.core.steps.ParameterConverters.ParameterConverter) ExamplesTableParametersConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableParametersConverter) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) MyParameters(org.jbehave.core.steps.SomeSteps.MyParameters) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) Arrays.asList(java.util.Arrays.asList) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 20 with TableTransformers

use of org.jbehave.core.model.TableTransformers in project jbehave-core by jbehave.

the class ParameterConvertersBehaviour method shouldNotModifyListOfConvertersFromOriginalParameterConvertersWhenCreatingNewInstance.

@Test
public void shouldNotModifyListOfConvertersFromOriginalParameterConvertersWhenCreatingNewInstance() {
    expectedException.expect(ParameterConvertionFailed.class);
    ParameterConverters original = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
    original.newInstanceAdding(new FooToBarParameterConverter());
    original.convert("foo", Bar.class);
}
Also used : LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Aggregations

TableTransformers (org.jbehave.core.model.TableTransformers)25 LoadFromClasspath (org.jbehave.core.io.LoadFromClasspath)22 Test (org.junit.Test)16 MostUsefulConfiguration (org.jbehave.core.configuration.MostUsefulConfiguration)8 StoryReporterBuilder (org.jbehave.core.reporters.StoryReporterBuilder)8 ParameterConverters (org.jbehave.core.steps.ParameterConverters)8 LocalizedKeywords (org.jbehave.core.i18n.LocalizedKeywords)7 ExamplesTableFactory (org.jbehave.core.model.ExamplesTableFactory)7 SimpleDateFormat (java.text.SimpleDateFormat)5 Properties (java.util.Properties)5 RegexStepMatcher (org.jbehave.core.parsers.RegexStepMatcher)5 RegexStoryParser (org.jbehave.core.parsers.RegexStoryParser)5 StepMatcher (org.jbehave.core.parsers.StepMatcher)5 ParametrisedStep (org.jbehave.core.steps.StepCreator.ParametrisedStep)5 Type (java.lang.reflect.Type)4 DateConverter (org.jbehave.core.steps.ParameterConverters.DateConverter)4 ParameterConverter (org.jbehave.core.steps.ParameterConverters.ParameterConverter)4 HashMap (java.util.HashMap)3 StoryControls (org.jbehave.core.embedder.StoryControls)3 RegexPrefixCapturingPatternParser (org.jbehave.core.parsers.RegexPrefixCapturingPatternParser)3