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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
|
package com.vaadin.tests.data.converter;
import static org.junit.Assert.assertEquals;
import org.junit.Test;
import com.vaadin.data.Result;
import com.vaadin.data.ValueContext;
import com.vaadin.data.converter.StringToLongConverter;
public class StringToLongConverterTest extends AbstractStringConverterTest {
@Override
protected StringToLongConverter getConverter() {
return new StringToLongConverter(getErrorMessage());
}
@Override
@Test
public void testEmptyStringConversion() {
assertValue(null,
getConverter().convertToModel("", new ValueContext()));
}
@Test
public void testValueConversion() {
assertValue(Long.valueOf(10),
getConverter().convertToModel("10", new ValueContext()));
}
@Test
public void testExtremeLongValueConversion() {
Result<Long> l = getConverter().convertToModel("9223372036854775807",
new ValueContext());
assertValue(Long.MAX_VALUE, l);
l = getConverter().convertToModel("-9223372036854775808",
new ValueContext());
assertValue(Long.MIN_VALUE, l);
}
@Test
public void testOutOfBoundsValueConversion() {
// Long.MAX_VALUE+1 is converted to Long.MAX_VALUE
Result<Long> l = getConverter().convertToModel("9223372036854775808",
new ValueContext());
assertValue(Long.MAX_VALUE, l);
// Long.MIN_VALUE-1 is converted to Long.MIN_VALUE
l = getConverter().convertToModel("-9223372036854775809",
new ValueContext());
assertValue(Long.MIN_VALUE, l);
}
@Test
public void customEmptyValue() {
StringToLongConverter converter = new StringToLongConverter((long) 0,
getErrorMessage());
assertValue((long) 0, converter.convertToModel("", new ValueContext()));
assertEquals("0",
converter.convertToPresentation((long) 0, new ValueContext()));
}
}
|