From: Artur Signell Date: Thu, 22 Dec 2011 21:05:21 +0000 (+0200) Subject: Test for #8191 X-Git-Tag: 7.0.0.alpha1^2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=44ee53c99397ed23b6f2acb102e1c4cc61bec71f;p=vaadin-framework.git Test for #8191 --- diff --git a/tests/testbench/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java b/tests/testbench/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java new file mode 100644 index 0000000000..b8b0c18e0f --- /dev/null +++ b/tests/testbench/com/vaadin/tests/converter/ConverterThatEnforcesAFormat.java @@ -0,0 +1,46 @@ +package com.vaadin.tests.converter; + +import com.vaadin.data.Property.ValueChangeEvent; +import com.vaadin.data.Property.ValueChangeListener; +import com.vaadin.tests.components.TestBase; +import com.vaadin.tests.util.Log; +import com.vaadin.ui.TextField; + +public class ConverterThatEnforcesAFormat extends TestBase { + + private Log log = new Log(5); + + @Override + protected void setup() { + final TextField tf = new TextField( + "This field should always be formatted with 3 digits"); + tf.setConverter(new StringToDoubleConverterWithThreeFractionDigits()); + tf.addListener(new ValueChangeListener() { + public void valueChange(ValueChangeEvent event) { + log.log("Value changed to " + + event.getProperty().getValue() + + "(converted value is " + + tf.getConvertedValue() + + "). Two-way conversion gives: " + + tf.getConverter().convertToPresentation( + tf.getConverter().convertToModel(tf.getValue(), + tf.getLocale()), tf.getLocale()) + ")"); + } + }); + tf.setImmediate(true); + addComponent(log); + addComponent(tf); + tf.setConvertedValue(50.0); + } + + @Override + protected String getDescription() { + 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"; + } + + @Override + protected Integer getTicketNumber() { + return 8191; + } + +} diff --git a/tests/testbench/com/vaadin/tests/converter/StringToDoubleConverterWithThreeFractionDigits.java b/tests/testbench/com/vaadin/tests/converter/StringToDoubleConverterWithThreeFractionDigits.java new file mode 100644 index 0000000000..f7b38633cb --- /dev/null +++ b/tests/testbench/com/vaadin/tests/converter/StringToDoubleConverterWithThreeFractionDigits.java @@ -0,0 +1,18 @@ +package com.vaadin.tests.converter; + +import java.text.NumberFormat; +import java.util.Locale; + +import com.vaadin.data.util.converter.StringToDoubleConverter; + +public class StringToDoubleConverterWithThreeFractionDigits extends StringToDoubleConverter { + + @Override + protected NumberFormat getFormat(Locale locale) { + NumberFormat format = super.getFormat(locale); + format.setGroupingUsed(false); + format.setMaximumFractionDigits(3); + format.setMinimumFractionDigits(3); + return format; + } +}