From 6f912b18129fe7c0f7d78407dafb472e1a75f6aa Mon Sep 17 00:00:00 2001 From: Artur Signell Date: Wed, 5 Jun 2013 13:40:38 +0300 Subject: Rename tests so they are run during build (Abstract* is ignored) Change-Id: I2f5eee8926b3ba194160b85c33176029850ca8ed --- .../abstractfield/AbsFieldValidators.java | 64 +++++ .../abstractfield/AbsFieldValueConversions.java | 260 +++++++++++++++++++++ .../abstractfield/AbstractFieldValidators.java | 64 ----- .../AbstractFieldValueConversions.java | 260 --------------------- .../vaadin/ui/AbsFieldDataSourceLocaleChange.java | 63 +++++ .../ui/AbstractFieldDataSourceLocaleChange.java | 63 ----- 6 files changed, 387 insertions(+), 387 deletions(-) create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValidators.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValidators.java delete mode 100644 server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java create mode 100644 server/tests/src/com/vaadin/ui/AbsFieldDataSourceLocaleChange.java delete mode 100644 server/tests/src/com/vaadin/ui/AbstractFieldDataSourceLocaleChange.java (limited to 'server') diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValidators.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValidators.java new file mode 100644 index 0000000000..764446f7aa --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValidators.java @@ -0,0 +1,64 @@ +package com.vaadin.tests.server.component.abstractfield; + +import junit.framework.TestCase; + +import org.easymock.EasyMock; + +import com.vaadin.data.Validator; +import com.vaadin.ui.AbstractField; +import com.vaadin.ui.Field; + +public class AbsFieldValidators extends TestCase { + + Field field = new AbstractField() { + @Override + public Class getType() { + return Object.class; + } + }; + + Validator validator = EasyMock.createMock(Validator.class); + Validator validator2 = EasyMock.createMock(Validator.class); + + public void testAddValidator() { + assertNotNull(field.getValidators()); + assertEquals(0, field.getValidators().size()); + + field.addValidator(validator); + assertEquals(1, field.getValidators().size()); + assertTrue(field.getValidators().contains(validator)); + + field.addValidator(validator2); + assertEquals(2, field.getValidators().size()); + assertTrue(field.getValidators().contains(validator)); + assertTrue(field.getValidators().contains(validator2)); + } + + public void testRemoveValidator() { + field.addValidator(validator); + field.addValidator(validator2); + + field.removeValidator(validator); + assertNotNull(field.getValidators()); + assertEquals(1, field.getValidators().size()); + assertFalse(field.getValidators().contains(validator)); + assertTrue(field.getValidators().contains(validator2)); + + field.removeValidator(validator2); + assertNotNull(field.getValidators()); + assertEquals(0, field.getValidators().size()); + assertFalse(field.getValidators().contains(validator)); + assertFalse(field.getValidators().contains(validator2)); + } + + public void testRemoveAllValidators() { + field.addValidator(validator); + field.addValidator(validator2); + + field.removeAllValidators(); + assertNotNull(field.getValidators()); + assertEquals(0, field.getValidators().size()); + assertFalse(field.getValidators().contains(validator)); + assertFalse(field.getValidators().contains(validator2)); + } +} 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 new file mode 100644 index 0000000000..b5e937f27d --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbsFieldValueConversions.java @@ -0,0 +1,260 @@ +package com.vaadin.tests.server.component.abstractfield; + +import java.util.Locale; + +import junit.framework.Assert; +import junit.framework.TestCase; + +import org.junit.Test; + +import com.vaadin.data.util.MethodProperty; +import com.vaadin.data.util.ObjectProperty; +import com.vaadin.data.util.converter.Converter; +import com.vaadin.data.util.converter.Converter.ConversionException; +import com.vaadin.data.util.converter.StringToIntegerConverter; +import com.vaadin.server.VaadinSession; +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.tests.util.AlwaysLockedVaadinSession; +import com.vaadin.ui.CheckBox; +import com.vaadin.ui.TextField; + +public class AbsFieldValueConversions extends TestCase { + + Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com", + 34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town", + Country.FINLAND)); + + /** + * Java uses a non-breaking space (ascii 160) instead of space when + * formatting + */ + private static final char FORMATTED_SPACE = 160; + + public void testWithoutConversion() { + TextField tf = new TextField(); + tf.setPropertyDataSource(new MethodProperty(paulaBean, + "firstName")); + assertEquals("Paula", tf.getValue()); + assertEquals("Paula", tf.getPropertyDataSource().getValue()); + tf.setValue("abc"); + assertEquals("abc", tf.getValue()); + assertEquals("abc", tf.getPropertyDataSource().getValue()); + assertEquals("abc", paulaBean.getFirstName()); + } + + public void testNonmodifiedBufferedFieldConversion() { + VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); + TextField tf = new TextField("salary"); + tf.setBuffered(true); + tf.setLocale(new Locale("en", "US")); + ObjectProperty ds = new ObjectProperty(123456789); + tf.setPropertyDataSource(ds); + assertEquals((Integer) 123456789, ds.getValue()); + assertEquals("123,456,789", tf.getValue()); + tf.setLocale(new Locale("fi", "FI")); + assertEquals((Integer) 123456789, ds.getValue()); + assertEquals("123" + FORMATTED_SPACE + "456" + FORMATTED_SPACE + "789", + tf.getValue()); + + } + + public void testModifiedBufferedFieldConversion() { + VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); + TextField tf = new TextField("salary"); + tf.setBuffered(true); + tf.setLocale(new Locale("en", "US")); + ObjectProperty ds = new ObjectProperty(123456789); + tf.setPropertyDataSource(ds); + assertEquals((Integer) 123456789, ds.getValue()); + assertEquals("123,456,789", tf.getValue()); + tf.setValue("123,123"); + assertEquals((Integer) 123456789, ds.getValue()); + assertEquals("123,123", tf.getValue()); + + tf.setLocale(new Locale("fi", "FI")); + assertEquals((Integer) 123456789, ds.getValue()); + // Value should not be updated when field is buffered + assertEquals("123,123", tf.getValue()); + } + + public void testStringIdentityConversion() { + TextField tf = new TextField(); + tf.setConverter(new Converter() { + + @Override + public String convertToModel(String value, Locale locale) { + return value; + } + + @Override + public String convertToPresentation(String value, Locale locale) { + return value; + } + + @Override + public Class getModelType() { + return String.class; + } + + @Override + public Class getPresentationType() { + return String.class; + } + }); + tf.setPropertyDataSource(new MethodProperty(paulaBean, + "firstName")); + assertEquals("Paula", tf.getValue()); + assertEquals("Paula", tf.getPropertyDataSource().getValue()); + tf.setValue("abc"); + assertEquals("abc", tf.getValue()); + assertEquals("abc", tf.getPropertyDataSource().getValue()); + assertEquals("abc", paulaBean.getFirstName()); + } + + public void testIntegerStringConversion() { + TextField tf = new TextField(); + + tf.setConverter(new StringToIntegerConverter()); + tf.setPropertyDataSource(new MethodProperty(paulaBean, "age")); + assertEquals(34, tf.getPropertyDataSource().getValue()); + assertEquals("34", tf.getValue()); + tf.setValue("12"); + assertEquals(12, tf.getPropertyDataSource().getValue()); + assertEquals("12", tf.getValue()); + tf.getPropertyDataSource().setValue(42); + assertEquals(42, tf.getPropertyDataSource().getValue()); + assertEquals("42", tf.getValue()); + } + + public void testChangeReadOnlyFieldLocale() { + VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); + + TextField tf = new TextField("salary"); + tf.setLocale(new Locale("en", "US")); + ObjectProperty ds = new ObjectProperty(123456789); + ds.setReadOnly(true); + tf.setPropertyDataSource(ds); + assertEquals((Integer) 123456789, ds.getValue()); + assertEquals("123,456,789", tf.getValue()); + tf.setLocale(new Locale("fi", "FI")); + assertEquals((Integer) 123456789, ds.getValue()); + assertEquals("123" + FORMATTED_SPACE + "456" + FORMATTED_SPACE + "789", + tf.getValue()); + } + + public void testBooleanNullConversion() { + CheckBox cb = new CheckBox(); + cb.setConverter(new Converter() { + + @Override + public Boolean convertToModel(Boolean value, 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); + return value; + } + + @Override + public Boolean convertToPresentation(Boolean value, Locale locale) { + // Datamodel -> field + if (value == null) { + return false; + } + + return value; + } + + @Override + public Class getModelType() { + return Boolean.class; + } + + @Override + public Class getPresentationType() { + return Boolean.class; + } + + }); + MethodProperty property = new MethodProperty( + paulaBean, "deceased"); + cb.setPropertyDataSource(property); + assertEquals(Boolean.FALSE, property.getValue()); + assertEquals(Boolean.FALSE, cb.getValue()); + Boolean newDmValue = cb.getConverter().convertToPresentation( + cb.getValue(), new Locale("fi", "FI")); + assertEquals(Boolean.FALSE, newDmValue); + + // FIXME: Should be able to set to false here to cause datamodel to be + // set to false but the change will not be propagated to the Property + // (field value is already false) + + cb.setValue(true); + assertEquals(Boolean.TRUE, cb.getValue()); + assertEquals(Boolean.TRUE, property.getValue()); + + cb.setValue(false); + assertEquals(Boolean.FALSE, cb.getValue()); + assertEquals(Boolean.FALSE, property.getValue()); + + } + + public static class NumberBean { + private Number number; + + public Number getNumber() { + return number; + } + + public void setNumber(Number number) { + this.number = number; + } + + } + + public void testNumberDoubleConverterChange() { + final VaadinSession a = new AlwaysLockedVaadinSession(null); + VaadinSession.setCurrent(a); + TextField tf = new TextField() { + @Override + public VaadinSession getSession() { + return a; + } + }; + NumberBean nb = new NumberBean(); + nb.setNumber(490); + + tf.setPropertyDataSource(new MethodProperty(nb, "number")); + assertEquals(490, tf.getPropertyDataSource().getValue()); + assertEquals("490", tf.getValue()); + + Converter c1 = tf.getConverter(); + + tf.setPropertyDataSource(new MethodProperty(nb, "number")); + Converter c2 = tf.getConverter(); + assertTrue( + "StringToNumber converter is ok for integer types and should stay even though property is changed", + c1 == c2); + assertEquals(490, tf.getPropertyDataSource().getValue()); + assertEquals("490", tf.getValue()); + + } + + @Test + public void testNullConverter() { + TextField tf = new TextField("foo"); + tf.setPropertyDataSource(new ObjectProperty(12)); + tf.setConverter((Converter) null); + try { + Object v = tf.getConvertedValue(); + System.out.println(v); + Assert.fail("Trying to convert String -> Integer should fail when there is no converter"); + } catch (ConversionException e) { + // ok, should happen when there is no converter but conversion is + // needed + } + } + +} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValidators.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValidators.java deleted file mode 100644 index 19c58fe6d3..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValidators.java +++ /dev/null @@ -1,64 +0,0 @@ -package com.vaadin.tests.server.component.abstractfield; - -import junit.framework.TestCase; - -import org.easymock.EasyMock; - -import com.vaadin.data.Validator; -import com.vaadin.ui.AbstractField; -import com.vaadin.ui.Field; - -public class AbstractFieldValidators extends TestCase { - - Field field = new AbstractField() { - @Override - public Class getType() { - return Object.class; - } - }; - - Validator validator = EasyMock.createMock(Validator.class); - Validator validator2 = EasyMock.createMock(Validator.class); - - public void testAddValidator() { - assertNotNull(field.getValidators()); - assertEquals(0, field.getValidators().size()); - - field.addValidator(validator); - assertEquals(1, field.getValidators().size()); - assertTrue(field.getValidators().contains(validator)); - - field.addValidator(validator2); - assertEquals(2, field.getValidators().size()); - assertTrue(field.getValidators().contains(validator)); - assertTrue(field.getValidators().contains(validator2)); - } - - public void testRemoveValidator() { - field.addValidator(validator); - field.addValidator(validator2); - - field.removeValidator(validator); - assertNotNull(field.getValidators()); - assertEquals(1, field.getValidators().size()); - assertFalse(field.getValidators().contains(validator)); - assertTrue(field.getValidators().contains(validator2)); - - field.removeValidator(validator2); - assertNotNull(field.getValidators()); - assertEquals(0, field.getValidators().size()); - assertFalse(field.getValidators().contains(validator)); - assertFalse(field.getValidators().contains(validator2)); - } - - public void testRemoveAllValidators() { - field.addValidator(validator); - field.addValidator(validator2); - - field.removeAllValidators(); - assertNotNull(field.getValidators()); - assertEquals(0, field.getValidators().size()); - assertFalse(field.getValidators().contains(validator)); - assertFalse(field.getValidators().contains(validator2)); - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java b/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java deleted file mode 100644 index 3c4d43543b..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/abstractfield/AbstractFieldValueConversions.java +++ /dev/null @@ -1,260 +0,0 @@ -package com.vaadin.tests.server.component.abstractfield; - -import java.util.Locale; - -import junit.framework.Assert; -import junit.framework.TestCase; - -import org.junit.Test; - -import com.vaadin.data.util.MethodProperty; -import com.vaadin.data.util.ObjectProperty; -import com.vaadin.data.util.converter.Converter; -import com.vaadin.data.util.converter.Converter.ConversionException; -import com.vaadin.data.util.converter.StringToIntegerConverter; -import com.vaadin.server.VaadinSession; -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.tests.util.AlwaysLockedVaadinSession; -import com.vaadin.ui.CheckBox; -import com.vaadin.ui.TextField; - -public class AbstractFieldValueConversions extends TestCase { - - Person paulaBean = new Person("Paula", "Brilliant", "paula@brilliant.com", - 34, Sex.FEMALE, new Address("Paula street 1", 12345, "P-town", - Country.FINLAND)); - - /** - * Java uses a non-breaking space (ascii 160) instead of space when - * formatting - */ - private static final char FORMATTED_SPACE = 160; - - public void testWithoutConversion() { - TextField tf = new TextField(); - tf.setPropertyDataSource(new MethodProperty(paulaBean, - "firstName")); - assertEquals("Paula", tf.getValue()); - assertEquals("Paula", tf.getPropertyDataSource().getValue()); - tf.setValue("abc"); - assertEquals("abc", tf.getValue()); - assertEquals("abc", tf.getPropertyDataSource().getValue()); - assertEquals("abc", paulaBean.getFirstName()); - } - - public void testNonmodifiedBufferedFieldConversion() { - VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); - TextField tf = new TextField("salary"); - tf.setBuffered(true); - tf.setLocale(new Locale("en", "US")); - ObjectProperty ds = new ObjectProperty(123456789); - tf.setPropertyDataSource(ds); - assertEquals((Integer) 123456789, ds.getValue()); - assertEquals("123,456,789", tf.getValue()); - tf.setLocale(new Locale("fi", "FI")); - assertEquals((Integer) 123456789, ds.getValue()); - assertEquals("123" + FORMATTED_SPACE + "456" + FORMATTED_SPACE + "789", - tf.getValue()); - - } - - public void testModifiedBufferedFieldConversion() { - VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); - TextField tf = new TextField("salary"); - tf.setBuffered(true); - tf.setLocale(new Locale("en", "US")); - ObjectProperty ds = new ObjectProperty(123456789); - tf.setPropertyDataSource(ds); - assertEquals((Integer) 123456789, ds.getValue()); - assertEquals("123,456,789", tf.getValue()); - tf.setValue("123,123"); - assertEquals((Integer) 123456789, ds.getValue()); - assertEquals("123,123", tf.getValue()); - - tf.setLocale(new Locale("fi", "FI")); - assertEquals((Integer) 123456789, ds.getValue()); - // Value should not be updated when field is buffered - assertEquals("123,123", tf.getValue()); - } - - public void testStringIdentityConversion() { - TextField tf = new TextField(); - tf.setConverter(new Converter() { - - @Override - public String convertToModel(String value, Locale locale) { - return value; - } - - @Override - public String convertToPresentation(String value, Locale locale) { - return value; - } - - @Override - public Class getModelType() { - return String.class; - } - - @Override - public Class getPresentationType() { - return String.class; - } - }); - tf.setPropertyDataSource(new MethodProperty(paulaBean, - "firstName")); - assertEquals("Paula", tf.getValue()); - assertEquals("Paula", tf.getPropertyDataSource().getValue()); - tf.setValue("abc"); - assertEquals("abc", tf.getValue()); - assertEquals("abc", tf.getPropertyDataSource().getValue()); - assertEquals("abc", paulaBean.getFirstName()); - } - - public void testIntegerStringConversion() { - TextField tf = new TextField(); - - tf.setConverter(new StringToIntegerConverter()); - tf.setPropertyDataSource(new MethodProperty(paulaBean, "age")); - assertEquals(34, tf.getPropertyDataSource().getValue()); - assertEquals("34", tf.getValue()); - tf.setValue("12"); - assertEquals(12, tf.getPropertyDataSource().getValue()); - assertEquals("12", tf.getValue()); - tf.getPropertyDataSource().setValue(42); - assertEquals(42, tf.getPropertyDataSource().getValue()); - assertEquals("42", tf.getValue()); - } - - public void testChangeReadOnlyFieldLocale() { - VaadinSession.setCurrent(new AlwaysLockedVaadinSession(null)); - - TextField tf = new TextField("salary"); - tf.setLocale(new Locale("en", "US")); - ObjectProperty ds = new ObjectProperty(123456789); - ds.setReadOnly(true); - tf.setPropertyDataSource(ds); - assertEquals((Integer) 123456789, ds.getValue()); - assertEquals("123,456,789", tf.getValue()); - tf.setLocale(new Locale("fi", "FI")); - assertEquals((Integer) 123456789, ds.getValue()); - assertEquals("123" + FORMATTED_SPACE + "456" + FORMATTED_SPACE + "789", - tf.getValue()); - } - - public void testBooleanNullConversion() { - CheckBox cb = new CheckBox(); - cb.setConverter(new Converter() { - - @Override - public Boolean convertToModel(Boolean value, 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); - return value; - } - - @Override - public Boolean convertToPresentation(Boolean value, Locale locale) { - // Datamodel -> field - if (value == null) { - return false; - } - - return value; - } - - @Override - public Class getModelType() { - return Boolean.class; - } - - @Override - public Class getPresentationType() { - return Boolean.class; - } - - }); - MethodProperty property = new MethodProperty( - paulaBean, "deceased"); - cb.setPropertyDataSource(property); - assertEquals(Boolean.FALSE, property.getValue()); - assertEquals(Boolean.FALSE, cb.getValue()); - Boolean newDmValue = cb.getConverter().convertToPresentation( - cb.getValue(), new Locale("fi", "FI")); - assertEquals(Boolean.FALSE, newDmValue); - - // FIXME: Should be able to set to false here to cause datamodel to be - // set to false but the change will not be propagated to the Property - // (field value is already false) - - cb.setValue(true); - assertEquals(Boolean.TRUE, cb.getValue()); - assertEquals(Boolean.TRUE, property.getValue()); - - cb.setValue(false); - assertEquals(Boolean.FALSE, cb.getValue()); - assertEquals(Boolean.FALSE, property.getValue()); - - } - - public static class NumberBean { - private Number number; - - public Number getNumber() { - return number; - } - - public void setNumber(Number number) { - this.number = number; - } - - } - - public void testNumberDoubleConverterChange() { - final VaadinSession a = new AlwaysLockedVaadinSession(null); - VaadinSession.setCurrent(a); - TextField tf = new TextField() { - @Override - public VaadinSession getSession() { - return a; - } - }; - NumberBean nb = new NumberBean(); - nb.setNumber(490); - - tf.setPropertyDataSource(new MethodProperty(nb, "number")); - assertEquals(490, tf.getPropertyDataSource().getValue()); - assertEquals("490", tf.getValue()); - - Converter c1 = tf.getConverter(); - - tf.setPropertyDataSource(new MethodProperty(nb, "number")); - Converter c2 = tf.getConverter(); - assertTrue( - "StringToNumber converter is ok for integer types and should stay even though property is changed", - c1 == c2); - assertEquals(490, tf.getPropertyDataSource().getValue()); - assertEquals("490", tf.getValue()); - - } - - @Test - public void testNullConverter() { - TextField tf = new TextField("foo"); - tf.setPropertyDataSource(new ObjectProperty(12)); - tf.setConverter((Converter) null); - try { - Object v = tf.getConvertedValue(); - System.out.println(v); - Assert.fail("Trying to convert String -> Integer should fail when there is no converter"); - } catch (ConversionException e) { - // ok, should happen when there is no converter but conversion is - // needed - } - } - -} diff --git a/server/tests/src/com/vaadin/ui/AbsFieldDataSourceLocaleChange.java b/server/tests/src/com/vaadin/ui/AbsFieldDataSourceLocaleChange.java new file mode 100644 index 0000000000..acea0a84c7 --- /dev/null +++ b/server/tests/src/com/vaadin/ui/AbsFieldDataSourceLocaleChange.java @@ -0,0 +1,63 @@ +package com.vaadin.ui; + +import java.text.NumberFormat; +import java.util.Locale; + +import junit.framework.Assert; + +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.data.util.converter.StringToIntegerConverter; +import com.vaadin.server.VaadinRequest; +import com.vaadin.server.VaadinSession; + +public class AbsFieldDataSourceLocaleChange { + + private VaadinSession vaadinSession; + private UI ui; + + @Before + public void setup() { + vaadinSession = new VaadinSession(null); + VaadinSession.setCurrent(vaadinSession); + ui = new UI() { + + @Override + protected void init(VaadinRequest request) { + + } + }; + ui.setSession(vaadinSession); + UI.setCurrent(ui); + } + + @Test + public void localeChangesOnAttach() { + TextField tf = new TextField(); + + ; + tf.setConverter(new StringToIntegerConverter() { + @Override + protected NumberFormat getFormat(Locale locale) { + if (locale == null) { + NumberFormat format = super.getFormat(locale); + format.setGroupingUsed(false); + format.setMinimumIntegerDigits(10); + return format; + } + return super.getFormat(locale); + } + }); + tf.setImmediate(true); + tf.setConvertedValue(10000); + Assert.assertEquals("0000010000", tf.getValue()); + + VerticalLayout vl = new VerticalLayout(); + ui.setContent(vl); + ui.setLocale(new Locale("en", "US")); + + vl.addComponent(tf); + Assert.assertEquals("10,000", tf.getValue()); + } +} diff --git a/server/tests/src/com/vaadin/ui/AbstractFieldDataSourceLocaleChange.java b/server/tests/src/com/vaadin/ui/AbstractFieldDataSourceLocaleChange.java deleted file mode 100644 index 9810873f0b..0000000000 --- a/server/tests/src/com/vaadin/ui/AbstractFieldDataSourceLocaleChange.java +++ /dev/null @@ -1,63 +0,0 @@ -package com.vaadin.ui; - -import java.text.NumberFormat; -import java.util.Locale; - -import junit.framework.Assert; - -import org.junit.Before; -import org.junit.Test; - -import com.vaadin.data.util.converter.StringToIntegerConverter; -import com.vaadin.server.VaadinRequest; -import com.vaadin.server.VaadinSession; - -public class AbstractFieldDataSourceLocaleChange { - - private VaadinSession vaadinSession; - private UI ui; - - @Before - public void setup() { - vaadinSession = new VaadinSession(null); - VaadinSession.setCurrent(vaadinSession); - ui = new UI() { - - @Override - protected void init(VaadinRequest request) { - - } - }; - ui.setSession(vaadinSession); - UI.setCurrent(ui); - } - - @Test - public void localeChangesOnAttach() { - TextField tf = new TextField(); - - ; - tf.setConverter(new StringToIntegerConverter() { - @Override - protected NumberFormat getFormat(Locale locale) { - if (locale == null) { - NumberFormat format = super.getFormat(locale); - format.setGroupingUsed(false); - format.setMinimumIntegerDigits(10); - return format; - } - return super.getFormat(locale); - } - }); - tf.setImmediate(true); - tf.setConvertedValue(10000); - Assert.assertEquals("0000010000", tf.getValue()); - - VerticalLayout vl = new VerticalLayout(); - ui.setContent(vl); - ui.setLocale(new Locale("en", "US")); - - vl.addComponent(tf); - Assert.assertEquals("10,000", tf.getValue()); - } -} -- cgit v1.2.3