use of org.jbehave.core.steps.ParameterConverters.NumberListConverter 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.NumberListConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldConvertCommaSeparatedValuesToListOfNumbersWithDefaultFormat.
@Test
public void shouldConvertCommaSeparatedValuesToListOfNumbersWithDefaultFormat() {
ParameterConverter<List<Number>> converter = new NumberListConverter();
Type listOfNumbers = new TypeLiteral<List<Number>>() {
}.getType();
Type setOfNumbers = new TypeLiteral<Set<Number>>() {
}.getType();
assertThat(converter.accept(listOfNumbers), is(true));
assertThat(converter.accept(setOfNumbers), is(false));
List<Number> list = converter.convertValue("3, 0.5, 6.1f, 8.00", listOfNumbers);
assertThatCollectionIs(list, 3L, 0.5, 6.1, 8L);
}
use of org.jbehave.core.steps.ParameterConverters.NumberListConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldConvertCommaSeparatedValuesToListOfNumbersWithCustomFormat.
@Test
public void shouldConvertCommaSeparatedValuesToListOfNumbersWithCustomFormat() {
ParameterConverter<List<Number>> converter = new NumberListConverter(new DecimalFormat("#,####"), " ");
Type type = new TypeLiteral<List<Number>>() {
}.getType();
List<Number> list = converter.convertValue("3,000 0.5 6.1f 8.00", type);
assertThatCollectionIs(list, 3000L, 0.5, 6.1, 8L);
}
use of org.jbehave.core.steps.ParameterConverters.NumberListConverter in project jbehave-core by jbehave.
the class ParameterConvertersBehaviour method shouldFailToConvertCommaSeparatedValuesOfInvalidNumbers.
@Test
public void shouldFailToConvertCommaSeparatedValuesOfInvalidNumbers() {
expectedException.expect(ParameterConvertionFailed.class);
new NumberListConverter().convertValue("3x, x.5", new TypeLiteral<List<Number>>() {
}.getType());
}
Aggregations