use of cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter in project cucumber-jvm by cucumber.
the class ConvertersTest method shouldTransformToTypeWithStringCtor.
@Test
public void shouldTransformToTypeWithStringCtor() {
SingleValueConverter c = ((DynamicClassBasedSingleValueConverter) en.lookupConverterForType(MyClass.class)).converterForClass(MyClass.class);
assertEquals("X", ((MyClass) c.fromString("X")).s);
}
use of cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter in project cucumber-jvm by cucumber.
the class ConvertersTest method shouldTransformToTypeWithObjectCtor.
@Test
public void shouldTransformToTypeWithObjectCtor() {
SingleValueConverter c = ((DynamicClassBasedSingleValueConverter) en.lookupConverterForType(MyOtherClass.class)).converterForClass(MyOtherClass.class);
assertEquals("X", ((MyOtherClass) c.fromString("X")).o);
}
use of cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter in project cucumber-jvm by cucumber.
the class TableConverter method toMaps.
public <K, V> List<Map<K, V>> toMaps(DataTable dataTable, Type keyType, Type valueType) {
try {
xStream.setParameterInfo(parameterInfo);
SingleValueConverter keyConverter = xStream.getSingleValueConverter(keyType);
SingleValueConverter valueConverter = xStream.getSingleValueConverter(valueType);
if (keyConverter == null || valueConverter == null) {
throw new CucumberException(String.format("Can't convert DataTable to List<Map<%s,%s>>", keyType, valueType));
}
List<Map<K, V>> result = new ArrayList<Map<K, V>>();
List<String> keyStrings = dataTable.topCells();
List<K> keys = new ArrayList<K>();
for (String keyString : keyStrings) {
keys.add((K) keyConverter.fromString(keyString));
}
List<List<String>> valueRows = dataTable.cells(1);
for (List<String> valueRow : valueRows) {
Map<K, V> map = new LinkedHashMap<K, V>();
int i = 0;
for (String cell : valueRow) {
map.put(keys.get(i), (V) valueConverter.fromString(cell));
i++;
}
result.add(Collections.unmodifiableMap(map));
}
return Collections.unmodifiableList(result);
} finally {
xStream.unsetParameterInfo();
}
}
use of cucumber.deps.com.thoughtworks.xstream.converters.SingleValueConverter in project cucumber-jvm by cucumber.
the class ConvertersTest method shouldTransformToTheRightType.
@Test
public void shouldTransformToTheRightType() {
assertTrue((Boolean) ((SingleValueConverter) en.lookupConverterForType(Boolean.class)).fromString("true"));
assertTrue((Boolean) ((SingleValueConverter) en.lookupConverterForType(Boolean.TYPE)).fromString("true"));
assertEquals(3000.15f, (Float) ((SingleValueConverter) en.lookupConverterForType(Float.class)).fromString("3000.15"), 0.000001);
assertEquals(3000.15f, (Float) ((SingleValueConverter) en.lookupConverterForType(Float.TYPE)).fromString("3000.15"), 0.000001);
assertEquals(new BigDecimal("3000.15"), ((SingleValueConverter) en.lookupConverterForType(BigDecimal.class)).fromString("3000.15"));
assertEquals(3000.15f, (Float) ((SingleValueConverter) no.lookupConverterForType(Float.TYPE)).fromString("3000,15"), 0.000001);
}
Aggregations