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.

StringToIntegerConverterTest.java 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package com.vaadin.tests.data.converter;
  2. import org.junit.Assert;
  3. import org.junit.Test;
  4. import com.vaadin.data.util.converter.StringToIntegerConverter;
  5. public class StringToIntegerConverterTest extends AbstractConverterTest {
  6. @Override
  7. protected StringToIntegerConverter getConverter() {
  8. return new StringToIntegerConverter("Failed");
  9. }
  10. @Test
  11. public void testEmptyStringConversion() {
  12. assertResult(null, getConverter().convertToModel("", null));
  13. }
  14. @Test
  15. public void testValueOutOfRange() {
  16. Double[] values = new Double[] { Integer.MAX_VALUE * 2.0,
  17. Integer.MIN_VALUE * 2.0, Long.MAX_VALUE * 2.0,
  18. Long.MIN_VALUE * 2.0 };
  19. boolean accepted = false;
  20. for (Number value : values) {
  21. try {
  22. getConverter().convertToModel(String.format("%.0f", value),
  23. null);
  24. } catch (Exception e) {
  25. accepted = true;
  26. }
  27. }
  28. Assert.assertFalse("Accepted value outside range of int", accepted);
  29. }
  30. @Test
  31. public void testValueConversion() {
  32. assertResult(Integer.valueOf(10),
  33. getConverter().convertToModel("10", null));
  34. }
  35. }