summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-06-10 20:01:40 +0300
committerVaadin Code Review <review@vaadin.com>2013-06-11 12:40:09 +0000
commit3d9d47d222a53e33267cb3f26112782fe9f12caf (patch)
treea8fdc3a5bcaecf535673f957f8ef1bb7254d1f73 /server/tests
parent5793a1c3a2da2c9771bd1721483a4689100d4bc3 (diff)
downloadvaadin-framework-3d9d47d222a53e33267cb3f26112782fe9f12caf.tar.gz
vaadin-framework-3d9d47d222a53e33267cb3f26112782fe9f12caf.zip
Added type parameter to converter methods (#11895)
Change-Id: I6562c537d9e5a0745eb67bc613123a265578ae00
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java6
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestAnyEnumToStringConverter.java37
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestDateToLongConverter.java4
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestSpecificEnumToStringConverter.java16
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToBooleanConverter.java8
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToDateConverter.java6
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToDoubleConverter.java6
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToFloatConverter.java7
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToIntegerConverter.java7
-rw-r--r--server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java9
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java14
11 files changed, 65 insertions, 55 deletions
diff --git a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java
index 9da8406507..b53c5a930f 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/ConverterFactory.java
@@ -30,13 +30,15 @@ public class ConverterFactory extends TestCase {
public static class ConvertTo42 implements Converter<String, Integer> {
@Override
- public Integer convertToModel(String value, Locale locale)
+ public Integer convertToModel(String value,
+ Class<? extends Integer> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
return 42;
}
@Override
- public String convertToPresentation(Integer value, Locale locale)
+ public String convertToPresentation(Integer value,
+ Class<? extends String> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
return "42";
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestAnyEnumToStringConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestAnyEnumToStringConverter.java
index c267e012e8..e21382069f 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestAnyEnumToStringConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestAnyEnumToStringConverter.java
@@ -33,14 +33,12 @@ public class TestAnyEnumToStringConverter {
public class AnyEnumToStringConverter implements Converter<Enum, String> {
- private Class<? extends Enum>[] enumClass;
-
- public AnyEnumToStringConverter(Class<? extends Enum>... enumClass) {
- this.enumClass = enumClass;
+ public AnyEnumToStringConverter() {
}
@Override
- public String convertToModel(Enum value, Locale locale)
+ public String convertToModel(Enum value,
+ Class<? extends String> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null) {
return null;
@@ -50,16 +48,15 @@ public class TestAnyEnumToStringConverter {
}
@Override
- public Enum convertToPresentation(String value, Locale locale)
+ public Enum convertToPresentation(String value,
+ Class<? extends Enum> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null) {
return null;
}
- for (Class<? extends Enum> candidate : enumClass) {
- for (Enum e : candidate.getEnumConstants()) {
- if (e.toString().equals(value)) {
- return e;
- }
+ for (Enum e : targetType.getEnumConstants()) {
+ if (e.toString().equals(value)) {
+ return e;
}
}
@@ -82,29 +79,29 @@ public class TestAnyEnumToStringConverter {
@Before
public void setup() {
- converter = new AnyEnumToStringConverter(TestEnum.class,
- AnotherTestEnum.class);
+ converter = new AnyEnumToStringConverter();
}
@Test
public void nullConversion() {
- Assert.assertEquals(null, converter.convertToModel(null, null));
+ Assert.assertEquals(null, converter.convertToModel(null, null, null));
}
@Test
public void enumToStringConversion() {
Assert.assertEquals(TestEnum.TWO.toString(),
- converter.convertToModel(TestEnum.TWO, null));
- Assert.assertEquals(AnotherTestEnum.TWO.toString(),
- converter.convertToModel(AnotherTestEnum.TWO, null));
+ converter.convertToModel(TestEnum.TWO, String.class, null));
+ Assert.assertEquals(AnotherTestEnum.TWO.toString(), converter
+ .convertToModel(AnotherTestEnum.TWO, String.class, null));
}
@Test
public void stringToEnumConversion() {
- Assert.assertEquals(TestEnum.TWO,
- converter.convertToPresentation(TestEnum.TWO.toString(), null));
+ Assert.assertEquals(TestEnum.TWO, converter.convertToPresentation(
+ TestEnum.TWO.toString(), TestEnum.class, null));
Assert.assertEquals(AnotherTestEnum.TWO, converter
- .convertToPresentation(AnotherTestEnum.TWO.toString(), null));
+ .convertToPresentation(AnotherTestEnum.TWO.toString(),
+ AnotherTestEnum.class, null));
}
@Test
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestDateToLongConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestDateToLongConverter.java
index aab4ae18f0..6b9fa93e27 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestDateToLongConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestDateToLongConverter.java
@@ -11,11 +11,11 @@ public class TestDateToLongConverter extends TestCase {
DateToLongConverter converter = new DateToLongConverter();
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, null));
+ assertEquals(null, converter.convertToModel(null, Long.class, null));
}
public void testValueConversion() {
assertEquals(Long.valueOf(946677600000l),
- converter.convertToModel(new Date(100, 0, 1), null));
+ converter.convertToModel(new Date(100, 0, 1), Long.class, null));
}
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestSpecificEnumToStringConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestSpecificEnumToStringConverter.java
index 93dbe96b56..8ce7b8eab8 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestSpecificEnumToStringConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestSpecificEnumToStringConverter.java
@@ -41,7 +41,8 @@ public class TestSpecificEnumToStringConverter {
}
@Override
- public String convertToModel(Enum value, Locale locale)
+ public String convertToModel(Enum value,
+ Class<? extends String> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null) {
return null;
@@ -51,7 +52,8 @@ public class TestSpecificEnumToStringConverter {
}
@Override
- public Enum convertToPresentation(String value, Locale locale)
+ public Enum convertToPresentation(String value,
+ Class<? extends Enum> targetType, Locale locale)
throws com.vaadin.data.util.converter.Converter.ConversionException {
if (value == null) {
return null;
@@ -90,19 +92,21 @@ public class TestSpecificEnumToStringConverter {
@Test
public void nullConversion() {
- Assert.assertEquals(null, testEnumConverter.convertToModel(null, null));
+ Assert.assertEquals(null,
+ testEnumConverter.convertToModel(null, null, null));
}
@Test
public void enumToStringConversion() {
- Assert.assertEquals(TestEnum.TWO.toString(),
- testEnumConverter.convertToModel(TestEnum.TWO, null));
+ Assert.assertEquals(TestEnum.TWO.toString(), testEnumConverter
+ .convertToModel(TestEnum.TWO, String.class, null));
}
@Test
public void stringToEnumConversion() {
Assert.assertEquals(TestEnum.TWO, testEnumConverter
- .convertToPresentation(TestEnum.TWO.toString(), null));
+ .convertToPresentation(TestEnum.TWO.toString(), TestEnum.class,
+ null));
}
@Test
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToBooleanConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBooleanConverter.java
index 1c2b919db0..f236bb4000 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToBooleanConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToBooleanConverter.java
@@ -9,15 +9,15 @@ public class TestStringToBooleanConverter extends TestCase {
StringToBooleanConverter converter = new StringToBooleanConverter();
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, null));
+ assertEquals(null, converter.convertToModel(null, null, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", null));
+ assertEquals(null, converter.convertToModel("", Boolean.class, null));
}
public void testValueConversion() {
- assertTrue(converter.convertToModel("true", null));
- assertFalse(converter.convertToModel("false", null));
+ assertTrue(converter.convertToModel("true", Boolean.class, null));
+ assertFalse(converter.convertToModel("false", Boolean.class, null));
}
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToDateConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToDateConverter.java
index 2961b93c89..59314bd5ee 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToDateConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToDateConverter.java
@@ -12,15 +12,15 @@ public class TestStringToDateConverter extends TestCase {
StringToDateConverter converter = new StringToDateConverter();
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, null));
+ assertEquals(null, converter.convertToModel(null, null, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", null));
+ assertEquals(null, converter.convertToModel("", Date.class, null));
}
public void testValueConversion() {
assertEquals(new Date(100, 0, 1), converter.convertToModel(
- "Jan 1, 2000 12:00:00 AM", Locale.ENGLISH));
+ "Jan 1, 2000 12:00:00 AM", Date.class, Locale.ENGLISH));
}
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToDoubleConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToDoubleConverter.java
index 9903a8deaa..739f9b7d5a 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToDoubleConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToDoubleConverter.java
@@ -9,14 +9,14 @@ public class TestStringToDoubleConverter extends TestCase {
StringToDoubleConverter converter = new StringToDoubleConverter();
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, null));
+ assertEquals(null, converter.convertToModel(null, null, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", null));
+ assertEquals(null, converter.convertToModel("", Double.class, null));
}
public void testValueConversion() {
- assertEquals(10.0, converter.convertToModel("10", null));
+ assertEquals(10.0, converter.convertToModel("10", Double.class, null));
}
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToFloatConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToFloatConverter.java
index 670daec202..3bb2b3649e 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToFloatConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToFloatConverter.java
@@ -9,14 +9,15 @@ public class TestStringToFloatConverter extends TestCase {
StringToFloatConverter converter = new StringToFloatConverter();
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, null));
+ assertEquals(null, converter.convertToModel(null, null, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", null));
+ assertEquals(null, converter.convertToModel("", Float.class, null));
}
public void testValueConversion() {
- assertEquals(Float.valueOf(10), converter.convertToModel("10", null));
+ assertEquals(Float.valueOf(10),
+ converter.convertToModel("10", Float.class, null));
}
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToIntegerConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToIntegerConverter.java
index 80414cccaf..7f247b791f 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToIntegerConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToIntegerConverter.java
@@ -9,14 +9,15 @@ public class TestStringToIntegerConverter extends TestCase {
StringToIntegerConverter converter = new StringToIntegerConverter();
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, null));
+ assertEquals(null, converter.convertToModel(null, null, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", null));
+ assertEquals(null, converter.convertToModel("", Integer.class, null));
}
public void testValueConversion() {
- assertEquals(Integer.valueOf(10), converter.convertToModel("10", null));
+ assertEquals(Integer.valueOf(10),
+ converter.convertToModel("10", Integer.class, null));
}
}
diff --git a/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java b/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java
index d3f87d628a..9c322cd301 100644
--- a/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java
+++ b/server/tests/src/com/vaadin/tests/data/converter/TestStringToNumberConverter.java
@@ -9,15 +9,16 @@ public class TestStringToNumberConverter extends TestCase {
StringToNumberConverter converter = new StringToNumberConverter();
public void testNullConversion() {
- assertEquals(null, converter.convertToModel(null, null));
+ assertEquals(null, converter.convertToModel(null, null, null));
}
public void testEmptyStringConversion() {
- assertEquals(null, converter.convertToModel("", null));
+ assertEquals(null, converter.convertToModel("", Number.class, null));
}
public void testValueConversion() {
- assertEquals(Long.valueOf(10), converter.convertToModel("10", null));
- assertEquals(10.5, converter.convertToModel("10.5", null));
+ assertEquals(Long.valueOf(10),
+ converter.convertToModel("10", Number.class, null));
+ assertEquals(10.5, converter.convertToModel("10.5", Number.class, null));
}
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java
index b5e937f27d..9854296538 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java
@@ -85,12 +85,14 @@ public class AbsFieldValueConversions extends TestCase {
tf.setConverter(new Converter<String, String>() {
@Override
- public String convertToModel(String value, Locale locale) {
+ public String convertToModel(String value,
+ Class<? extends String> targetType, Locale locale) {
return value;
}
@Override
- public String convertToPresentation(String value, Locale locale) {
+ public String convertToPresentation(String value,
+ Class<? extends String> targetType, Locale locale) {
return value;
}
@@ -150,7 +152,8 @@ public class AbsFieldValueConversions extends TestCase {
cb.setConverter(new Converter<Boolean, Boolean>() {
@Override
- public Boolean convertToModel(Boolean value, Locale locale) {
+ public Boolean convertToModel(Boolean value,
+ Class<? extends Boolean> targetType, Locale locale) {
// value from a CheckBox should never be null as long as it is
// not set to null (handled by conversion below).
assertNotNull(value);
@@ -158,7 +161,8 @@ public class AbsFieldValueConversions extends TestCase {
}
@Override
- public Boolean convertToPresentation(Boolean value, Locale locale) {
+ public Boolean convertToPresentation(Boolean value,
+ Class<? extends Boolean> targetType, Locale locale) {
// Datamodel -> field
if (value == null) {
return false;
@@ -184,7 +188,7 @@ public class AbsFieldValueConversions extends TestCase {
assertEquals(Boolean.FALSE, property.getValue());
assertEquals(Boolean.FALSE, cb.getValue());
Boolean newDmValue = cb.getConverter().convertToPresentation(
- cb.getValue(), new Locale("fi", "FI"));
+ cb.getValue(), Boolean.class, new Locale("fi", "FI"));
assertEquals(Boolean.FALSE, newDmValue);
// FIXME: Should be able to set to false here to cause datamodel to be