1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
|
package com.vaadin.v7.tests.data.converter;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import org.junit.Test;
import com.vaadin.v7.data.util.converter.Converter.ConversionException;
import com.vaadin.v7.data.util.converter.StringToIntegerConverter;
public class StringToIntegerConverterTest {
StringToIntegerConverter converter = new StringToIntegerConverter();
@Test
public void testNullConversion() {
assertEquals(null, converter.convertToModel(null, Integer.class, null));
}
@Test
public void testEmptyStringConversion() {
assertEquals(null, converter.convertToModel("", Integer.class, null));
}
@Test
public void testValueOutOfRange() {
Double[] values = { 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) {
}
}
assertFalse("Accepted value outside range of int", accepted);
}
@Test
public void testValueConversion() {
assertEquals(Integer.valueOf(10),
converter.convertToModel("10", Integer.class, null));
}
}
|