Search in sources :

Example 26 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.

the class ExamplesTableFactoryBehaviour method shouldCreateExamplesTableFromTableInputWithInlinedSeparators.

@Test
public void shouldCreateExamplesTableFromTableInputWithInlinedSeparators() {
    // Given
    ExamplesTableFactory factory = new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers());
    // When
    ExamplesTable examplesTable = factory.createExamplesTable(TABLE_WITH_INLINED_SEPARATTORS);
    // Then
    assertThat(examplesTable.asString(), equalTo(FILTERED_TABLE_WITH_INLINED_SEPARATTORS));
}
Also used : LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Test(org.junit.Test)

Example 27 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldMatchParametersByDelimitedNameWithDistinctNamedAnnotations.

@SuppressWarnings("unchecked")
@Test
public void shouldMatchParametersByDelimitedNameWithDistinctNamedAnnotations() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
    StepMatcher stepMatcher = mock(StepMatcher.class);
    ParameterControls parameterControls = new ParameterControls().useDelimiterNamedParameters(true);
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, stepMatcher, parameterControls);
    Map<String, String> params = new HashMap<>();
    params.put("t", "distinct theme");
    params.put("v", "distinct 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("distinct theme"));
    assertThat(results.get("variant"), equalTo("distinct 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 28 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.

the class StepCreatorBehaviour method shouldMatchParametersByDelimitedNameWithNoNamedAnnotations.

@Test
public void shouldMatchParametersByDelimitedNameWithNoNamedAnnotations() throws Exception {
    // Given
    SomeSteps stepsInstance = new SomeSteps();
    parameterConverters = new ParameterConverters(new LoadFromClasspath(), new TableTransformers());
    StepMatcher stepMatcher = mock(StepMatcher.class);
    ParameterControls parameterControls = new ParameterControls().useDelimiterNamedParameters(true);
    StepCreator stepCreator = stepCreatorUsing(stepsInstance, stepMatcher, parameterControls);
    Map<String, String> params = Collections.singletonMap("param", "value");
    when(stepMatcher.parameterNames()).thenReturn(params.keySet().toArray(new String[params.size()]));
    when(stepMatcher.parameter(1)).thenReturn("<param>");
    // When
    Step step = stepCreator.createParametrisedStep(SomeSteps.methodFor("aMethodWithoutNamedAnnotation"), "When a parameter <param> is set", "a parameter <param> is set", params);
    step.perform(null);
    // Then
    assertThat((String) stepsInstance.args, equalTo("value"));
}
Also used : RegexStepMatcher(org.jbehave.core.parsers.RegexStepMatcher) StepMatcher(org.jbehave.core.parsers.StepMatcher) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Matchers.anyString(org.mockito.Matchers.anyString) ParametrisedStep(org.jbehave.core.steps.StepCreator.ParametrisedStep) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 29 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath 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 30 with LoadFromClasspath

use of org.jbehave.core.io.LoadFromClasspath 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)

Aggregations

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