use of org.jbehave.core.io.LoadFromClasspath 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"));
}
use of org.jbehave.core.io.LoadFromClasspath 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"));
}
use of org.jbehave.core.io.LoadFromClasspath 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);
}
use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldDefineDefaultConverters.
@SuppressWarnings("unchecked")
@Test
public void shouldDefineDefaultConverters() {
LoadFromClasspath resourceLoader = new LoadFromClasspath();
TableTransformers tableTransformers = new TableTransformers();
ParameterControls parameterControls = new ParameterControls();
ParameterConverters converters = new ParameterConverters(resourceLoader, parameterControls, tableTransformers, true);
ParameterConverter<?>[] defaultConverters = converters.defaultConverters(resourceLoader, parameterControls, tableTransformers, Locale.ENGLISH, ",");
assertThatDefaultConvertersInclude(defaultConverters, BooleanConverter.class, NumberConverter.class, StringListConverter.class, DateConverter.class, EnumConverter.class, ExamplesTableConverter.class, ExamplesTableParametersConverter.class);
}
use of org.jbehave.core.io.LoadFromClasspath in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldNotConvertToAnyCollectionOfCustomObjectsUsingCustomConverter.
@Test
public void shouldNotConvertToAnyCollectionOfCustomObjectsUsingCustomConverter() {
expectedException.expect(ParameterConvertionFailed.class);
expectedException.expectMessage("No parameter converter for java.util.Collection<org.jbehave.core.steps.ParameterConvertersBehaviour$Bar>");
ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath());
parameterConverters.addConverters(new FooToBarParameterConverter());
Type type = new TypeLiteral<Collection<Bar>>() {
}.getType();
parameterConverters.convert("foo", type);
}
Aggregations