]> source.dussan.org Git - vaadin-framework.git/commitdiff
Renamed abstract base class of field value change notification tests for it to be...
authorHenri Sara <henri.sara@itmill.com>
Wed, 24 Mar 2010 07:45:36 +0000 (07:45 +0000)
committerHenri Sara <henri.sara@itmill.com>
Wed, 24 Mar 2010 07:45:36 +0000 (07:45 +0000)
svn changeset:12050/svn branch:6.3

tests/src/com/vaadin/tests/server/components/AbstractTestFieldValueChange.java [new file with mode: 0644]
tests/src/com/vaadin/tests/server/components/TestComboBoxValueChange.java
tests/src/com/vaadin/tests/server/components/TestFieldValueChange.java [deleted file]
tests/src/com/vaadin/tests/server/components/TestTextFieldValueChange.java

diff --git a/tests/src/com/vaadin/tests/server/components/AbstractTestFieldValueChange.java b/tests/src/com/vaadin/tests/server/components/AbstractTestFieldValueChange.java
new file mode 100644 (file)
index 0000000..756db0e
--- /dev/null
@@ -0,0 +1,165 @@
+package com.vaadin.tests.server.components;\r
+\r
+import junit.framework.TestCase;\r
+\r
+import org.easymock.EasyMock;\r
+\r
+import com.vaadin.data.Property.ValueChangeEvent;\r
+import com.vaadin.data.Property.ValueChangeListener;\r
+import com.vaadin.data.Property.ValueChangeNotifier;\r
+import com.vaadin.data.util.ObjectProperty;\r
+import com.vaadin.ui.AbstractField;\r
+\r
+/**\r
+ * Base class for tests for checking that value change listeners for fields are\r
+ * not called exactly once when they should be, and not at other times.\r
+ * \r
+ * Does not check all cases (e.g. properties that do not implement\r
+ * {@link ValueChangeNotifier}).\r
+ * \r
+ * Subclasses should implement {@link #setValue()} and call\r
+ * <code>super.setValue(AbstractField)</code>. Also, subclasses should typically\r
+ * override {@link #setValue(AbstractField)} to set the field value via\r
+ * <code>changeVariables()</code>.\r
+ */\r
+public abstract class AbstractTestFieldValueChange extends TestCase {\r
+\r
+    private AbstractField field;\r
+    private ValueChangeListener listener;\r
+\r
+    protected void setUp(AbstractField field) throws Exception {\r
+        this.field = field;\r
+        listener = EasyMock.createStrictMock(ValueChangeListener.class);\r
+\r
+    }\r
+\r
+    /**\r
+     * Test that listeners are not called when they have been unregistered.\r
+     */\r
+    public void testRemoveListener() {\r
+        getField().setPropertyDataSource(new ObjectProperty(""));\r
+        getField().setWriteThrough(true);\r
+        getField().setReadThrough(true);\r
+\r
+        // Expectations and start test\r
+        listener.valueChange(EasyMock.isA(ValueChangeEvent.class));\r
+        EasyMock.replay(listener);\r
+\r
+        // Add listener and set the value -> should end up in listener once\r
+        getField().addListener(listener);\r
+        setValue(getField());\r
+\r
+        // Ensure listener was called once\r
+        EasyMock.verify(listener);\r
+\r
+        // Remove the listener and set the value -> should not end up in\r
+        // listener\r
+        getField().removeListener(listener);\r
+        setValue(getField());\r
+\r
+        // Ensure listener still has been called only once\r
+        EasyMock.verify(listener);\r
+    }\r
+\r
+    /**\r
+     * Common unbuffered case: both writeThrough (auto-commit) and readThrough\r
+     * are on. Calling commit() should not cause notifications.\r
+     * \r
+     * Using the readThrough mode allows changes made to the property value to\r
+     * be seen in some cases also when there is no notification of value change\r
+     * from the property.\r
+     * \r
+     * Field value change notifications closely mirror value changes of the data\r
+     * source behind the field.\r
+     */\r
+    public void testWriteThroughReadThrough() {\r
+        getField().setPropertyDataSource(new ObjectProperty(""));\r
+        getField().setWriteThrough(true);\r
+        getField().setReadThrough(true);\r
+\r
+        expectValueChangeFromSetValueNotCommit();\r
+    }\r
+\r
+    /**\r
+     * Fully buffered use where the data source is neither read nor modified\r
+     * during editing, and is updated at commit().\r
+     * \r
+     * Field value change notifications reflect the buffered value in the field,\r
+     * not the original data source value changes.\r
+     */\r
+    public void testNoWriteThroughNoReadThrough() {\r
+        getField().setPropertyDataSource(new ObjectProperty(""));\r
+        getField().setWriteThrough(false);\r
+        getField().setReadThrough(false);\r
+\r
+        expectValueChangeFromSetValueNotCommit();\r
+    }\r
+\r
+    /**\r
+     * Less common partly buffered case: writeThrough (auto-commit) is on and\r
+     * readThrough is off. Calling commit() should not cause notifications.\r
+     * \r
+     * Without readThrough activated, changes to the data source that do not\r
+     * cause notifications are not reflected by the field value.\r
+     * \r
+     * Field value change notifications correspond to changes made to the data\r
+     * source value through the text field or the (notifying) property.\r
+     */\r
+    public void testWriteThroughNoReadThrough() {\r
+        getField().setPropertyDataSource(new ObjectProperty(""));\r
+        getField().setWriteThrough(true);\r
+        getField().setReadThrough(false);\r
+\r
+        expectValueChangeFromSetValueNotCommit();\r
+    }\r
+\r
+    /**\r
+     * Partly buffered use where the data source is read but not nor modified\r
+     * during editing, and is updated at commit().\r
+     * \r
+     * When used like this, a field is updated from the data source if necessary\r
+     * when its value is requested and the property value has changed but the\r
+     * field has not been modified in its buffer.\r
+     * \r
+     * Field value change notifications reflect the buffered value in the field,\r
+     * not the original data source value changes.\r
+     */\r
+    public void testNoWriteThroughReadThrough() {\r
+        getField().setPropertyDataSource(new ObjectProperty(""));\r
+        getField().setWriteThrough(false);\r
+        getField().setReadThrough(true);\r
+\r
+        expectValueChangeFromSetValueNotCommit();\r
+    }\r
+\r
+    protected void expectValueChangeFromSetValueNotCommit() {\r
+        // Expectations and start test\r
+        listener.valueChange(EasyMock.isA(ValueChangeEvent.class));\r
+        EasyMock.replay(listener);\r
+\r
+        // Add listener and set the value -> should end up in listener once\r
+        getField().addListener(listener);\r
+        setValue(getField());\r
+\r
+        // Ensure listener was called once\r
+        EasyMock.verify(listener);\r
+\r
+        // commit\r
+        getField().commit();\r
+\r
+        // Ensure listener was not called again\r
+        EasyMock.verify(listener);\r
+    }\r
+\r
+    protected AbstractField getField() {\r
+        return field;\r
+    }\r
+\r
+    /**\r
+     * Override in subclasses to set value with changeVariables().\r
+     */\r
+    protected void setValue(AbstractField field) {\r
+        field.setValue("newValue");\r
+    }\r
+\r
+}\r
index f104fbe800e6cd227fb16ffe8e223d31bc695f36..cb73199fb825ed04f978a41948efbf25f970b9e7 100644 (file)
@@ -12,7 +12,7 @@ import com.vaadin.ui.ComboBox;
  * \r
  * See <a href="http://dev.vaadin.com/ticket/4394">Ticket 4394</a>.\r
  */\r
-public class TestComboBoxValueChange extends TestFieldValueChange {\r
+public class TestComboBoxValueChange extends AbstractTestFieldValueChange {\r
     @Override\r
     protected void setUp() throws Exception {\r
         ComboBox combo = new ComboBox();\r
diff --git a/tests/src/com/vaadin/tests/server/components/TestFieldValueChange.java b/tests/src/com/vaadin/tests/server/components/TestFieldValueChange.java
deleted file mode 100644 (file)
index 2749f16..0000000
+++ /dev/null
@@ -1,165 +0,0 @@
-package com.vaadin.tests.server.components;\r
-\r
-import junit.framework.TestCase;\r
-\r
-import org.easymock.EasyMock;\r
-\r
-import com.vaadin.data.Property.ValueChangeEvent;\r
-import com.vaadin.data.Property.ValueChangeListener;\r
-import com.vaadin.data.Property.ValueChangeNotifier;\r
-import com.vaadin.data.util.ObjectProperty;\r
-import com.vaadin.ui.AbstractField;\r
-\r
-/**\r
- * Base class for tests for checking that value change listeners for fields are\r
- * not called exactly once when they should be, and not at other times.\r
- * \r
- * Does not check all cases (e.g. properties that do not implement\r
- * {@link ValueChangeNotifier}).\r
- * \r
- * Subclasses should implement {@link #setValue()} and call\r
- * <code>super.setValue(AbstractField)</code>. Also, subclasses should typically\r
- * override {@link #setValue(AbstractField)} to set the field value via\r
- * <code>changeVariables()</code>.\r
- */\r
-public abstract class TestFieldValueChange extends TestCase {\r
-\r
-    private AbstractField field;\r
-    private ValueChangeListener listener;\r
-\r
-    protected void setUp(AbstractField field) throws Exception {\r
-        this.field = field;\r
-        listener = EasyMock.createStrictMock(ValueChangeListener.class);\r
-\r
-    }\r
-\r
-    /**\r
-     * Test that listeners are not called when they have been unregistered.\r
-     */\r
-    public void testRemoveListener() {\r
-        getField().setPropertyDataSource(new ObjectProperty(""));\r
-        getField().setWriteThrough(true);\r
-        getField().setReadThrough(true);\r
-\r
-        // Expectations and start test\r
-        listener.valueChange(EasyMock.isA(ValueChangeEvent.class));\r
-        EasyMock.replay(listener);\r
-\r
-        // Add listener and set the value -> should end up in listener once\r
-        getField().addListener(listener);\r
-        setValue(getField());\r
-\r
-        // Ensure listener was called once\r
-        EasyMock.verify(listener);\r
-\r
-        // Remove the listener and set the value -> should not end up in\r
-        // listener\r
-        getField().removeListener(listener);\r
-        setValue(getField());\r
-\r
-        // Ensure listener still has been called only once\r
-        EasyMock.verify(listener);\r
-    }\r
-\r
-    /**\r
-     * Common unbuffered case: both writeThrough (auto-commit) and readThrough\r
-     * are on. Calling commit() should not cause notifications.\r
-     * \r
-     * Using the readThrough mode allows changes made to the property value to\r
-     * be seen in some cases also when there is no notification of value change\r
-     * from the property.\r
-     * \r
-     * Field value change notifications closely mirror value changes of the data\r
-     * source behind the field.\r
-     */\r
-    public void testWriteThroughReadThrough() {\r
-        getField().setPropertyDataSource(new ObjectProperty(""));\r
-        getField().setWriteThrough(true);\r
-        getField().setReadThrough(true);\r
-\r
-        expectValueChangeFromSetValueNotCommit();\r
-    }\r
-\r
-    /**\r
-     * Fully buffered use where the data source is neither read nor modified\r
-     * during editing, and is updated at commit().\r
-     * \r
-     * Field value change notifications reflect the buffered value in the field,\r
-     * not the original data source value changes.\r
-     */\r
-    public void testNoWriteThroughNoReadThrough() {\r
-        getField().setPropertyDataSource(new ObjectProperty(""));\r
-        getField().setWriteThrough(false);\r
-        getField().setReadThrough(false);\r
-\r
-        expectValueChangeFromSetValueNotCommit();\r
-    }\r
-\r
-    /**\r
-     * Less common partly buffered case: writeThrough (auto-commit) is on and\r
-     * readThrough is off. Calling commit() should not cause notifications.\r
-     * \r
-     * Without readThrough activated, changes to the data source that do not\r
-     * cause notifications are not reflected by the field value.\r
-     * \r
-     * Field value change notifications correspond to changes made to the data\r
-     * source value through the text field or the (notifying) property.\r
-     */\r
-    public void testWriteThroughNoReadThrough() {\r
-        getField().setPropertyDataSource(new ObjectProperty(""));\r
-        getField().setWriteThrough(true);\r
-        getField().setReadThrough(false);\r
-\r
-        expectValueChangeFromSetValueNotCommit();\r
-    }\r
-\r
-    /**\r
-     * Partly buffered use where the data source is read but not nor modified\r
-     * during editing, and is updated at commit().\r
-     * \r
-     * When used like this, a field is updated from the data source if necessary\r
-     * when its value is requested and the property value has changed but the\r
-     * field has not been modified in its buffer.\r
-     * \r
-     * Field value change notifications reflect the buffered value in the field,\r
-     * not the original data source value changes.\r
-     */\r
-    public void testNoWriteThroughReadThrough() {\r
-        getField().setPropertyDataSource(new ObjectProperty(""));\r
-        getField().setWriteThrough(false);\r
-        getField().setReadThrough(true);\r
-\r
-        expectValueChangeFromSetValueNotCommit();\r
-    }\r
-\r
-    protected void expectValueChangeFromSetValueNotCommit() {\r
-        // Expectations and start test\r
-        listener.valueChange(EasyMock.isA(ValueChangeEvent.class));\r
-        EasyMock.replay(listener);\r
-\r
-        // Add listener and set the value -> should end up in listener once\r
-        getField().addListener(listener);\r
-        setValue(getField());\r
-\r
-        // Ensure listener was called once\r
-        EasyMock.verify(listener);\r
-\r
-        // commit\r
-        getField().commit();\r
-\r
-        // Ensure listener was not called again\r
-        EasyMock.verify(listener);\r
-    }\r
-\r
-    protected AbstractField getField() {\r
-        return field;\r
-    }\r
-\r
-    /**\r
-     * Override in subclasses to set value with changeVariables().\r
-     */\r
-    protected void setValue(AbstractField field) {\r
-        field.setValue("newValue");\r
-    }\r
-\r
-}\r
index 74161a9f73e03800a1d335493433ff5920d3afce..9e50d983dc2cb6274ab3f95163b6ab9cf96d2f28 100644 (file)
@@ -12,7 +12,7 @@ import com.vaadin.ui.TextField;
  * \r
  * See <a href="http://dev.vaadin.com/ticket/4394">Ticket 4394</a>.\r
  */\r
-public class TestTextFieldValueChange extends TestFieldValueChange {\r
+public class TestTextFieldValueChange extends AbstractTestFieldValueChange {\r
 \r
     @Override\r
     protected void setUp() throws Exception {\r