1 package com.vaadin.tests.server.component.abstractfield;
3 import junit.framework.TestCase;
5 import org.junit.Assert;
7 import com.vaadin.data.Validator.InvalidValueException;
8 import com.vaadin.data.util.MethodProperty;
9 import com.vaadin.data.util.converter.Converter.ConversionException;
10 import com.vaadin.data.util.converter.StringToIntegerConverter;
11 import com.vaadin.tests.data.bean.Address;
12 import com.vaadin.tests.data.bean.Country;
13 import com.vaadin.tests.data.bean.Person;
14 import com.vaadin.tests.data.bean.Sex;
15 import com.vaadin.ui.TextField;
17 public class AbsFieldValueConversionErrorTest extends TestCase {
19 Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com",
20 34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town",
23 public void testValidateConversionErrorParameters() {
24 TextField tf = new TextField();
25 tf.setConverter(new StringToIntegerConverter());
26 tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age"));
27 tf.setConversionError("(Type: {0}) Converter exception message: {1}");
32 } catch (InvalidValueException e) {
34 "(Type: Integer) Converter exception message: Could not convert 'abc' to java.lang.Integer",
40 public void testConvertToModelConversionErrorParameters() {
41 TextField tf = new TextField();
42 tf.setConverter(new StringToIntegerConverter());
43 tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age"));
44 tf.setConversionError("(Type: {0}) Converter exception message: {1}");
47 tf.getConvertedValue();
49 } catch (ConversionException e) {
51 "(Type: Integer) Converter exception message: Could not convert 'abc' to java.lang.Integer",
57 public void testNullConversionMessages() {
58 TextField tf = new TextField();
59 tf.setConverter(new StringToIntegerConverter());
60 tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age"));
61 tf.setConversionError(null);
66 } catch (InvalidValueException e) {
67 Assert.assertEquals(null, e.getMessage());
72 public void testDefaultConversionErrorMessage() {
73 TextField tf = new TextField();
74 tf.setConverter(new StringToIntegerConverter());
75 tf.setPropertyDataSource(new MethodProperty<String>(paulaBean, "age"));
81 } catch (InvalidValueException e) {
82 Assert.assertEquals("Could not convert value to Integer",