summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorAnna Miroshnik <anna.miroshnik@arcadia.spb.ru>2014-12-04 15:52:27 +0300
committerVaadin Code Review <review@vaadin.com>2014-12-08 19:14:31 +0000
commita28d6c2098e738dfd78e1df929ce689a2ceb6c2a (patch)
tree9b9e725043d4e6ad3d6f25ee5a28e4e8bf533bab /server/tests
parentbf4e325ac6387cac0afc8096b3ca65b88bf9fdfd (diff)
downloadvaadin-framework-a28d6c2098e738dfd78e1df929ce689a2ceb6c2a.tar.gz
vaadin-framework-a28d6c2098e738dfd78e1df929ce689a2ceb6c2a.zip
Add new StringTo<Byte, Short, BigInteger> Converters (#14583)
DefaultConverterFactory was updated, added missed types. Change-Id: I65cffc7f91df6f40e132b45e325e15f029f9848c
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java28
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java16
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java15
3 files changed, 36 insertions, 23 deletions
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java
index 641f18c865..8d493609fe 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBigIntegerConverter.java
@@ -15,39 +15,43 @@
*/
package com.vaadin.tests.data.converter;
-import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.Locale;
import junit.framework.TestCase;
-import com.vaadin.data.util.converter.StringToBigDecimalConverter;
+import com.vaadin.data.util.converter.StringToBigIntegerConverter;
public class TestStringToBigIntegerConverter extends TestCase {
- StringToBigDecimalConverter converter = new StringToBigDecimalConverter();
+ StringToBigIntegerConverter converter = new StringToBigIntegerConverter();
public void testNullConversion() {
- assertEquals(null,
- converter.convertToModel(null, BigDecimal.class, null));
+ assertEquals("Null value was converted incorrectly", null,
+ converter.convertToModel(null, BigInteger.class, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", BigDecimal.class, null));
+ assertEquals("Empty value was converted incorrectly", null,
+ converter.convertToModel("", BigInteger.class, null));
}
public void testValueParsing() {
- BigDecimal converted = converter.convertToModel("10", BigDecimal.class,
- null);
- BigDecimal expected = new BigDecimal(10);
- assertEquals(expected, converted);
+ 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);
}
public void testValueFormatting() {
- BigDecimal bd = new BigDecimal(1000);
+ BigInteger bd = new BigInteger("1000");
String expected = "1.000";
String converted = converter.convertToPresentation(bd, String.class,
Locale.GERMAN);
- assertEquals(expected, converted);
+ assertEquals("Value with specific locale was converted incorrectly",
+ expected, converted);
}
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java
index 440d056c06..19a68fbfdb 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToByteConverter.java
@@ -16,25 +16,28 @@ public class TestStringToByteConverter extends TestCase {
converter);
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Byte.class, null));
+ assertEquals("Null value was converted incorrectly", null,
+ converter.convertToModel(null, Byte.class, null));
}
public void testReverseNullConversion() {
- assertEquals(null,
+ assertEquals("Null value reversely was converted incorrectly", null,
reverseConverter.convertToModel(null, String.class, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Byte.class, null));
+ assertEquals("Empty value was converted incorrectly", null,
+ converter.convertToModel("", Byte.class, null));
}
public void testValueConversion() {
- assertEquals(Byte.valueOf((byte) 10),
+ assertEquals("Byte value was converted incorrectly",
+ Byte.valueOf((byte) 10),
converter.convertToModel("10", Byte.class, null));
}
public void testReverseValueConversion() {
- assertEquals(
+ assertEquals("Byte value reversely was converted incorrectly",
reverseConverter.convertToModel((byte) 10, String.class, null),
"10");
}
@@ -43,7 +46,8 @@ public class TestStringToByteConverter extends TestCase {
byte b = converter.convertToModel("127", Byte.class, null);
Assert.assertEquals(Byte.MAX_VALUE, b);
b = converter.convertToModel("-128", Byte.class, null);
- assertEquals(Byte.MIN_VALUE, b);
+ assertEquals("Min byte value was converted incorrectly",
+ Byte.MIN_VALUE, b);
}
public void testValueOutOfRange() {
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java
index 35547d2570..542c580025 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToShortConverter.java
@@ -16,25 +16,29 @@ public class TestStringToShortConverter extends TestCase {
converter);
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, Short.class, null));
+ assertEquals("Null value was converted incorrectly", null,
+ converter.convertToModel(null, Short.class, null));
}
public void testReverseNullConversion() {
- assertEquals(null,
+ assertEquals("Null value reversely was converted incorrectly", null,
reverseConverter.convertToModel(null, String.class, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", Short.class, null));
+ assertEquals("Empty value was converted incorrectly", null,
+ converter.convertToModel("", Short.class, null));
}
public void testValueConversion() {
- assertEquals(Short.valueOf((short) 10),
+ assertEquals("Short value was converted incorrectly",
+ Short.valueOf((short) 10),
converter.convertToModel("10", Short.class, null));
}
public void testReverseValueConversion() {
assertEquals(
+ "Short value reversely was converted incorrectly",
reverseConverter.convertToModel((short) 10, String.class, null),
"10");
}
@@ -43,7 +47,8 @@ public class TestStringToShortConverter extends TestCase {
short b = converter.convertToModel("32767", Short.class, null);
Assert.assertEquals(Short.MAX_VALUE, b);
b = converter.convertToModel("-32768", Short.class, null);
- assertEquals(Short.MIN_VALUE, b);
+ assertEquals("Min short value was converted incorrectly",
+ Short.MIN_VALUE, b);
}
public void testValueOutOfRange() {