diff options
Diffstat (limited to 'common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java')
-rw-r--r-- | common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java | 118 |
1 files changed, 60 insertions, 58 deletions
diff --git a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java index e87cc82924..18860d8783 100644 --- a/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java +++ b/common/tests/org.eclipse.jpt.common.utility.tests/src/org/eclipse/jpt/common/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008, 2012 Oracle. All rights reserved. + * Copyright (c) 2008, 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,11 +9,10 @@ ******************************************************************************/ 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.PropertyValueModelTools; import org.eclipse.jpt.common.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.common.utility.internal.model.value.TransformationPropertyValueModel; -import org.eclipse.jpt.common.utility.internal.transformer.AbstractTransformer; +import org.eclipse.jpt.common.utility.internal.transformer.TransformerAdapter; import org.eclipse.jpt.common.utility.model.event.PropertyChangeEvent; import org.eclipse.jpt.common.utility.model.listener.ChangeAdapter; import org.eclipse.jpt.common.utility.model.listener.ChangeListener; @@ -22,13 +21,16 @@ import org.eclipse.jpt.common.utility.model.value.ModifiablePropertyValueModel; import org.eclipse.jpt.common.utility.model.value.PropertyValueModel; import org.eclipse.jpt.common.utility.tests.internal.TestTools; import org.eclipse.jpt.common.utility.transformer.Transformer; +import junit.framework.TestCase; @SuppressWarnings("nls") -public class CachingTransformationPropertyValueModelTests extends TestCase { - private ModifiablePropertyValueModel<Person> objectHolder; +public class CachingTransformationPropertyValueModelTests + extends TestCase +{ + private ModifiablePropertyValueModel<Person> personModel; PropertyChangeEvent event; - private PropertyValueModel<Person> transformationObjectHolder; + private PropertyValueModel<Person> testModel; PropertyChangeEvent transformationEvent; public CachingTransformationPropertyValueModelTests(String name) { @@ -38,8 +40,8 @@ public class CachingTransformationPropertyValueModelTests extends TestCase { @Override protected void setUp() throws Exception { super.setUp(); - this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null)); - this.transformationObjectHolder = new TransformationPropertyValueModel<Person, Person>(this.objectHolder, PARENT_TRANSFORMER); + this.personModel = new SimplePropertyValueModel<>(new Person("Karen", "Peggy", null)); + this.testModel = PropertyValueModelTools.transform(this.personModel, PARENT_TRANSFORMER); } @Override @@ -50,93 +52,93 @@ public class CachingTransformationPropertyValueModelTests extends TestCase { public void testValue() { ChangeListener listener = this.buildTransformationChangeListener(); - this.transformationObjectHolder.addChangeListener(listener); + this.testModel.addChangeListener(listener); - Person person = this.objectHolder.getValue(); + Person person = this.personModel.getValue(); assertEquals("Karen", person.getName()); - Person parent = this.transformationObjectHolder.getValue(); + Person parent = this.testModel.getValue(); assertEquals(person.getParent().getName(), parent.getName()); - assertNotSame(person.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent, this.transformationObjectHolder.getValue()); + assertNotSame(person.getParent(), this.testModel.getValue()); + assertEquals(parent, this.testModel.getValue()); Person person1 = new Person("Matt", "Mitch", null); - this.objectHolder.setValue(person1); - Person parent2 = this.transformationObjectHolder.getValue(); + this.personModel.setValue(person1); + Person parent2 = this.testModel.getValue(); assertEquals(person1.getParent().getName(), parent2.getName()); - assertNotSame(person1.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent2, this.transformationObjectHolder.getValue()); + assertNotSame(person1.getParent(), this.testModel.getValue()); + assertEquals(parent2, this.testModel.getValue()); - this.objectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); + this.personModel.setValue(null); + assertNull(this.personModel.getValue()); + assertNull(this.testModel.getValue()); Person person3 = new Person("Karen", "Peggy", null); - this.objectHolder.setValue(person3); + this.personModel.setValue(person3); assertEquals("Karen", person3.getName()); - Person parent3 = this.transformationObjectHolder.getValue(); + Person parent3 = this.testModel.getValue(); assertEquals(person3.getParent().getName(), parent3.getName()); - assertNotSame(person3.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent3, this.transformationObjectHolder.getValue()); + assertNotSame(person3.getParent(), this.testModel.getValue()); + assertEquals(parent3, this.testModel.getValue()); } public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + assertTrue(((AbstractModel) this.personModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); ChangeListener listener = this.buildTransformationChangeListener(); - this.transformationObjectHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.transformationObjectHolder.removeChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.transformationObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.addChangeListener(listener); + assertTrue(((AbstractModel) this.personModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.removeChangeListener(listener); + assertTrue(((AbstractModel) this.personModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); + + this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.personModel).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); + this.testModel.removePropertyChangeListener(PropertyValueModel.VALUE, listener); + assertTrue(((AbstractModel) this.personModel).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); } public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildChangeListener()); - this.transformationObjectHolder.addChangeListener(this.buildTransformationChangeListener()); + this.personModel.addChangeListener(this.buildChangeListener()); + this.testModel.addChangeListener(this.buildTransformationChangeListener()); this.verifyPropertyChanges(); } public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); + this.personModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); + this.testModel.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); this.verifyPropertyChanges(); } private void verifyPropertyChanges() { this.event = null; this.transformationEvent = null; - Person karen = this.objectHolder.getValue(); - Person peggyParent = this.transformationObjectHolder.getValue(); + Person karen = this.personModel.getValue(); + Person peggyParent = this.testModel.getValue(); Person peggy = new Person("Peggy", "Marian", null); - this.objectHolder.setValue(peggy); - Person marianParent = this.transformationObjectHolder.getValue(); - this.verifyEvent(this.event, this.objectHolder, karen, peggy); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, peggyParent, marianParent); + this.personModel.setValue(peggy); + Person marianParent = this.testModel.getValue(); + this.verifyEvent(this.event, this.personModel, karen, peggy); + this.verifyEvent(this.transformationEvent, this.testModel, peggyParent, marianParent); this.event = null; this.transformationEvent = null; Person matt = new Person("Matt", "Mitch", null); - this.objectHolder.setValue(matt); - Person mitchParent = this.transformationObjectHolder.getValue(); - this.verifyEvent(this.event, this.objectHolder, peggy, matt); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, marianParent, mitchParent); + this.personModel.setValue(matt); + Person mitchParent = this.testModel.getValue(); + this.verifyEvent(this.event, this.personModel, peggy, matt); + this.verifyEvent(this.transformationEvent, this.testModel, marianParent, mitchParent); this.event = null; this.transformationEvent = null; - this.objectHolder.setValue(null); - this.verifyEvent(this.event, this.objectHolder, matt, null); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, mitchParent, null); + this.personModel.setValue(null); + this.verifyEvent(this.event, this.personModel, matt, null); + this.verifyEvent(this.transformationEvent, this.testModel, mitchParent, null); this.event = null; this.transformationEvent = null; - this.objectHolder.setValue(matt); - mitchParent = this.transformationObjectHolder.getValue(); - this.verifyEvent(this.event, this.objectHolder, null, matt); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, null, mitchParent); + this.personModel.setValue(matt); + mitchParent = this.testModel.getValue(); + this.verifyEvent(this.event, this.personModel, null, matt); + this.verifyEvent(this.transformationEvent, this.testModel, null, mitchParent); } private PropertyChangeListener buildListener() { @@ -183,10 +185,10 @@ public class CachingTransformationPropertyValueModelTests extends TestCase { private static final Transformer<Person, Person> PARENT_TRANSFORMER = new ParentTransformer(); static class ParentTransformer - extends AbstractTransformer<Person, Person> + extends TransformerAdapter<Person, Person> { @Override - public Person transform_(Person person) { + public Person transform(Person person) { return person.getParent(); } } |