Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java')
-rw-r--r--common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java142
1 files changed, 54 insertions, 88 deletions
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
index 73a410eec3..a61fc26776 100644
--- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
+++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/DoubleModifiablePropertyValueModelTests.java
@@ -9,8 +9,9 @@
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.model.value;
-import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
+import org.eclipse.jpt.common.utility.internal.closure.ClosureAdapter;
import org.eclipse.jpt.common.utility.internal.model.value.PropertyValueModelTools;
+import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel;
import org.eclipse.jpt.common.utility.model.value.PropertyValueModel;
@@ -23,102 +24,67 @@ public class DoubleModifiablePropertyValueModelTests
}
@Override
- protected PropertyValueModel<String> buildDoubleModel(ModifiablePropertyValueModel<ModifiablePropertyValueModel<String>> modelModel) {
+ protected ModifiablePropertyValueModel<String> buildTestModel(PropertyValueModel<SimplePropertyValueModel<String>> modelModel) {
return PropertyValueModelTools.doubleWrapModifiable(modelModel);
}
- protected ModifiablePropertyValueModel<String> getDoubleModel() {
- return (ModifiablePropertyValueModel<String>) this.doubleModel;
- }
-
- public void testSetValue() {
- assertEquals("foo", this.stringModel.getValue());
- assertEquals(this.stringModel, this.stringModelModel.getValue());
- assertNull(this.doubleModel.getValue());
- this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
- assertEquals("foo", this.doubleModel.getValue());
-
- this.getDoubleModel().setValue("bar");
- assertEquals("bar", this.stringModel.getValue());
- assertEquals("bar", this.doubleModel.getValue());
-
- this.stringModelModel.setValue(null);
- assertNull(this.doubleModel.getValue());
- boolean exCaught = false;
- try {
- this.getDoubleModel().setValue("TTT"); // unsupported?
- } catch (IllegalStateException ex) {
- exCaught = true;
+ public class SetClosure
+ extends ClosureAdapter<String>
+ {
+ @Override
+ public void execute(String argument) {
+ String key = DoubleModifiablePropertyValueModelTests.this.keyModel.getValue();
+ DoubleModifiablePropertyValueModelTests.this.getValueModel(key).setValue(argument);
}
- assertTrue(exCaught);
- assertEquals("bar", this.stringModel.getValue());
- assertNull(this.doubleModel.getValue());
}
- public void testPropertyChange3() {
- this.stringModel.addChangeListener(this.stringModelListener);
- this.stringModelModel.addChangeListener(this.stringModelModelListener);
- this.doubleModel.addChangeListener(this.doubleModelListener);
- this.verifyPropertyChanges2();
+ protected ModifiablePropertyValueModel<String> getTestModel() {
+ return (ModifiablePropertyValueModel<String>) this.testModel;
}
- public void testPropertyChange4() {
- this.stringModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelListener);
- this.stringModelModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.stringModelModelListener);
- this.doubleModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.doubleModelListener);
- this.verifyPropertyChanges2();
+ public void testSetValue() {
+ assertNull(this.keyModel.getValue());
+ assertNull(this.valueModelModel.getValue());
+ assertNull(this.testModel.getValue());
+
+ this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.testModelListener);
+
+ assertNull(this.keyModel.getValue());
+ assertNull(this.valueModelModel.getValue());
+ assertNull(this.testModel.getValue());
+
+ this.keyModel.setValue("foo");
+ assertEquals("foo", this.keyModel.getValue());
+ assertEquals(this.valueModels.get("foo"), this.valueModelModel.getValue());
+ assertEquals("foofoo", this.testModel.getValue());
+
+ this.getTestModel().setValue("bar");
+ assertEquals("foo", this.keyModel.getValue());
+ assertEquals(this.valueModels.get("foo"), this.valueModelModel.getValue());
+ assertEquals("bar", this.testModel.getValue());
+
+ this.getTestModel().setValue(null);
+ assertEquals("foo", this.keyModel.getValue());
+ assertEquals(this.valueModels.get("foo"), this.valueModelModel.getValue());
+ assertNull(this.testModel.getValue());
}
- protected void verifyPropertyChanges2() {
- this.stringModelEvent = null;
- this.stringModelModelEvent = null;
- this.doubleModelEvent = null;
- this.getDoubleModel().setValue("bar");
- this.verifyEvent(this.stringModelEvent, this.stringModel, "foo", "bar");
- assertNull(this.stringModelModelEvent);
- this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "bar");
-
- this.stringModelEvent = null;
- this.stringModelModelEvent = null;
- this.doubleModelEvent = null;
- this.getDoubleModel().setValue(null);
- this.verifyEvent(this.stringModelEvent, this.stringModel, "bar", null);
- assertNull(this.stringModelModelEvent);
- this.verifyEvent(this.doubleModelEvent, this.doubleModel, "bar", null);
-
- this.stringModelEvent = null;
- this.stringModelModelEvent = null;
- this.doubleModelEvent = null;
- this.getDoubleModel().setValue("foo");
- this.verifyEvent(this.stringModelEvent, this.stringModel, null, "foo");
- assertNull(this.stringModelModelEvent);
- this.verifyEvent(this.doubleModelEvent, this.doubleModel, null, "foo");
-
- this.stringModelEvent = null;
- this.stringModelModelEvent = null;
- this.doubleModelEvent = null;
- ModifiablePropertyValueModel<String> stringModel2 = new SimplePropertyValueModel<>("TTT");
- this.stringModelModel.setValue(stringModel2);
- assertNull(this.stringModelEvent);
- this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, this.stringModel, stringModel2);
- this.verifyEvent(this.doubleModelEvent, this.doubleModel, "foo", "TTT");
-
- this.stringModelEvent = null;
- this.stringModelModelEvent = null;
- this.doubleModelEvent = null;
- this.getDoubleModel().setValue("XXX");
- assertNull(this.stringModelEvent);
- assertNull(this.stringModelModelEvent);
- this.verifyEvent(this.doubleModelEvent, this.doubleModel, "TTT", "XXX");
- assertEquals("foo", this.stringModel.getValue());
- assertEquals("XXX", stringModel2.getValue());
-
- this.stringModelEvent = null;
- this.stringModelModelEvent = null;
- this.doubleModelEvent = null;
- this.stringModelModel.setValue(this.stringModel);
- assertNull(this.stringModelEvent);
- this.verifyEvent(this.stringModelModelEvent, this.stringModelModel, stringModel2, this.stringModel);
- this.verifyEvent(this.doubleModelEvent, this.doubleModel, "XXX", "foo");
+ public void testPropertyChange_directSet() {
+ this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.testModelListener);
+
+ this.keyModel.setValue("foo");
+ this.verifyEvent(this.testModelEvent, this.testModel, null, "foofoo");
+
+ this.testModelEvent = null;
+ this.getTestModel().setValue("bar");
+ this.verifyEvent(this.testModelEvent, this.testModel, "foofoo", "bar");
+
+ this.testModelEvent = null;
+ this.getTestModel().setValue(null);
+ this.verifyEvent(this.testModelEvent, this.testModel, "bar", null);
+
+ this.testModelEvent = null;
+ this.getTestModel().setValue("foo");
+ this.verifyEvent(this.testModelEvent, this.testModel, null, "foo");
}
}

Back to the top