]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test for #8191
authorArtur Signell <artur@vaadin.com>
Thu, 22 Dec 2011 21:05:21 +0000 (23:05 +0200)
committerArtur Signell <artur@vaadin.com>
Thu, 22 Dec 2011 21:17:38 +0000 (23:17 +0200)
tests/testbench/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java [new file with mode: 0644]
tests/testbench/com/vaadin/tests/converter/StringToDoubleConverterWithThreeFractionDigits.java [new file with mode: 0644]

diff --git a/tests/testbench/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java b/tests/testbench/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java
new file mode 100644 (file)
index 0000000..b8b0c18
--- /dev/null
@@ -0,0 +1,46 @@
+package com.vaadin.tests.converter;\r
+\r
+import com.vaadin.data.Property.ValueChangeEvent;\r
+import com.vaadin.data.Property.ValueChangeListener;\r
+import com.vaadin.tests.components.TestBase;\r
+import com.vaadin.tests.util.Log;\r
+import com.vaadin.ui.TextField;\r
+\r
+public class ConverterThatEnforcesAFormat extends TestBase {\r
+\r
+    private Log log = new Log(5);\r
+\r
+    @Override\r
+    protected void setup() {\r
+        final TextField tf = new TextField(\r
+                "This field should always be formatted with 3 digits");\r
+        tf.setConverter(new StringToDoubleConverterWithThreeFractionDigits());\r
+        tf.addListener(new ValueChangeListener() {\r
+            public void valueChange(ValueChangeEvent event) {\r
+                log.log("Value changed to "\r
+                        + event.getProperty().getValue()\r
+                        + "(converted value is "\r
+                        + tf.getConvertedValue()\r
+                        + "). Two-way conversion gives: "\r
+                        + tf.getConverter().convertToPresentation(\r
+                                tf.getConverter().convertToModel(tf.getValue(),\r
+                                        tf.getLocale()), tf.getLocale()) + ")");\r
+            }\r
+        });\r
+        tf.setImmediate(true);\r
+        addComponent(log);\r
+        addComponent(tf);\r
+        tf.setConvertedValue(50.0);\r
+    }\r
+\r
+    @Override\r
+    protected String getDescription() {\r
+        return "Entering a valid double in the field should always cause the field contents to be formatted to contain 3 digits after the decimal point";\r
+    }\r
+\r
+    @Override\r
+    protected Integer getTicketNumber() {\r
+        return 8191;\r
+    }\r
+\r
+}\r
diff --git a/tests/testbench/com/vaadin/tests/converter/StringToDoubleConverterWithThreeFractionDigits.java b/tests/testbench/com/vaadin/tests/converter/StringToDoubleConverterWithThreeFractionDigits.java
new file mode 100644 (file)
index 0000000..f7b3863
--- /dev/null
@@ -0,0 +1,18 @@
+package com.vaadin.tests.converter;\r
+\r
+import java.text.NumberFormat;\r
+import java.util.Locale;\r
+\r
+import com.vaadin.data.util.converter.StringToDoubleConverter;\r
+\r
+public class StringToDoubleConverterWithThreeFractionDigits extends StringToDoubleConverter {\r
+\r
+    @Override\r
+    protected NumberFormat getFormat(Locale locale) {\r
+        NumberFormat format = super.getFormat(locale);\r
+        format.setGroupingUsed(false);\r
+        format.setMaximumFractionDigits(3);\r
+        format.setMinimumFractionDigits(3);\r
+        return format;\r
+    }\r
+}\r