use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldConvertEnumList.
@Test
public void shouldConvertEnumList() {
ParameterConverter converter = new EnumListConverter();
Type type = new TypeLiteral<List<SomeEnum>>() {
}.getType();
assertThat(converter.accept(type), is(true));
List<Enum> list = (List<Enum>) converter.convertValue("ONE,TWO,THREE", type);
assertThatCollectionIs(list, SomeEnum.ONE, SomeEnum.TWO, SomeEnum.THREE);
}
use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldConvertCommaSeparatedValuesOfSpecificNumberTypes.
@SuppressWarnings("unchecked")
@Test
public void shouldConvertCommaSeparatedValuesOfSpecificNumberTypes() {
ParameterConverter converter = new NumberListConverter();
Type doubleType = new TypeLiteral<List<Double>>() {
}.getType();
List<Double> doubles = (List<Double>) converter.convertValue("3, 0.5, 0.0, 8.00, " + NAN + ", " + POSITIVE_INFINITY, doubleType);
assertThatCollectionIs(doubles, 3.0, 0.5, 0.0, 8.0, Double.NaN, Double.POSITIVE_INFINITY);
Type floatType = new TypeLiteral<List<Float>>() {
}.getType();
List<Float> floats = (List<Float>) converter.convertValue("3, 0.5, 0.0, 8.00, " + NAN + ", " + NEGATIVE_INFINITY, floatType);
assertThatCollectionIs(floats, 3.0f, 0.5f, 0.0f, 8.0f, Float.NaN, Float.NEGATIVE_INFINITY);
Type longType = new TypeLiteral<List<Long>>() {
}.getType();
List<Long> longs = (List<Long>) converter.convertValue("3, 0, 8", longType);
assertThatCollectionIs(longs, 3L, 0L, 8L);
Type intType = new TypeLiteral<List<Integer>>() {
}.getType();
List<Integer> ints = (List<Integer>) converter.convertValue("3, 0, 8", intType);
assertThatCollectionIs(ints, 3, 0, 8);
}
use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldFailToConvertParameterFromFailingMethodReturningValue.
@Test
public void shouldFailToConvertParameterFromFailingMethodReturningValue() throws IntrospectionException {
expectedException.expect(ParameterConvertionFailed.class);
Method method = SomeSteps.methodFor("aFailingMethodReturningExamplesTable");
ParameterConverter converter = new MethodReturningConverter(method, new SomeSteps());
String value = "|col1|col2|\n|row11|row12|\n|row21|row22|\n";
converter.convertValue(value, ExamplesTable.class);
}
use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.
the class ConcurrencyBehaviour method shouldAllowConcurrentAdditionOfParameterConvertersInThreadSafeMode.
@Test
public void shouldAllowConcurrentAdditionOfParameterConvertersInThreadSafeMode() {
final ParameterConverters parameterConverters = new ParameterConverters(new LoadFromClasspath(), new ParameterControls(), new TableTransformers(), true);
final boolean[] active = new boolean[] { true };
final ParameterConverter[] toAdd = new ParameterConverter[] { mock(ParameterConverter.class, "one"), mock(ParameterConverter.class, "two"), mock(ParameterConverter.class, "three") };
Thread t = new Thread(new Runnable() {
@Override
public void run() {
while (active[0]) {
parameterConverters.addConverters(toAdd);
}
}
});
t.start();
parameterConverters.convert("test", String.class);
active[0] = false;
}
use of org.jbehave.core.steps.ParameterConverters.ParameterConverter in project jbehave-core by jbehave.
the class SpringAnnotationBuilder method getBeansOfType.
private List<ParameterConverter> getBeansOfType(ApplicationContext context, Class<ParameterConverter> type) {
Map<String, ParameterConverter> beansOfType = context.getBeansOfType(type);
List<ParameterConverter> converters = new ArrayList<>();
for (ParameterConverter converter : beansOfType.values()) {
converters.add(converter);
}
return converters;
}
Aggregations