123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- package com.vaadin.tests.data.converter;
-
- import org.junit.Assert;
- import org.junit.Test;
-
- import com.vaadin.v7.data.util.converter.LegacyConverter.ConversionException;
- import com.vaadin.v7.data.util.converter.LegacyStringToIntegerConverter;
-
- public class StringToIntegerConverterTest {
-
- LegacyStringToIntegerConverter converter = new LegacyStringToIntegerConverter();
-
- @Test
- public void testNullConversion() {
- Assert.assertEquals(null,
- converter.convertToModel(null, Integer.class, null));
- }
-
- @Test
- public void testEmptyStringConversion() {
- Assert.assertEquals(null,
- converter.convertToModel("", Integer.class, null));
- }
-
- @Test
- public void testValueOutOfRange() {
- Double[] values = new Double[] { Integer.MAX_VALUE * 2.0,
- Integer.MIN_VALUE * 2.0, Long.MAX_VALUE * 2.0,
- Long.MIN_VALUE * 2.0 };
-
- boolean accepted = false;
- for (Number value : values) {
- try {
- converter.convertToModel(String.format("%.0f", value),
- Integer.class, null);
- accepted = true;
- } catch (ConversionException expected) {
- }
- }
- Assert.assertFalse("Accepted value outside range of int", accepted);
- }
-
- @Test
- public void testValueConversion() {
- Assert.assertEquals(Integer.valueOf(10),
- converter.convertToModel("10", Integer.class, null));
- }
- }
|