summaryrefslogtreecommitdiffstats
path: root/server/tests
diff options
context:
space:
mode:
authorArtur Signell <artur@vaadin.com>2013-05-31 09:56:58 +0300
committerVaadin Code Review <review@vaadin.com>2013-06-07 06:32:15 +0000
commit1b0a214100e6270abea8b9f415a0873de88aab95 (patch)
treeeddf7b4c64b0b0abeb53cf6d2681485d6da263e0 /server/tests
parent9efd4d676c1c68638cfdb6d70db076761f86c6fc (diff)
downloadvaadin-framework-1b0a214100e6270abea8b9f415a0873de88aab95.tar.gz
vaadin-framework-1b0a214100e6270abea8b9f415a0873de88aab95.zip
Pass ConversionException to getConversionError (#11960)
Change-Id: I6a25c4e4bfd9fe73f973670583c708503f77f60a
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java72
1 files changed, 72 insertions, 0 deletions
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java
new file mode 100644
index 0000000000..ad762f8931
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversionError.java
@@ -0,0 +1,72 @@
+package com.vaadin.tests.server.component.abstractfield;
+
+import junit.framework.TestCase;
+
+import org.junit.Assert;
+
+import com.vaadin.data.Validator.InvalidValueException;
+import com.vaadin.data.util.MethodProperty;
+import com.vaadin.data.util.converter.Converter.ConversionException;
+import com.vaadin.data.util.converter.StringToIntegerConverter;
+import com.vaadin.tests.data.bean.Address;
+import com.vaadin.tests.data.bean.Country;
+import com.vaadin.tests.data.bean.Person;
+import com.vaadin.tests.data.bean.Sex;
+import com.vaadin.ui.TextField;
+
+public class AbsFieldValueConversionError extends TestCase {
+
+ Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com",
+ 34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town",
+ Country.FINLAND));
+
+ public void testValidateConversionErrorParameters() {
+ TextField tf = new TextField();
+ tf.setConverter(new StringToIntegerConverter());
+ tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age"));
+ tf.setConversionError("(Type: {0}) Converter exception message: {1}");
+ tf.setValue("abc");
+ try {
+ tf.validate();
+ fail();
+ } catch (InvalidValueException e) {
+ Assert.assertEquals(
+ "(Type: Integer) Converter exception message: Could not convert 'abc' to java.lang.Integer",
+ e.getMessage());
+ }
+
+ }
+
+ public void testConvertToModelConversionErrorParameters() {
+ TextField tf = new TextField();
+ tf.setConverter(new StringToIntegerConverter());
+ tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age"));
+ tf.setConversionError("(Type: {0}) Converter exception message: {1}");
+ tf.setValue("abc");
+ try {
+ tf.getConvertedValue();
+ fail();
+ } catch (ConversionException e) {
+ Assert.assertEquals(
+ "(Type: Integer) Converter exception message: Could not convert 'abc' to java.lang.Integer",
+ e.getMessage());
+ }
+
+ }
+
+ public void testDefaultConversionErrorMessage() {
+ TextField tf = new TextField();
+ tf.setConverter(new StringToIntegerConverter());
+ tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age"));
+ tf.setValue("abc");
+
+ try {
+ tf.validate();
+ fail();
+ } catch (InvalidValueException e) {
+ Assert.assertEquals("Could not convert value to Integer",
+ e.getMessage());
+ }
+
+ }
+}