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.

StringToBigIntegerConverterTest.java 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. package com.vaadin.v7.tests.data.converter;
  2. import static org.junit.Assert.assertEquals;
  3. import java.math.BigInteger;
  4. import java.util.Locale;
  5. import org.junit.Test;
  6. import com.vaadin.v7.data.util.converter.StringToBigIntegerConverter;
  7. public class StringToBigIntegerConverterTest {
  8. StringToBigIntegerConverter converter = new StringToBigIntegerConverter();
  9. @Test
  10. public void testNullConversion() {
  11. assertEquals("Null value was converted incorrectly", null,
  12. converter.convertToModel(null, BigInteger.class, null));
  13. }
  14. @Test
  15. public void testEmptyStringConversion() {
  16. assertEquals("Empty value was converted incorrectly", null,
  17. converter.convertToModel("", BigInteger.class, null));
  18. }
  19. @Test
  20. public void testValueParsing() {
  21. String bigInt = "1180591620717411303424"; // 2^70 > 2^63 - 1
  22. BigInteger converted = converter.convertToModel(bigInt,
  23. BigInteger.class, null);
  24. BigInteger expected = new BigInteger(bigInt);
  25. assertEquals("Value bigger than max long was converted incorrectly",
  26. expected, converted);
  27. }
  28. @Test
  29. public void testValueFormatting() {
  30. BigInteger bd = new BigInteger("1000");
  31. String expected = "1.000";
  32. String converted = converter.convertToPresentation(bd, String.class,
  33. Locale.GERMAN);
  34. assertEquals("Value with specific locale was converted incorrectly",
  35. expected, converted);
  36. }
  37. }