aboutsummaryrefslogtreecommitdiffstats
path: root/compatibility-server/src/test/java/com/vaadin/v7/tests/data/converter/StringToBigIntegerConverterTest.java
blob: e351fdda568c8e6dd0d47686551bb8f3e886861b (plain)
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
package com.vaadin.v7.tests.data.converter;

import static org.junit.Assert.assertEquals;

import java.math.BigInteger;
import java.util.Locale;

import org.junit.Test;

import com.vaadin.v7.data.util.converter.StringToBigIntegerConverter;

public class StringToBigIntegerConverterTest {

    StringToBigIntegerConverter converter = new StringToBigIntegerConverter();

    @Test
    public void testNullConversion() {
        assertEquals("Null value was converted incorrectly", null,
                converter.convertToModel(null, BigInteger.class, null));
    }

    @Test
    public void testEmptyStringConversion() {
        assertEquals("Empty value was converted incorrectly", null,
                converter.convertToModel("", BigInteger.class, null));
    }

    @Test
    public void testValueParsing() {
        String bigInt = "1180591620717411303424"; // 2^70 > 2^63 - 1
        BigInteger converted = converter.convertToModel(bigInt,
                BigInteger.class, null);
        BigInteger expected = new BigInteger(bigInt);
        assertEquals("Value bigger than max long was converted incorrectly",
                expected, converted);
    }

    @Test
    public void testValueFormatting() {
        BigInteger bd = new BigInteger("1000");
        String expected = "1.000";

        String converted = converter.convertToPresentation(bd, String.class,
                Locale.GERMAN);
        assertEquals("Value with specific locale was converted incorrectly",
                expected, converted);
    }
}