Search in sources :

Example 6 with LoadFromClasspath

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

the class ParameterConvertersBehaviour method shouldConvertToLinkedListOfCustomObjectsUsingCustomConverter.

@SuppressWarnings("unchecked")
@Test
public void shouldConvertToLinkedListOfCustomObjectsUsingCustomConverter() {
    ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath());
    parameterConverters.addConverters(new FooToBarParameterConverter());
    Type type = new TypeLiteral<LinkedList<Bar>>() {
    }.getType();
    assertThatCollectionIs((LinkedList<Bar>) parameterConverters.convert("foo", type), Bar.INSTANCE);
}
Also used : Type(java.lang.reflect.Type) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Test(org.junit.Test)

Example 7 with LoadFromClasspath

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

the class ParameterConvertersBehaviour method shouldConvertToListOfCustomObjectsUsingCustomConverter.

@Test
public void shouldConvertToListOfCustomObjectsUsingCustomConverter() {
    ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath());
    parameterConverters.addConverters(new FooToBarParameterConverter());
    Type type = new TypeLiteral<List<Bar>>() {
    }.getType();
    List<Bar> list = (List<Bar>) parameterConverters.convert("foo", type);
    assertThatCollectionIs(list, Bar.INSTANCE);
}
Also used : Type(java.lang.reflect.Type) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Arrays.asList(java.util.Arrays.asList) Test(org.junit.Test)

Example 8 with LoadFromClasspath

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

the class ParameterConvertersBehaviour method shouldConvertToNavigableSetOfCustomObjectsUsingCustomConverter.

@SuppressWarnings("unchecked")
@Test
public void shouldConvertToNavigableSetOfCustomObjectsUsingCustomConverter() {
    ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath());
    parameterConverters.addConverters(new FooToBarParameterConverter());
    Type type = new TypeLiteral<NavigableSet<Bar>>() {
    }.getType();
    Set<Bar> set = (Set<Bar>) parameterConverters.convert("foo", type);
    assertThatCollectionIs(set, Bar.INSTANCE);
}
Also used : Type(java.lang.reflect.Type) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) Test(org.junit.Test)

Example 9 with LoadFromClasspath

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

the class ParameterConvertersBehaviour method shouldConvertMultilineTable.

@Test
public void shouldConvertMultilineTable() {
    ParameterConverter<ExamplesTable> converter = new ExamplesTableConverter(new ExamplesTableFactory(new LoadFromClasspath(), new TableTransformers()));
    Type type = ExamplesTable.class;
    assertThatTypesAreAccepted(converter, type);
    String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
    ExamplesTable table = converter.convertValue(value, type);
    assertThat(table.getRowCount(), is(2));
    Map<String, String> row1 = table.getRow(0);
    assertThat(row1.get("col1"), is("row11"));
    assertThat(row1.get("col2"), is("row12"));
    Map<String, String> row2 = table.getRow(1);
    assertThat(row2.get("col1"), is("row21"));
    assertThat(row2.get("col2"), is("row22"));
}
Also used : Type(java.lang.reflect.Type) LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) ExamplesTable(org.jbehave.core.model.ExamplesTable) ExamplesTableFactory(org.jbehave.core.model.ExamplesTableFactory) ExamplesTableConverter(org.jbehave.core.steps.ParameterConverters.ExamplesTableConverter) TableTransformers(org.jbehave.core.model.TableTransformers) Test(org.junit.Test)

Example 10 with LoadFromClasspath

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

the class ParameterConvertersBehaviour method shouldConvertToCustomObjectUsingCustomConverter.

@Test
public void shouldConvertToCustomObjectUsingCustomConverter() {
    ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath());
    parameterConverters.addConverters(new FooToBarParameterConverter());
    assertThat((Bar) parameterConverters.convert("foo", Bar.class), is(Bar.INSTANCE));
}
Also used : LoadFromClasspath(org.jbehave.core.io.LoadFromClasspath) 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