use of io.vertigo.dynamo.domain.metamodel.Formatter in project vertigo by KleeGroup.
the class NumberFormatterTest method testFormatterNumber.
/**
* Test du formatter de nombre.
* @throws FormatterException e
*/
@Test
public void testFormatterNumber() throws FormatterException {
final Formatter formatterNumber = new FormatterNumber("#,###,##0.00");
// BigDecimal
final BigDecimal pi = new BigDecimal("3.14");
Assert.assertEquals(pi, formatterNumber.stringToValue("3.14", DataType.BigDecimal));
Assert.assertEquals(pi, formatterNumber.stringToValue("3,14", DataType.BigDecimal));
Assert.assertEquals("3,14", formatterNumber.valueToString(pi, DataType.BigDecimal));
Assert.assertEquals(new BigDecimal("0.14"), formatterNumber.stringToValue("0.14", DataType.BigDecimal));
// Integer
Assert.assertEquals(1492, formatterNumber.stringToValue("1492", DataType.Integer));
Assert.assertEquals(1492, formatterNumber.stringToValue("1 492", DataType.Integer));
Assert.assertEquals(1492, formatterNumber.stringToValue("1492 ", DataType.Integer));
Assert.assertEquals(1492, formatterNumber.stringToValue("01492 ", DataType.Integer));
// Long
Assert.assertEquals(1492L, formatterNumber.stringToValue("1492", DataType.Long));
Assert.assertEquals(1492L, formatterNumber.stringToValue("1 492", DataType.Long));
Assert.assertEquals(1492L, formatterNumber.stringToValue("1492 ", DataType.Long));
Assert.assertEquals(1492L, formatterNumber.stringToValue("01492 ", DataType.Long));
// Double
Assert.assertEquals(3.14D, formatterNumber.stringToValue("3.14", DataType.Double));
Assert.assertEquals(3.14D, formatterNumber.stringToValue("3,14", DataType.Double));
Assert.assertEquals(.14D, formatterNumber.stringToValue("0.14", DataType.Double));
Assert.assertEquals("3,14", formatterNumber.valueToString(3.14D, DataType.Double));
}
use of io.vertigo.dynamo.domain.metamodel.Formatter in project vertigo by KleeGroup.
the class OOMEnvironmentManagerTest method testDefaultBooleanFormatter.
@Test
public void testDefaultBooleanFormatter() {
final DefinitionSpace definitionSpace = getApp().getDefinitionSpace();
final Formatter formatter = definitionSpace.resolve("FMT_DEFAULT", FormatterDefinition.class);
Assert.assertEquals("MyTrue", formatter.valueToString(true, DataType.Boolean));
}
Aggregations