diff options
author | Brian Vosburgh | 2016-06-27 19:46:25 +0000 |
---|---|---|
committer | Brian Vosburgh | 2017-05-18 22:37:24 +0000 |
commit | 0a077f35ef9ff55fe1baa5c9928445fe79251ded (patch) | |
tree | 2ff603b1fc8272baf0b8eca980abc1ac8c1463da /common/tests | |
parent | 8077ad16826b0a6769ede4af962a67fa4c669f85 (diff) | |
download | webtools.dali-0a077f35ef9ff55fe1baa5c9928445fe79251ded.tar.gz webtools.dali-0a077f35ef9ff55fe1baa5c9928445fe79251ded.tar.xz webtools.dali-0a077f35ef9ff55fe1baa5c9928445fe79251ded.zip |
remove NullCheckPVMWrapper, PredicatePVM, FilteringPVM
Diffstat (limited to 'common/tests')
5 files changed, 469 insertions, 158 deletions
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java index 3d3e6ce9fa..44eb7e895d 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2013 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -9,9 +9,8 @@ ******************************************************************************/ package org.eclipse.jpt.common.utility.tests.internal.model.value; -import junit.framework.TestCase; import org.eclipse.jpt.common.utility.internal.model.AbstractModel; -import org.eclipse.jpt.common.utility.internal.model.value.FilteringModifiablePropertyValueModel; +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.internal.predicate.PredicateAdapter; import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; @@ -21,14 +20,17 @@ import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; import org.eclipse.jpt.common.utility.predicate.Predicate; import org.eclipse.jpt.common.utility.tests.internal.TestTools; +import junit.framework.TestCase; @SuppressWarnings("nls") -public class FilteringPropertyValueModelTests extends TestCase { - private ModifiablePropertyValueModel<String> objectHolder; - PropertyChangeEvent event; +public class FilteringPropertyValueModelTests + extends TestCase +{ + private ModifiablePropertyValueModel<String> innerModel; + PropertyChangeEvent innerModelEvent; - private ModifiablePropertyValueModel<String> filteredObjectHolder; - PropertyChangeEvent filteredEvent; + private ModifiablePropertyValueModel<String> filteredModel; + PropertyChangeEvent filteredModelEvent; public FilteringPropertyValueModelTests(String name) { super(name); @@ -37,8 +39,9 @@ public class FilteringPropertyValueModelTests extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - this.objectHolder = new SimplePropertyValueModel<String>("foo"); - this.filteredObjectHolder = new FilteringModifiablePropertyValueModel<String>(this.objectHolder, this.buildGetFilter(), this.buildSetFilter()); + this.innerModel = new SimplePropertyValueModel<>("foo"); + this.filteredModel = PropertyValueModelTools.filterModifiable(this.innerModel, this.buildGetFilter(), this.buildSetFilter()); +// this.filteredModel = new FilteringModifiablePropertyValueModel<>(this.innerModel, this.buildGetFilter(), this.buildSetFilter()); } private Predicate<String> buildGetFilter() { @@ -65,115 +68,165 @@ public class FilteringPropertyValueModelTests extends TestCase { } public void testValue() { - assertEquals("foo", this.objectHolder.getValue()); - assertNull(this.filteredObjectHolder.getValue()); - - this.objectHolder.setValue("bar"); - assertEquals("bar", this.objectHolder.getValue()); - assertNotNull(this.filteredObjectHolder.getValue()); - assertEquals("bar", this.filteredObjectHolder.getValue()); - - this.objectHolder.setValue("baz"); - assertEquals("baz", this.objectHolder.getValue()); - assertNotNull(this.filteredObjectHolder.getValue()); - assertEquals("baz", this.filteredObjectHolder.getValue()); - - this.objectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.filteredObjectHolder.getValue()); - - this.objectHolder.setValue("foo"); - assertEquals("foo", this.objectHolder.getValue()); - assertNull(this.filteredObjectHolder.getValue()); + assertEquals("foo", this.innerModel.getValue()); + assertNull(this.filteredModel.getValue()); + + ChangeListener innerListener = this.buildInnerListener(); + this.innerModel.addChangeListener(innerListener); + ChangeListener filteredListener = this.buildFilteredListener(); + this.filteredModel.addChangeListener(filteredListener); + + assertEquals("foo", this.innerModel.getValue()); + assertNull(this.filteredModel.getValue()); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue("bar"); + assertEquals("bar", this.innerModel.getValue()); + assertEquals("bar", this.innerModelEvent.getNewValue()); + assertNotNull(this.filteredModel.getValue()); + assertEquals("bar", this.filteredModel.getValue()); + assertEquals("bar", this.filteredModelEvent.getNewValue()); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue("baz"); + assertEquals("baz", this.innerModel.getValue()); + assertEquals("baz", this.innerModelEvent.getNewValue()); + assertNotNull(this.filteredModel.getValue()); + assertEquals("baz", this.filteredModel.getValue()); + assertEquals("baz", this.filteredModelEvent.getNewValue()); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue(null); + assertNull(this.innerModel.getValue()); + assertNull(this.innerModelEvent.getNewValue()); + assertNull(this.filteredModel.getValue()); + assertNull(this.filteredModelEvent.getNewValue()); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue("foo"); + assertEquals("foo", this.innerModel.getValue()); + assertEquals("foo", this.innerModelEvent.getNewValue()); + assertNull(this.filteredModel.getValue()); + assertNull(this.filteredModelEvent); } public void testSetValue() { - this.filteredObjectHolder.setValue("bar"); - assertEquals("bar", this.objectHolder.getValue()); - assertEquals("bar", this.filteredObjectHolder.getValue()); - - this.filteredObjectHolder.setValue("foo"); - assertEquals("bar", this.objectHolder.getValue()); - assertEquals("bar", this.filteredObjectHolder.getValue()); - - this.filteredObjectHolder.setValue(null); - assertEquals("bar", this.objectHolder.getValue()); - assertEquals("bar", this.filteredObjectHolder.getValue()); - - this.filteredObjectHolder.setValue("baz"); - assertEquals("baz", this.objectHolder.getValue()); - assertEquals("baz", this.filteredObjectHolder.getValue()); + assertEquals("foo", this.innerModel.getValue()); + assertNull(this.filteredModel.getValue()); + + ChangeListener innerListener = this.buildInnerListener(); + this.innerModel.addChangeListener(innerListener); + ChangeListener filteredListener = this.buildFilteredListener(); + this.filteredModel.addChangeListener(filteredListener); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.filteredModel.setValue("bar"); + assertEquals("bar", this.innerModel.getValue()); + assertEquals("bar", this.innerModelEvent.getNewValue()); + assertEquals("bar", this.filteredModel.getValue()); + assertEquals("bar", this.filteredModelEvent.getNewValue()); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.filteredModel.setValue("foo"); + assertNull(this.innerModel.getValue()); + assertNull(this.innerModelEvent.getNewValue()); + assertNull(this.filteredModel.getValue()); + assertNull(this.filteredModelEvent.getNewValue()); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.filteredModel.setValue(null); + assertNull(this.innerModel.getValue()); + assertNull(this.innerModelEvent); + assertNull(this.filteredModel.getValue()); + assertNull(this.filteredModelEvent); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.filteredModel.setValue("baz"); + assertEquals("baz", this.innerModel.getValue()); + assertEquals("baz", this.innerModelEvent.getNewValue()); + assertEquals("baz", this.filteredModel.getValue()); + assertEquals("baz", this.filteredModelEvent.getNewValue()); } public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + assertTrue(((AbstractModel) this.innerModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); ChangeListener listener = this.buildFilteredListener(); - this.filteredObjectHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.filteredObjectHolder.removeChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.filteredObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.filteredObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + this.filteredModel.addChangeListener(listener); + assertTrue(((AbstractModel) this.innerModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.filteredModel.removeChangeListener(listener); + assertTrue(((AbstractModel) this.innerModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + + this.filteredModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.innerModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.filteredModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.innerModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); } public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildListener()); - this.filteredObjectHolder.addChangeListener(this.buildFilteredListener()); + this.innerModel.addChangeListener(this.buildInnerListener()); + this.filteredModel.addChangeListener(this.buildFilteredListener()); this.verifyPropertyChanges(); } public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.filteredObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildFilteredListener()); + this.innerModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildInnerListener()); + this.filteredModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildFilteredListener()); this.verifyPropertyChanges(); } private void verifyPropertyChanges() { - this.event = null; - this.filteredEvent = null; - this.objectHolder.setValue("bar"); - this.verifyEvent(this.event, this.objectHolder, "foo", "bar"); - this.verifyEvent(this.filteredEvent, this.filteredObjectHolder, null, "bar"); - - this.event = null; - this.filteredEvent = null; - this.objectHolder.setValue("baz"); - this.verifyEvent(this.event, this.objectHolder, "bar", "baz"); - this.verifyEvent(this.filteredEvent, this.filteredObjectHolder, "bar", "baz"); - - this.event = null; - this.filteredEvent = null; - this.objectHolder.setValue("foo"); - this.verifyEvent(this.event, this.objectHolder, "baz", "foo"); - this.verifyEvent(this.filteredEvent, this.filteredObjectHolder, "baz", null); - - this.event = null; - this.filteredEvent = null; - this.objectHolder.setValue("fop"); - this.verifyEvent(this.event, this.objectHolder, "foo", "fop"); - assertNull(this.filteredEvent); - - this.event = null; - this.filteredEvent = null; - this.objectHolder.setValue(null); - this.verifyEvent(this.event, this.objectHolder, "fop", null); - assertNull(this.filteredEvent); - - this.event = null; - this.filteredEvent = null; - this.objectHolder.setValue("bar"); - this.verifyEvent(this.event, this.objectHolder, null, "bar"); - this.verifyEvent(this.filteredEvent, this.filteredObjectHolder, null, "bar"); + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue("bar"); + this.verifyEvent(this.innerModelEvent, this.innerModel, "foo", "bar"); + this.verifyEvent(this.filteredModelEvent, this.filteredModel, null, "bar"); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue("baz"); + this.verifyEvent(this.innerModelEvent, this.innerModel, "bar", "baz"); + this.verifyEvent(this.filteredModelEvent, this.filteredModel, "bar", "baz"); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue("foo"); + this.verifyEvent(this.innerModelEvent, this.innerModel, "baz", "foo"); + this.verifyEvent(this.filteredModelEvent, this.filteredModel, "baz", null); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue("fop"); + this.verifyEvent(this.innerModelEvent, this.innerModel, "foo", "fop"); + assertNull(this.filteredModelEvent); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue(null); + this.verifyEvent(this.innerModelEvent, this.innerModel, "fop", null); + assertNull(this.filteredModelEvent); + + this.innerModelEvent = null; + this.filteredModelEvent = null; + this.innerModel.setValue("bar"); + this.verifyEvent(this.innerModelEvent, this.innerModel, null, "bar"); + this.verifyEvent(this.filteredModelEvent, this.filteredModel, null, "bar"); } - private ChangeListener buildListener() { + private ChangeListener buildInnerListener() { return new ChangeAdapter() { @Override public void propertyChanged(PropertyChangeEvent e) { - FilteringPropertyValueModelTests.this.event = e; + FilteringPropertyValueModelTests.this.innerModelEvent = e; } }; } @@ -182,7 +235,7 @@ public class FilteringPropertyValueModelTests extends TestCase { return new ChangeAdapter() { @Override public void propertyChanged(PropertyChangeEvent e) { - FilteringPropertyValueModelTests.this.filteredEvent = e; + FilteringPropertyValueModelTests.this.filteredModelEvent = e; } }; } diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java index c5ff11b419..a501b5a9f4 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/PropertyValueModelToolsTests.java @@ -24,6 +24,7 @@ import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener; import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; +import org.eclipse.jpt.common.utility.transformer.Transformer; import junit.framework.TestCase; @SuppressWarnings("nls") @@ -35,6 +36,78 @@ public class PropertyValueModelToolsTests super(name); } + public void testValueIsNull() { + ModifiablePropertyValueModel<String> stringModel = new SimplePropertyValueModel<>(""); + PropertyValueModel<Boolean> booleanModel = PropertyValueModelTools.valueIsNull(stringModel); + LocalListener listener = new LocalListener(); + booleanModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + + listener.event = null; + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertEquals("", stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + stringModel.setValue("foo"); + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertEquals("foo", stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + stringModel.setValue(null); + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertNull(stringModel.getValue()); + assertEquals(Boolean.TRUE, listener.event.getNewValue()); + + listener.event = null; + stringModel.setValue("bar"); + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertEquals("bar", stringModel.getValue()); + assertEquals(Boolean.FALSE, listener.event.getNewValue()); + + listener.event = null; + booleanModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); + assertNull(booleanModel.getValue()); + assertEquals("bar", stringModel.getValue()); + assertNull(listener.event); + } + + public void testValueIsNotNull() { + ModifiablePropertyValueModel<String> stringModel = new SimplePropertyValueModel<>(""); + PropertyValueModel<Boolean> booleanModel = PropertyValueModelTools.valueIsNotNull(stringModel); + LocalListener listener = new LocalListener(); + booleanModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + + listener.event = null; + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertEquals("", stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + stringModel.setValue("foo"); + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertEquals("foo", stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + stringModel.setValue(null); + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertNull(stringModel.getValue()); + assertEquals(Boolean.FALSE, listener.event.getNewValue()); + + listener.event = null; + stringModel.setValue("bar"); + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertEquals("bar", stringModel.getValue()); + assertEquals(Boolean.TRUE, listener.event.getNewValue()); + + listener.event = null; + booleanModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); + assertNull(booleanModel.getValue()); + assertEquals("bar", stringModel.getValue()); + assertNull(listener.event); + } + public void testValueEquals() { String string = "foo"; ModifiablePropertyValueModel<String> stringModel = new SimplePropertyValueModel<>(""); @@ -61,9 +134,124 @@ public class PropertyValueModelToolsTests listener.event = null; stringModel.setValue(null); + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertNull(stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + booleanModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); + assertNull(booleanModel.getValue()); + assertNull(stringModel.getValue()); + assertNull(listener.event); + } + + public void testValueNotEquals() { + String string = "foo"; + ModifiablePropertyValueModel<String> stringModel = new SimplePropertyValueModel<>(""); + PropertyValueModel<Boolean> booleanModel = PropertyValueModelTools.valueNotEquals(stringModel, string); + LocalListener listener = new LocalListener(); + booleanModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + + listener.event = null; + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertEquals("", stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + stringModel.setValue("foo"); + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertEquals("foo", stringModel.getValue()); + assertEquals(Boolean.FALSE, listener.event.getNewValue()); + + listener.event = null; + stringModel.setValue("bar"); + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertEquals("bar", stringModel.getValue()); + assertEquals(Boolean.TRUE, listener.event.getNewValue()); + + listener.event = null; + stringModel.setValue(null); + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertNull(stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + booleanModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); + assertNull(booleanModel.getValue()); + assertNull(stringModel.getValue()); + assertNull(listener.event); + } + + public void testValueIsIdentical() { + Object object0 = new Object(); + Object object1 = new Object(); + Object object2 = new Object(); + ModifiablePropertyValueModel<Object> stringModel = new SimplePropertyValueModel<>(object0); + PropertyValueModel<Boolean> booleanModel = PropertyValueModelTools.valueIsIdentical(stringModel, object1); + LocalListener listener = new LocalListener(); + booleanModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + + listener.event = null; + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertEquals(object0, stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + stringModel.setValue(object1); + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertEquals(object1, stringModel.getValue()); + assertEquals(Boolean.TRUE, listener.event.getNewValue()); + + listener.event = null; + stringModel.setValue(object2); + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertEquals(object2, stringModel.getValue()); + assertEquals(Boolean.FALSE, listener.event.getNewValue()); + + listener.event = null; + stringModel.setValue(null); + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertNull(stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + booleanModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); assertNull(booleanModel.getValue()); assertNull(stringModel.getValue()); - assertNull(listener.event.getNewValue()); + assertNull(listener.event); + } + + public void testValueIsNotIdentical() { + Object object0 = new Object(); + Object object1 = new Object(); + Object object2 = new Object(); + ModifiablePropertyValueModel<Object> stringModel = new SimplePropertyValueModel<>(object0); + PropertyValueModel<Boolean> booleanModel = PropertyValueModelTools.valueIsNotIdentical(stringModel, object1); + LocalListener listener = new LocalListener(); + booleanModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + + listener.event = null; + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertEquals(object0, stringModel.getValue()); + assertNull(listener.event); + + listener.event = null; + stringModel.setValue(object1); + assertEquals(Boolean.FALSE, booleanModel.getValue()); + assertEquals(object1, stringModel.getValue()); + assertEquals(Boolean.FALSE, listener.event.getNewValue()); + + listener.event = null; + stringModel.setValue(object2); + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertEquals(object2, stringModel.getValue()); + assertEquals(Boolean.TRUE, listener.event.getNewValue()); + + listener.event = null; + stringModel.setValue(null); + assertEquals(Boolean.TRUE, booleanModel.getValue()); + assertNull(stringModel.getValue()); + assertNull(listener.event); listener.event = null; booleanModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); @@ -81,6 +269,7 @@ public class PropertyValueModelToolsTests listener.event = null; assertEquals("foofoo", doubleStringModel.getValue()); + assertEquals("foo", halfStringModel.getValue()); assertNull(listener.event); @@ -195,6 +384,50 @@ public class PropertyValueModelToolsTests assertTrue(exCaught); } + public void testTransformModifiablePropertyValueModel() { + ModifiablePropertyValueModel<String> innerModel = new SimplePropertyValueModel<>("1"); + Transformer<String, Integer> getTransformer = new StringToIntegerTransformer(); + Transformer<Integer, String> setTransformer = new IntegerToStringTransformer(); + ModifiablePropertyValueModel<Integer> outerModel = PropertyValueModelTools.transform(innerModel, getTransformer, setTransformer); + LocalListener listener = new LocalListener(); + outerModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + + listener.event = null; + assertEquals("1", innerModel.getValue()); + assertEquals(Integer.valueOf(1), outerModel.getValue()); + assertNull(listener.event); + + listener.event = null; + innerModel.setValue("42"); + assertEquals("42", innerModel.getValue()); + assertEquals(Integer.valueOf(42), outerModel.getValue()); + assertEquals(Integer.valueOf(42), listener.event.getNewValue()); + + listener.event = null; + outerModel.setValue(Integer.valueOf(666)); + assertEquals("666", innerModel.getValue()); + assertEquals(Integer.valueOf(666), outerModel.getValue()); + assertEquals(Integer.valueOf(666), listener.event.getNewValue()); + } + + public static class StringToIntegerTransformer + extends TransformerAdapter<String, Integer> + { + @Override + public Integer transform(String input) { + return Integer.valueOf(input); + } + } + + public static class IntegerToStringTransformer + extends TransformerAdapter<Integer, String> + { + @Override + public String transform(Integer input) { + return input.toString(); + } + } + public void testConstructor() { boolean exCaught = false; try { diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java index 459ba8c56f..2f1659f751 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -24,7 +24,7 @@ import org.eclipse.jpt.common.utility.tests.internal.TestTools; @SuppressWarnings("nls") public class CheckBoxModelAdapterTests extends TestCase { - private ModifiablePropertyValueModel<Boolean> booleanHolder; + private ModifiablePropertyValueModel<Boolean> booleanModel; private ButtonModel buttonModelAdapter; boolean eventFired; @@ -35,13 +35,21 @@ public class CheckBoxModelAdapterTests extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - this.booleanHolder = new SimplePropertyValueModel<Boolean>(Boolean.TRUE); - this.buttonModelAdapter = new CheckBoxModelAdapter(this.booleanHolder) { - @Override - protected PropertyChangeListener buildBooleanChangeListener() { - return this.buildBooleanChangeListener_(); - } - }; + this.booleanModel = new SimplePropertyValueModel<>(Boolean.TRUE); + this.buttonModelAdapter = new TestCheckBoxModelAdapter(this.booleanModel); + } + + public static class TestCheckBoxModelAdapter + extends CheckBoxModelAdapter + { + private static final long serialVersionUID = 1L; + public TestCheckBoxModelAdapter(ModifiablePropertyValueModel<Boolean> booleanModel) { + super(booleanModel); + } + @Override + protected PropertyChangeListener buildBooleanChangeListener() { + return this.buildBooleanChangeListener_(); + } } @Override @@ -60,7 +68,7 @@ public class CheckBoxModelAdapterTests extends TestCase { }); this.buttonModelAdapter.setSelected(false); assertTrue(this.eventFired); - assertEquals(Boolean.FALSE, this.booleanHolder.getValue()); + assertEquals(Boolean.FALSE, this.booleanModel.getValue()); } public void testSetValue() throws Exception { @@ -72,7 +80,7 @@ public class CheckBoxModelAdapterTests extends TestCase { } }); assertTrue(this.buttonModelAdapter.isSelected()); - this.booleanHolder.setValue(Boolean.FALSE); + this.booleanModel.setValue(Boolean.FALSE); assertTrue(this.eventFired); assertFalse(this.buttonModelAdapter.isSelected()); } @@ -86,18 +94,18 @@ public class CheckBoxModelAdapterTests extends TestCase { } }); assertTrue(this.buttonModelAdapter.isSelected()); - this.booleanHolder.setValue(null); + this.booleanModel.setValue(null); assertTrue(this.eventFired); assertFalse(this.buttonModelAdapter.isSelected()); this.eventFired = false; - this.booleanHolder.setValue(Boolean.FALSE); + this.booleanModel.setValue(Boolean.FALSE); assertFalse(this.eventFired); assertFalse(this.buttonModelAdapter.isSelected()); } public void testHasListeners() throws Exception { - SimplePropertyValueModel<Boolean> localBooleanHolder = (SimplePropertyValueModel<Boolean>) this.booleanHolder; + SimplePropertyValueModel<Boolean> localBooleanHolder = (SimplePropertyValueModel<Boolean>) this.booleanModel; assertFalse(localBooleanHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); this.verifyHasNoListeners(this.buttonModelAdapter); diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java index 1a733c82bd..b2c04a27ed 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -23,8 +23,10 @@ import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.tests.internal.TestTools; @SuppressWarnings("nls") -public class RadioButtonModelAdapterTests extends TestCase { - private ModifiablePropertyValueModel<Object> valueHolder; +public class RadioButtonModelAdapterTests + extends TestCase +{ + private ModifiablePropertyValueModel<Object> valueModel; private ButtonModel redButtonModelAdapter; private ChangeListener redListener; @@ -51,10 +53,10 @@ public class RadioButtonModelAdapterTests extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - this.valueHolder = new SimplePropertyValueModel<Object>(null); + this.valueModel = new SimplePropertyValueModel<>(null); // buttonGroup = new ButtonGroup(); - this.redButtonModelAdapter = this.buildButtonModel(this.valueHolder, RED); + this.redButtonModelAdapter = this.buildButtonModel(this.valueModel, RED); // this.redButtonModelAdapter.setGroup(buttonGroup); this.redListener = new TestChangeListener() { @Override @@ -63,7 +65,7 @@ public class RadioButtonModelAdapterTests extends TestCase { } }; - this.greenButtonModelAdapter = this.buildButtonModel(this.valueHolder, GREEN); + this.greenButtonModelAdapter = this.buildButtonModel(this.valueModel, GREEN); // this.greenButtonModelAdapter.setGroup(buttonGroup); this.greenListener = new TestChangeListener() { @Override @@ -72,7 +74,7 @@ public class RadioButtonModelAdapterTests extends TestCase { } }; - this.blueButtonModelAdapter = this.buildButtonModel(this.valueHolder, BLUE); + this.blueButtonModelAdapter = this.buildButtonModel(this.valueModel, BLUE); // this.blueButtonModelAdapter.setGroup(buttonGroup); this.blueListener = new TestChangeListener() { @Override @@ -85,12 +87,21 @@ public class RadioButtonModelAdapterTests extends TestCase { } private ButtonModel buildButtonModel(ModifiablePropertyValueModel<Object> pvm, Object buttonValue) { - return new RadioButtonModelAdapter(pvm, buttonValue) { - @Override - protected PropertyChangeListener buildBooleanChangeListener() { - return this.buildBooleanChangeListener_(); - } - }; + return new TestRadioButtonModelAdapter(pvm, buttonValue); + } + + // build synchronous listener + public static class TestRadioButtonModelAdapter + extends RadioButtonModelAdapter + { + public TestRadioButtonModelAdapter(ModifiablePropertyValueModel<Object> pvm, Object buttonValue) { + super(pvm, buttonValue); + } + private static final long serialVersionUID = 1L; + @Override + protected PropertyChangeListener buildBooleanChangeListener() { + return this.buildBooleanChangeListener_(); + } } private void listenToModelAdapters() { @@ -118,21 +129,21 @@ public class RadioButtonModelAdapterTests extends TestCase { assertFalse(this.redEventFired); assertTrue(this.greenEventFired); assertFalse(this.blueEventFired); - assertEquals(GREEN, this.valueHolder.getValue()); + assertEquals(GREEN, this.valueModel.getValue()); this.clearFlags(); this.blueButtonModelAdapter.setSelected(true); assertFalse(this.redEventFired); assertTrue(this.greenEventFired); assertTrue(this.blueEventFired); - assertEquals(BLUE, this.valueHolder.getValue()); + assertEquals(BLUE, this.valueModel.getValue()); this.clearFlags(); this.redButtonModelAdapter.setSelected(true); assertTrue(this.redEventFired); assertFalse(this.greenEventFired); assertTrue(this.blueEventFired); - assertEquals(RED, this.valueHolder.getValue()); + assertEquals(RED, this.valueModel.getValue()); } public void testSetValue() throws Exception { @@ -141,7 +152,7 @@ public class RadioButtonModelAdapterTests extends TestCase { this.greenButtonModelAdapter.setSelected(true); this.clearFlags(); - this.valueHolder.setValue(BLUE); + this.valueModel.setValue(BLUE); assertFalse(this.redEventFired); assertTrue(this.greenEventFired); assertTrue(this.blueEventFired); @@ -150,7 +161,7 @@ public class RadioButtonModelAdapterTests extends TestCase { assertTrue(this.blueButtonModelAdapter.isSelected()); this.clearFlags(); - this.valueHolder.setValue(RED); + this.valueModel.setValue(RED); assertTrue(this.redEventFired); assertFalse(this.greenEventFired); assertTrue(this.blueEventFired); @@ -162,13 +173,13 @@ public class RadioButtonModelAdapterTests extends TestCase { public void testDefaultValue() throws Exception { this.listenToModelAdapters(); - this.valueHolder.setValue(GREEN); + this.valueModel.setValue(GREEN); assertFalse(this.redButtonModelAdapter.isSelected()); assertTrue(this.greenButtonModelAdapter.isSelected()); assertFalse(this.blueButtonModelAdapter.isSelected()); this.clearFlags(); - this.valueHolder.setValue(null); + this.valueModel.setValue(null); assertFalse(this.redEventFired); assertTrue(this.greenEventFired); assertFalse(this.blueEventFired); @@ -177,7 +188,7 @@ public class RadioButtonModelAdapterTests extends TestCase { assertFalse(this.blueButtonModelAdapter.isSelected()); this.clearFlags(); - this.valueHolder.setValue(BLUE); + this.valueModel.setValue(BLUE); assertFalse(this.redEventFired); assertFalse(this.greenEventFired); assertTrue(this.blueEventFired); @@ -187,7 +198,7 @@ public class RadioButtonModelAdapterTests extends TestCase { } public void testHasListeners() throws Exception { - SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueHolder; + SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueModel; assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); this.verifyHasNoListeners(this.redButtonModelAdapter); this.verifyHasNoListeners(this.greenButtonModelAdapter); diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java index 9bc19631d7..9af086f626 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 Oracle. All rights reserved. + * Copyright (c) 2007, 2016 Oracle. All rights reserved. * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v1.0, which accompanies this distribution * and is available at http://www.eclipse.org/legal/epl-v10.html. @@ -41,9 +41,9 @@ import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; @SuppressWarnings("nls") public class RadioButtonModelAdapterUITest { - private TestModel testModel; - private ModifiablePropertyValueModel<TestModel> testModelHolder; - private ModifiablePropertyValueModel<Object> colorHolder; + private ColoredThing coloredThing; + private ModifiablePropertyValueModel<ColoredThing> coloredThingModel; + private ModifiablePropertyValueModel<String> colorModel; private ButtonModel redButtonModel; private ButtonModel greenButtonModel; private ButtonModel blueButtonModel; @@ -57,30 +57,30 @@ public class RadioButtonModelAdapterUITest { } private void exec() throws Exception { - this.testModel = new TestModel(); - this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel); - this.colorHolder = this.buildColorHolder(this.testModelHolder); - this.redButtonModel = this.buildRadioButtonModelAdapter(this.colorHolder, TestModel.RED); - this.greenButtonModel = this.buildRadioButtonModelAdapter(this.colorHolder, TestModel.GREEN); - this.blueButtonModel = this.buildRadioButtonModelAdapter(this.colorHolder, TestModel.BLUE); + this.coloredThing = new ColoredThing(); + this.coloredThingModel = new SimplePropertyValueModel<>(this.coloredThing); + this.colorModel = this.buildColorModel(this.coloredThingModel); + this.redButtonModel = this.buildRadioButtonModelAdapter(this.colorModel, ColoredThing.RED); + this.greenButtonModel = this.buildRadioButtonModelAdapter(this.colorModel, ColoredThing.GREEN); + this.blueButtonModel = this.buildRadioButtonModelAdapter(this.colorModel, ColoredThing.BLUE); this.openWindow(); } - private ModifiablePropertyValueModel<Object> buildColorHolder(PropertyValueModel<TestModel> subjectHolder) { - return new PropertyAspectAdapter<TestModel, Object>(subjectHolder, TestModel.COLOR_PROPERTY) { + private ModifiablePropertyValueModel<String> buildColorModel(PropertyValueModel<ColoredThing> ctm) { + return new PropertyAspectAdapter<ColoredThing, String>(ctm, ColoredThing.COLOR_PROPERTY) { @Override - protected Object buildValue_() { + protected String buildValue_() { return this.subject.getColor(); } @Override - protected void setValue_(Object value) { - this.subject.setColor((String) value); + protected void setValue_(String value) { + this.subject.setColor(value); } }; } - private ButtonModel buildRadioButtonModelAdapter(ModifiablePropertyValueModel<Object> colorPVM, String color) { - return new RadioButtonModelAdapter(colorPVM, color); + private ButtonModel buildRadioButtonModelAdapter(ModifiablePropertyValueModel<String> colorPVM, String color) { + return new RadioButtonModelAdapter<>(colorPVM, color); } private void openWindow() { @@ -154,6 +154,7 @@ public class RadioButtonModelAdapterUITest { private Action buildResetColorAction() { Action action = new AbstractAction("reset color") { + private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent event) { RadioButtonModelAdapterUITest.this.resetColor(); } @@ -163,7 +164,7 @@ public class RadioButtonModelAdapterUITest { } void resetColor() { - this.testModel.setColor(TestModel.DEFAULT_COLOR); + this.coloredThing.setColor(ColoredThing.DEFAULT_COLOR); } private JButton buildClearModelButton() { @@ -172,6 +173,7 @@ public class RadioButtonModelAdapterUITest { private Action buildClearModelAction() { Action action = new AbstractAction("clear model") { + private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent event) { RadioButtonModelAdapterUITest.this.clearModel(); } @@ -181,7 +183,7 @@ public class RadioButtonModelAdapterUITest { } void clearModel() { - this.testModelHolder.setValue(null); + this.coloredThingModel.setValue(null); } private JButton buildRestoreModelButton() { @@ -190,6 +192,7 @@ public class RadioButtonModelAdapterUITest { private Action buildRestoreModelAction() { Action action = new AbstractAction("restore model") { + private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent event) { RadioButtonModelAdapterUITest.this.restoreModel(); } @@ -199,7 +202,7 @@ public class RadioButtonModelAdapterUITest { } void restoreModel() { - this.testModelHolder.setValue(this.testModel); + this.coloredThingModel.setValue(this.coloredThing); } private JButton buildPrintModelButton() { @@ -208,6 +211,7 @@ public class RadioButtonModelAdapterUITest { private Action buildPrintModelAction() { Action action = new AbstractAction("print model") { + private static final long serialVersionUID = 1L; public void actionPerformed(ActionEvent event) { RadioButtonModelAdapterUITest.this.printModel(); } @@ -217,11 +221,13 @@ public class RadioButtonModelAdapterUITest { } void printModel() { - System.out.println(this.testModel); + System.out.println(this.coloredThing); } - private static class TestModel extends AbstractModel { + private static class ColoredThing + extends AbstractModel + { private String color; public static final String COLOR_PROPERTY = "color"; public static final String RED = "red"; @@ -234,10 +240,10 @@ public class RadioButtonModelAdapterUITest { BLUE }; - public TestModel() { + public ColoredThing() { this(DEFAULT_COLOR); } - public TestModel(String color) { + public ColoredThing(String color) { this.color = color; } public String getColor() { |