You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

StringToBigDecimalConverterTest.java 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. package com.vaadin.v7.tests.data.converter;
  2. import static org.junit.Assert.assertEquals;
  3. import java.math.BigDecimal;
  4. import java.util.Locale;
  5. import org.junit.Test;
  6. import com.vaadin.v7.data.util.converter.StringToBigDecimalConverter;
  7. public class StringToBigDecimalConverterTest {
  8. StringToBigDecimalConverter converter = new StringToBigDecimalConverter();
  9. @Test
  10. public void testNullConversion() {
  11. assertEquals(null,
  12. converter.convertToModel(null, BigDecimal.class, null));
  13. }
  14. @Test
  15. public void testEmptyStringConversion() {
  16. assertEquals(null,
  17. converter.convertToModel("", BigDecimal.class, null));
  18. }
  19. @Test
  20. public void testValueParsing() {
  21. BigDecimal converted = converter.convertToModel("10", BigDecimal.class,
  22. null);
  23. BigDecimal expected = new BigDecimal(10);
  24. assertEquals(expected, converted);
  25. }
  26. @Test
  27. public void testValueFormatting() {
  28. BigDecimal bd = new BigDecimal(12.5);
  29. String expected = "12,5";
  30. String converted = converter.convertToPresentation(bd, String.class,
  31. Locale.GERMAN);
  32. assertEquals(expected, converted);
  33. }
  34. }