diff options
Diffstat (limited to 'jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model')
83 files changed, 0 insertions, 25230 deletions
diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/ChangeSupportTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/ChangeSupportTests.java deleted file mode 100644 index 73a51e224a..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/ChangeSupportTests.java +++ /dev/null @@ -1,4541 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashSet; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.ChangeSupport; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.event.StateChangeEvent; -import org.eclipse.jpt.utility.model.event.TreeAddEvent; -import org.eclipse.jpt.utility.model.event.TreeChangeEvent; -import org.eclipse.jpt.utility.model.event.TreeClearEvent; -import org.eclipse.jpt.utility.model.event.TreeEvent; -import org.eclipse.jpt.utility.model.event.TreeRemoveEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.CollectionChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ListChangeAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeAdapter; -import org.eclipse.jpt.utility.model.listener.StateChangeAdapter; -import org.eclipse.jpt.utility.model.listener.TreeChangeAdapter; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ChangeSupportTests - extends TestCase -{ - TestModel testModel; - static final String TEST_TO_STRING = "this is a test"; - - ChangeListener changeListener = new Adapter(); - - StateChangeEvent stateChangeEvent; - boolean stateChangedCalled = false; - - PropertyChangeEvent propertyChangeEvent; - boolean propertyChangeCalled = false; - static final String PROPERTY_NAME = "propertyName"; - static final Object OLD_OBJECT_VALUE = new Object(); - static final Object NEW_OBJECT_VALUE = new Object(); - static final Integer OLD_INT_VALUE = new Integer(27); - static final Boolean OLD_BOOLEAN_VALUE = Boolean.TRUE; - static final Integer NEW_INT_VALUE = new Integer(42); - static final Boolean NEW_BOOLEAN_VALUE = Boolean.FALSE; - - CollectionEvent collectionEvent; - boolean itemsAddedCollectionCalled = false; - boolean itemsRemovedCollectionCalled = false; - boolean collectionChangedCalled = false; - boolean collectionClearedCalled = false; - static final String COLLECTION_NAME = "collectionName"; - static final Object ADDED_OBJECT_VALUE = new Object(); - static final Object ADDED_OBJECT_VALUE_2 = new Object(); - static final Object REMOVED_OBJECT_VALUE = new Object(); - static final int TARGET_INDEX = 7; - static final int SOURCE_INDEX = 22; - - ListEvent listEvent; - boolean itemsAddedListCalled = false; - boolean itemsRemovedListCalled = false; - boolean itemsReplacedListCalled = false; - boolean itemsMovedListCalled = false; - boolean listChangedCalled = false; - boolean listClearedCalled = false; - static final String LIST_NAME = "listName"; - static final int ADD_INDEX = 3; - static final int REMOVE_INDEX = 5; - static final int REPLACE_INDEX = 2; - - TreeEvent treeEvent; - boolean nodeAddedCalled = false; - boolean nodeRemovedCalled = false; - boolean treeChangedCalled = false; - boolean treeClearedCalled = false; - static final String TREE_NAME = "treeName"; - static final List<Object> OBJECT_PATH = Arrays.asList(new Object[] {new Object(), new Object(), new String()}); - - - public ChangeSupportTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.testModel = new TestModel(); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - - // ********** general tests ********** - - public void testNullSource() { - boolean exCaught = false; - try { - ChangeSupport cs = new ChangeSupport(null); - fail("bogus change support: " + cs); - } catch (NullPointerException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - // ********** state change tests ********** - - public void testFireStateChange() { - this.stateChangeEvent = null; - this.stateChangedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireStateChange(); - assertNotNull(this.stateChangeEvent); - assertEquals(this.testModel, this.stateChangeEvent.getSource()); - assertTrue(this.stateChangedCalled); - } - - public void testHasAnyStateChangeListeners() { - assertTrue(this.testModel.hasNoStateChangeListeners()); - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.hasAnyStateChangeListeners()); - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.hasNoStateChangeListeners()); - } - - public void testHasAnyStateChangeListenersDuplicate() { - assertTrue(this.testModel.hasNoStateChangeListeners()); - this.testModel.addChangeListener(this.changeListener); - boolean exCaught = false; - try { - this.testModel.addChangeListener(this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - assertTrue(this.testModel.hasAnyStateChangeListeners()); - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.hasNoStateChangeListeners()); - - exCaught = false; - try { - this.testModel.removeChangeListener(this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(this.testModel.hasNoStateChangeListeners()); - } - - public void testAddNullStateListener() { - boolean exCaught = false; - try { - this.testModel.addStateChangeListener(null); - } catch (NullPointerException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testRemoveBogusStateListener() { - boolean exCaught = false; - try { - this.testModel.removeChangeListener(this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addPropertyChangeListener("foo", this.changeListener); - exCaught = false; - try { - this.testModel.removeChangeListener(this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addChangeListener(this.changeListener); - exCaught = false; - try { - this.testModel.removeStateChangeListener(new Adapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - exCaught = false; - try { - this.testModel.removeStateChangeListener(new StateChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - - // ********** property change tests ********** - - public void testFirePropertyChangedEvent() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedEvent(); - this.verifyPropertyChangeEvent(OLD_OBJECT_VALUE, NEW_OBJECT_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedEvent(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedEvent(); - this.verifyPropertyChangeEvent(OLD_OBJECT_VALUE, NEW_OBJECT_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedEvent(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testFirePropertyChangedEventNoChange() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedEventNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedEventNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedEventNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedEventNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testFirePropertyChangedObjectObject() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedObjectObject(); - this.verifyPropertyChangeEvent(OLD_OBJECT_VALUE, NEW_OBJECT_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedObjectObject(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedObjectObject(); - this.verifyPropertyChangeEvent(OLD_OBJECT_VALUE, NEW_OBJECT_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedObjectObject(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testFirePropertyChangedObjectObjectNoChange() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedObjectObjectNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedObjectObjectNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedObjectObjectNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedObjectObjectNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testFirePropertyChangedObject() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedObject(); - this.verifyPropertyChangeEvent(null, NEW_OBJECT_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedObject(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedObject(); - this.verifyPropertyChangeEvent(null, NEW_OBJECT_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedObject(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testFirePropertyChangedObjectNoChange() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedObjectNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedObjectNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedObjectNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedObjectNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testFirePropertyChangedIntInt() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedIntInt(); - this.verifyPropertyChangeEvent(OLD_INT_VALUE, NEW_INT_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedIntInt(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedIntInt(); - this.verifyPropertyChangeEvent(OLD_INT_VALUE, NEW_INT_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedIntInt(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testFirePropertyChangedIntIntNoChange() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedIntIntNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedIntIntNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedIntIntNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedIntIntNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testFirePropertyChangedBooleanBoolean() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedBooleanBoolean(); - this.verifyPropertyChangeEvent(OLD_BOOLEAN_VALUE, NEW_BOOLEAN_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedBooleanBoolean(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedBooleanBoolean(); - this.verifyPropertyChangeEvent(OLD_BOOLEAN_VALUE, NEW_BOOLEAN_VALUE); - assertTrue(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedBooleanBoolean(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testFirePropertyChangedBooleanBooleanNoChange() { - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedBooleanBooleanNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFirePropertyChangedBooleanBooleanNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedBooleanBooleanNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - this.testModel.testFirePropertyChangedBooleanBooleanNoChange(); - assertNull(this.propertyChangeEvent); - assertFalse(this.propertyChangeCalled); - } - - public void testHasAnyPropertyChangeListeners() { - assertTrue(this.testModel.hasNoPropertyChangeListeners(PROPERTY_NAME)); - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.hasAnyPropertyChangeListeners(PROPERTY_NAME)); - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.hasNoPropertyChangeListeners(PROPERTY_NAME)); - - assertTrue(this.testModel.hasNoPropertyChangeListeners(PROPERTY_NAME)); - this.testModel.addPropertyChangeListener(PROPERTY_NAME, this.changeListener); - assertTrue(this.testModel.hasAnyPropertyChangeListeners(PROPERTY_NAME)); - this.testModel.removePropertyChangeListener(PROPERTY_NAME, this.changeListener); - assertTrue(this.testModel.hasNoPropertyChangeListeners(PROPERTY_NAME)); - } - - public void testAddNullPropertyListener() { - boolean exCaught = false; - try { - this.testModel.addChangeListener(null); - } catch (NullPointerException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testAddNullPropertyListenerName() { - boolean exCaught = false; - try { - this.testModel.addPropertyChangeListener("foo", null); - } catch (NullPointerException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testRemoveBogusPropertyListener() { - boolean exCaught = false; - try { - this.testModel.removePropertyChangeListener("foo", new PropertyChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addCollectionChangeListener("foo", this.changeListener); - exCaught = false; - try { - this.testModel.removePropertyChangeListener("foo", this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addPropertyChangeListener("foo", this.changeListener); - exCaught = false; - try { - this.testModel.removePropertyChangeListener("foo", new PropertyChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - exCaught = false; - try { - this.testModel.removePropertyChangeListener("foo", new PropertyChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - private void verifyPropertyChangeEvent(Object oldValue, Object newValue) { - this.verifyPropertyChangeEvent(this.testModel, oldValue, newValue); - } - - private void verifyPropertyChangeEvent(Object source, Object oldValue, Object newValue) { - assertNotNull(this.propertyChangeEvent); - assertEquals(source, this.propertyChangeEvent.getSource()); - assertEquals(PROPERTY_NAME, this.propertyChangeEvent.getPropertyName()); - assertEquals(oldValue, this.propertyChangeEvent.getOldValue()); - assertEquals(newValue, this.propertyChangeEvent.getNewValue()); - } - - - // ********** collection change tests ********** - - public void testFireItemsAddedCollectionEvent() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsAddedCollectionEvent(); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsAddedCollectionEvent(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsAddedCollectionEvent(); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsAddedCollectionEvent(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testFireItemsAddedCollectionEventNoChange() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsAddedCollectionEventNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsAddedCollectionEventNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsAddedCollectionEventNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsAddedCollectionEventNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testFireItemsAddedCollection() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsAddedCollection(); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsAddedCollection(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsAddedCollection(); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsAddedCollection(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testFireItemsAddedCollectionNoChange() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsAddedCollectionNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsAddedCollectionNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsAddedCollectionNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsAddedCollectionNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testFireItemAddedCollection() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemAddedCollection(); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemAddedCollection(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemAddedCollection(); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemAddedCollection(); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testFireItemsRemovedCollectionEvent() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedCollectionEvent(); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedCollectionEvent(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsRemovedCollectionEvent(); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsRemovedCollectionEvent(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testFireItemsRemovedCollectionEventNoChange() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedCollectionEventNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedCollectionEventNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsRemovedCollectionEventNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsRemovedCollectionEventNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testFireItemsRemovedCollection() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedCollection(); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedCollection(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsRemovedCollection(); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsRemovedCollection(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testFireItemsRemovedCollectionNoChange() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedCollectionNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedCollectionNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsRemovedCollectionNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemsRemovedCollectionNoChange(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testFireItemRemovedCollection() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemRemovedCollection(); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemRemovedCollection(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemRemovedCollection(); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireItemRemovedCollection(); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testFireCollectionCleared() { - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireCollectionCleared(); - this.verifyCollectionEvent(null); - assertTrue(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireCollectionCleared(); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireCollectionCleared(); - this.verifyCollectionEvent(null); - assertTrue(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireCollectionCleared(); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - } - - public void testFireCollectionChangedEvent() { - this.collectionEvent = null; - this.collectionChangedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireCollectionChangedEvent(); - this.verifyCollectionEvent(null); - assertTrue(this.collectionChangedCalled); - - this.collectionEvent = null; - this.collectionChangedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireCollectionChangedEvent(); - assertNull(this.collectionEvent); - assertFalse(this.collectionChangedCalled); - - this.collectionEvent = null; - this.collectionChangedCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireCollectionChangedEvent(); - this.verifyCollectionEvent(null); - assertTrue(this.collectionChangedCalled); - - this.collectionEvent = null; - this.collectionChangedCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireCollectionChangedEvent(); - assertNull(this.collectionEvent); - assertFalse(this.collectionChangedCalled); - } - - public void testFireCollectionChanged() { - this.collectionEvent = null; - this.collectionChangedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireCollectionChanged(); - this.verifyCollectionEvent(null); - assertTrue(this.collectionChangedCalled); - - this.collectionEvent = null; - this.collectionChangedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireCollectionChanged(); - assertNull(this.collectionEvent); - assertFalse(this.collectionChangedCalled); - - this.collectionEvent = null; - this.collectionChangedCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireCollectionChanged(); - this.verifyCollectionEvent(null); - assertTrue(this.collectionChangedCalled); - - this.collectionEvent = null; - this.collectionChangedCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - this.testModel.testFireCollectionChanged(); - assertNull(this.collectionEvent); - assertFalse(this.collectionChangedCalled); - } - - public void testAddItemToCollection() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.testAddItemToCollection()); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.testAddItemToCollection()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testAddItemToCollection()); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testAddItemToCollection()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testAddItemToCollectionNoChange() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertFalse(this.testModel.testAddItemToCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertFalse(this.testModel.testAddItemToCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testAddItemToCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testAddItemToCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testAddItemsToCollection() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.testAddItemsToCollection()); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.testAddItemsToCollection()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testAddItemsToCollection()); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testAddItemsToCollection()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testAddItemsToCollectionNoChange() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertFalse(this.testModel.testAddItemsToCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertFalse(this.testModel.testAddItemsToCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testAddItemsToCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testAddItemsToCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testAddItemsToCollectionMixed() { - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.testAddItemsToCollectionMixed()); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE_2); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.testAddItemsToCollectionMixed()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testAddItemsToCollectionMixed()); - this.verifyCollectionEvent(ADDED_OBJECT_VALUE_2); - assertTrue(this.itemsAddedCollectionCalled); - - this.collectionEvent = null; - this.itemsAddedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testAddItemsToCollectionMixed()); - assertNull(this.collectionEvent); - assertFalse(this.itemsAddedCollectionCalled); - } - - public void testRemoveItemFromCollection() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.testRemoveItemFromCollection()); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.testRemoveItemFromCollection()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testRemoveItemFromCollection()); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testRemoveItemFromCollection()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testRemoveItemFromCollectionNoChange() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertFalse(this.testModel.testRemoveItemFromCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertFalse(this.testModel.testRemoveItemFromCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRemoveItemFromCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRemoveItemFromCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testRemoveItemsFromCollection() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.testRemoveItemsFromCollection()); - this.verifyCollectionChangeEvent2(REMOVED_OBJECT_VALUE, "foo", "bar"); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.testRemoveItemsFromCollection()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testRemoveItemsFromCollection()); - this.verifyCollectionChangeEvent2(REMOVED_OBJECT_VALUE, "foo", "bar"); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testRemoveItemsFromCollection()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testRemoveItemsFromCollectionNoChange1() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testRemoveItemsFromCollectionNoChange2() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange2()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange2()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange2()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange2()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testRemoveItemsFromCollectionNoChange3() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange3()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange3()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange3()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRemoveItemsFromCollectionNoChange3()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testRetainItemsInCollection1() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.testRetainItemsInCollection1()); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.testRetainItemsInCollection1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testRetainItemsInCollection1()); - this.verifyCollectionEvent(REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testRetainItemsInCollection1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - // collection cleared... - public void testRetainItemsInCollection2() { - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.testRetainItemsInCollection2()); - this.verifyCollectionEvent(null); - assertTrue(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.testRetainItemsInCollection2()); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testRetainItemsInCollection2()); - this.verifyCollectionEvent(null); - assertTrue(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testRetainItemsInCollection2()); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - } - - public void testRetainItemsInCollectionNoChange1() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertFalse(this.testModel.testRetainItemsInCollectionNoChange1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertFalse(this.testModel.testRetainItemsInCollectionNoChange1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRetainItemsInCollectionNoChange1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRetainItemsInCollectionNoChange1()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testRetainItemsInCollectionNoChange2() { - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertFalse(this.testModel.testRetainItemsInCollectionNoChange2()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertFalse(this.testModel.testRetainItemsInCollectionNoChange2()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRetainItemsInCollectionNoChange2()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - - this.collectionEvent = null; - this.itemsRemovedCollectionCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testRetainItemsInCollectionNoChange2()); - assertNull(this.collectionEvent); - assertFalse(this.itemsRemovedCollectionCalled); - } - - public void testClearCollection() { - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.testClearCollection()); - this.verifyCollectionEvent(null); - assertTrue(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.testClearCollection()); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testClearCollection()); - this.verifyCollectionEvent(null); - assertTrue(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.testClearCollection()); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - } - - public void testClearCollectionNoChange() { - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.addChangeListener(this.changeListener); - assertFalse(this.testModel.testClearCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - assertFalse(this.testModel.testClearCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testClearCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - - this.collectionEvent = null; - this.collectionClearedCalled = false; - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertFalse(this.testModel.testClearCollectionNoChange()); - assertNull(this.collectionEvent); - assertFalse(this.collectionClearedCalled); - } - - public void testSynchronizeCollection1() { - CollectionSynchListener csl = new CollectionSynchListener(); - this.testModel.addChangeListener(csl); - assertTrue(this.testModel.testSynchronizeCollection1()); - assertTrue(csl.itemsAdded); - assertTrue(csl.itemsRemoved); - assertFalse(csl.collectionChanged); - assertFalse(csl.collectionCleared); - assertEquals(2, csl.addedItems.size()); - assertTrue(CollectionTools.containsAll(csl.addedItems, new Object[] {"joo", "jar"})); - assertEquals(2, csl.removedItems.size()); - assertTrue(CollectionTools.containsAll(csl.removedItems, new Object[] {"foo", "bar"})); - } - - public void testSynchronizeCollection2() { - CollectionSynchListener csl = new CollectionSynchListener(); - this.testModel.addChangeListener(csl); - assertTrue(this.testModel.testSynchronizeCollection2()); - assertFalse(csl.itemsAdded); - assertFalse(csl.itemsRemoved); - assertFalse(csl.collectionChanged); - assertTrue(csl.collectionCleared); - assertTrue(csl.addedItems.isEmpty()); - assertTrue(csl.removedItems.isEmpty()); - } - - public void testSynchronizeCollection3() { - CollectionSynchListener csl = new CollectionSynchListener(); - this.testModel.addChangeListener(csl); - assertTrue(this.testModel.testSynchronizeCollection3()); - assertTrue(csl.itemsAdded); - assertFalse(csl.itemsRemoved); - assertFalse(csl.collectionChanged); - assertFalse(csl.collectionCleared); - assertEquals(3, csl.addedItems.size()); - assertTrue(CollectionTools.containsAll(csl.addedItems, new Object[] {"joo", "jar", "baz"})); - assertTrue(csl.removedItems.isEmpty()); - } - - class CollectionSynchListener extends ChangeAdapter { - boolean itemsAdded = false; - boolean itemsRemoved = false; - boolean collectionChanged = false; - boolean collectionCleared = false; - Collection<Object> addedItems = new ArrayList<Object>(); - Collection<Object> removedItems = new ArrayList<Object>(); - @Override - public void collectionChanged(CollectionChangeEvent event) { - this.collectionChanged = true; - } - @Override - public void collectionCleared(CollectionClearEvent event) { - this.collectionCleared = true; - } - @Override - public void itemsAdded(CollectionAddEvent event) { - this.itemsAdded = true; - CollectionTools.addAll(this.addedItems, event.getItems()); - } - @Override - public void itemsRemoved(CollectionRemoveEvent event) { - this.itemsRemoved = true; - CollectionTools.addAll(this.removedItems, event.getItems()); - } - } - - public void testHasAnyCollectionChangeListeners() { - assertTrue(this.testModel.hasNoCollectionChangeListeners(COLLECTION_NAME)); - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.hasAnyCollectionChangeListeners(COLLECTION_NAME)); - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.hasNoCollectionChangeListeners(COLLECTION_NAME)); - - assertTrue(this.testModel.hasNoCollectionChangeListeners(COLLECTION_NAME)); - this.testModel.addCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.hasAnyCollectionChangeListeners(COLLECTION_NAME)); - this.testModel.removeCollectionChangeListener(COLLECTION_NAME, this.changeListener); - assertTrue(this.testModel.hasNoCollectionChangeListeners(COLLECTION_NAME)); - } - - public void testAddNullCollectionListener() { - boolean exCaught = false; - try { - this.testModel.addCollectionChangeListener("foo", null); - } catch (NullPointerException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testRemoveBogusCollectionListener() { - boolean exCaught = false; - try { - this.testModel.removeCollectionChangeListener("foo", this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addPropertyChangeListener("foo", this.changeListener); - exCaught = false; - try { - this.testModel.removeCollectionChangeListener("foo", this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addCollectionChangeListener("foo", this.changeListener); - exCaught = false; - try { - this.testModel.removeCollectionChangeListener("foo", new CollectionChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - exCaught = false; - try { - this.testModel.removeCollectionChangeListener("foo", new CollectionChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - private void verifyCollectionEvent(Object item) { - assertNotNull(this.collectionEvent); - assertEquals(this.testModel, this.collectionEvent.getSource()); - assertEquals(COLLECTION_NAME, this.collectionEvent.getCollectionName()); - if (item != null) { - assertEquals(item, this.getCollectionEventItems().iterator().next()); - } - } - - private Iterable<?> getCollectionEventItems() { - if (this.collectionEvent instanceof CollectionAddEvent) { - return ((CollectionAddEvent) this.collectionEvent).getItems(); - } else if (this.collectionEvent instanceof CollectionRemoveEvent) { - return ((CollectionRemoveEvent) this.collectionEvent).getItems(); - } - throw new IllegalStateException(); - } - - private void verifyCollectionChangeEvent2(Object... items) { - assertNotNull(this.collectionEvent); - assertEquals(this.testModel, this.collectionEvent.getSource()); - assertEquals(COLLECTION_NAME, this.collectionEvent.getCollectionName()); - assertEquals(items.length, this.getCollectionEventItemsSize()); - for (Object item : items) { - assertTrue(CollectionTools.contains(this.getCollectionEventItems(), item)); - } - } - - private int getCollectionEventItemsSize() { - if (this.collectionEvent instanceof CollectionAddEvent) { - return ((CollectionAddEvent) this.collectionEvent).getItemsSize(); - } else if (this.collectionEvent instanceof CollectionRemoveEvent) { - return ((CollectionRemoveEvent) this.collectionEvent).getItemsSize(); - } - throw new IllegalStateException(); - } - - - // ********** list change tests ********** - - public void testFireItemsAddedListEvent() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsAddedListEvent(); - this.verifyListAddEvent(ADD_INDEX, ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsAddedListEvent(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsAddedListEvent(); - this.verifyListAddEvent(ADD_INDEX, ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsAddedListEvent(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testFireItemsAddedListEventNoChange() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsAddedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsAddedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsAddedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsAddedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testFireItemsAddedList() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsAddedList(); - this.verifyListAddEvent(ADD_INDEX, ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsAddedList(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsAddedList(); - this.verifyListAddEvent(ADD_INDEX, ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsAddedList(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testFireItemsAddedListNoChange() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsAddedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsAddedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsAddedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsAddedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testFireItemAddedList() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemAddedList(); - this.verifyListAddEvent(ADD_INDEX, ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemAddedList(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemAddedList(); - this.verifyListAddEvent(ADD_INDEX, ADDED_OBJECT_VALUE); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemAddedList(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testFireItemsRemovedListEvent() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedListEvent(); - this.verifyListRemoveEvent(REMOVE_INDEX, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedListEvent(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsRemovedListEvent(); - this.verifyListRemoveEvent(REMOVE_INDEX, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsRemovedListEvent(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testFireItemsRemovedListEventNoChange() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsRemovedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsRemovedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testFireItemsRemovedList() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedList(); - this.verifyListRemoveEvent(REMOVE_INDEX, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsRemovedList(); - this.verifyListRemoveEvent(REMOVE_INDEX, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsRemovedList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testFireItemsRemovedListNoChange() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsRemovedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsRemovedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsRemovedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testFireItemRemovedList() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemRemovedList(); - this.verifyListRemoveEvent(REMOVE_INDEX, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemRemovedList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemRemovedList(); - this.verifyListRemoveEvent(REMOVE_INDEX, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemRemovedList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testFireItemsReplacedListEvent() { - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsReplacedListEvent(); - this.verifyListReplaceEvent(REPLACE_INDEX, ADDED_OBJECT_VALUE, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsReplacedListEvent(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsReplacedListEvent(); - this.verifyListReplaceEvent(REPLACE_INDEX, ADDED_OBJECT_VALUE, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsReplacedListEvent(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - } - - public void testFireItemsReplacedListEventNoChange() { - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsReplacedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsReplacedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsReplacedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsReplacedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - } - - public void testFireItemsReplacedList() { - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsReplacedList(); - this.verifyListReplaceEvent(REPLACE_INDEX, ADDED_OBJECT_VALUE, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsReplacedList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsReplacedList(); - this.verifyListReplaceEvent(REPLACE_INDEX, ADDED_OBJECT_VALUE, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsReplacedList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - } - - public void testFireItemsReplacedListNoChange() { - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsReplacedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsReplacedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsReplacedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsReplacedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - } - - public void testFireItemReplacedList() { - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemReplacedList(); - this.verifyListReplaceEvent(REPLACE_INDEX, ADDED_OBJECT_VALUE, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemReplacedList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemReplacedList(); - this.verifyListReplaceEvent(REPLACE_INDEX, ADDED_OBJECT_VALUE, REMOVED_OBJECT_VALUE); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemReplacedList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - } - - public void testFireItemsMovedListEvent() { - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsMovedListEvent(); - this.verifyListMoveEvent(TARGET_INDEX, SOURCE_INDEX); - assertTrue(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsMovedListEvent(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsMovedListEvent(); - this.verifyListMoveEvent(TARGET_INDEX, SOURCE_INDEX); - assertTrue(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsMovedListEvent(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - } - - public void testFireItemsMovedListEventNoChange() { - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsMovedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsMovedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsMovedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsMovedListEventNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - } - - public void testFireItemsMovedList() { - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsMovedList(); - this.verifyListMoveEvent(TARGET_INDEX, SOURCE_INDEX); - assertTrue(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsMovedList(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsMovedList(); - this.verifyListMoveEvent(TARGET_INDEX, SOURCE_INDEX); - assertTrue(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsMovedList(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - } - - public void testFireItemsMovedListNoChange() { - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemsMovedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemsMovedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsMovedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemsMovedListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - } - - public void testFireItemMovedList() { - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireItemMovedList(); - this.verifyListMoveEvent(TARGET_INDEX, SOURCE_INDEX); - assertTrue(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireItemMovedList(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemMovedList(); - this.verifyListMoveEvent(TARGET_INDEX, SOURCE_INDEX); - assertTrue(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireItemMovedList(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - } - - public void testFireListClearedEvent() { - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireListClearedEvent(); - this.verifyListClearEvent(); - assertTrue(this.listClearedCalled); - - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireListClearedEvent(); - assertNull(this.listEvent); - assertFalse(this.listClearedCalled); - - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireListClearedEvent(); - this.verifyListClearEvent(); - assertTrue(this.listClearedCalled); - - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireListClearedEvent(); - assertNull(this.listEvent); - assertFalse(this.listClearedCalled); - } - - public void testFireListCleared() { - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireListCleared(); - this.verifyListClearEvent(); - assertTrue(this.listClearedCalled); - - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireListCleared(); - assertNull(this.listEvent); - assertFalse(this.listClearedCalled); - - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireListCleared(); - this.verifyListClearEvent(); - assertTrue(this.listClearedCalled); - - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireListCleared(); - assertNull(this.listEvent); - assertFalse(this.listClearedCalled); - } - - public void testFireListChangedEvent() { - this.listEvent = null; - this.listChangedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireListChangedEvent(); - this.verifyListChangeEvent(); - assertTrue(this.listChangedCalled); - - this.listEvent = null; - this.listChangedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireListChangedEvent(); - assertNull(this.listEvent); - assertFalse(this.listChangedCalled); - - this.listEvent = null; - this.listChangedCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireListChangedEvent(); - this.verifyListChangeEvent(); - assertTrue(this.listChangedCalled); - - this.listEvent = null; - this.listChangedCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireListChangedEvent(); - assertNull(this.listEvent); - assertFalse(this.listChangedCalled); - } - - public void testFireListChanged() { - this.listEvent = null; - this.listChangedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireListChanged(); - this.verifyListChangeEvent(); - assertTrue(this.listChangedCalled); - - this.listEvent = null; - this.listChangedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireListChanged(); - assertNull(this.listEvent); - assertFalse(this.listChangedCalled); - - this.listEvent = null; - this.listChangedCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireListChanged(); - this.verifyListChangeEvent(); - assertTrue(this.listChangedCalled); - - this.listEvent = null; - this.listChangedCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testFireListChanged(); - assertNull(this.listEvent); - assertFalse(this.listChangedCalled); - } - - public void testAddItemToListIndex() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testAddItemToListIndex(); - this.verifyListAddEvent(2, "joo"); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testAddItemToListIndex(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemToListIndex(); - this.verifyListAddEvent(2, "joo"); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemToListIndex(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testAddItemToList() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testAddItemToList(); - this.verifyListAddEvent(3, "joo"); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testAddItemToList(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemToList(); - this.verifyListAddEvent(3, "joo"); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemToList(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testAddItemsToListIndex() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testAddItemsToListIndex(); - this.verifyListAddEvent(2, "joo"); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testAddItemsToListIndex(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemsToListIndex(); - this.verifyListAddEvent(2, "joo"); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemsToListIndex(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testAddItemsToListIndexNoChange() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testAddItemsToListIndexNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testAddItemsToListIndexNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemsToListIndexNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemsToListIndexNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testAddItemsToList() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testAddItemsToList(); - this.verifyListAddEvent(3, "joo"); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testAddItemsToList(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemsToList(); - this.verifyListAddEvent(3, "joo"); - assertTrue(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemsToList(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testAddItemsToListNoChange() { - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testAddItemsToListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testAddItemsToListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemsToListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - - this.listEvent = null; - this.itemsAddedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testAddItemsToListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsAddedListCalled); - } - - public void testRemoveItemFromListIndex() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testRemoveItemFromListIndex(); - this.verifyListRemoveEvent(1, "bar"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testRemoveItemFromListIndex(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemFromListIndex(); - this.verifyListRemoveEvent(1, "bar"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemFromListIndex(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testRemoveItemFromList() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testRemoveItemFromList(); - this.verifyListRemoveEvent(1, "bar"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testRemoveItemFromList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemFromList(); - this.verifyListRemoveEvent(1, "bar"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemFromList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testRemoveItemsFromListIndex() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testRemoveItemsFromListIndex(); - this.verifyListRemoveEvent(1, "bar"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testRemoveItemsFromListIndex(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemsFromListIndex(); - this.verifyListRemoveEvent(1, "bar"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemsFromListIndex(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testRemoveItemsFromListIndexNoChange() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testRemoveItemsFromListIndexNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testRemoveItemsFromListIndexNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemsFromListIndexNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemsFromListIndexNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testRemoveItemsFromList() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testRemoveItemsFromList(); - this.verifyListRemoveEvent(1, "bar"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testRemoveItemsFromList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemsFromList(); - this.verifyListRemoveEvent(1, "bar"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemsFromList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testRemoveItemsFromListNoChange() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testRemoveItemsFromListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testRemoveItemsFromListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemsFromListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRemoveItemsFromListNoChange(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testRetainItemsInList() { - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testRetainItemsInList(); - this.verifyListRemoveEvent(0, "foo"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testRetainItemsInList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRetainItemsInList(); - this.verifyListRemoveEvent(0, "foo"); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testRetainItemsInList(); - assertNull(this.listEvent); - assertFalse(this.itemsRemovedListCalled); - } - - public void testReplaceItemInList() { - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testReplaceItemInList(); - this.verifyListReplaceEvent(1, "xxx", "bar"); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testReplaceItemInList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testReplaceItemInList(); - this.verifyListReplaceEvent(1, "xxx", "bar"); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testReplaceItemInList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - } - - public void testSetItemsInList() { - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testSetItemsInList(); - this.verifyListReplaceEvent(1, "xxx", "bar"); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testSetItemsInList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testSetItemsInList(); - this.verifyListReplaceEvent(1, "xxx", "bar"); - assertTrue(this.itemsReplacedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testSetItemsInList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - } - - public void testMoveItemsInList() { - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testMoveItemsInList(); - this.verifyListMoveEvent(2, 4, 2); - assertTrue(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testMoveItemsInList(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testMoveItemsInList(); - this.verifyListMoveEvent(2, 4, 2); - assertTrue(this.itemsMovedListCalled); - - this.listEvent = null; - this.itemsMovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testMoveItemsInList(); - assertNull(this.listEvent); - assertFalse(this.itemsMovedListCalled); - } - - public void testClearList() { - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testClearList(); - this.verifyListClearEvent(); - assertTrue(this.listClearedCalled); - - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testClearList(); - assertNull(this.listEvent); - assertFalse(this.listClearedCalled); - - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testClearList(); - this.verifyListClearEvent(); - assertTrue(this.listClearedCalled); - - this.listEvent = null; - this.listClearedCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testClearList(); - assertNull(this.listEvent); - assertFalse(this.listClearedCalled); - } - - public void testSynchronizeList() { - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.itemsRemovedListCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testSynchronizeList(); - assertNotNull(this.listEvent); - assertTrue(this.itemsReplacedListCalled); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.itemsRemovedListCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testSynchronizeList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - assertFalse(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.itemsRemovedListCalled = false; - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testSynchronizeList(); - assertNotNull(this.listEvent); - assertTrue(this.itemsReplacedListCalled); - assertTrue(this.itemsRemovedListCalled); - - this.listEvent = null; - this.itemsReplacedListCalled = false; - this.itemsRemovedListCalled = false; - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - this.testModel.testSynchronizeList(); - assertNull(this.listEvent); - assertFalse(this.itemsReplacedListCalled); - assertFalse(this.itemsRemovedListCalled); - } - - public void testHasAnyListChangeListeners() { - assertTrue(this.testModel.hasNoListChangeListeners(LIST_NAME)); - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.hasAnyListChangeListeners(LIST_NAME)); - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.hasNoListChangeListeners(LIST_NAME)); - - assertTrue(this.testModel.hasNoListChangeListeners(LIST_NAME)); - this.testModel.addListChangeListener(LIST_NAME, this.changeListener); - assertTrue(this.testModel.hasAnyListChangeListeners(LIST_NAME)); - this.testModel.removeListChangeListener(LIST_NAME, this.changeListener); - assertTrue(this.testModel.hasNoListChangeListeners(LIST_NAME)); - } - - public void testAddNullListListener() { - boolean exCaught = false; - try { - this.testModel.addListChangeListener("foo", null); - } catch (NullPointerException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testRemoveBogusListListener() { - boolean exCaught = false; - try { - this.testModel.removeListChangeListener("foo", this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addPropertyChangeListener("foo", this.changeListener); - exCaught = false; - try { - this.testModel.removeListChangeListener("foo", this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addListChangeListener("foo", this.changeListener); - exCaught = false; - try { - this.testModel.removeListChangeListener("foo", new ListChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - exCaught = false; - try { - this.testModel.removeListChangeListener("foo", new ListChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - private void verifyListAddEvent(int index, Object item) { - assertNotNull(this.listEvent); - assertEquals(this.testModel, this.listEvent.getSource()); - assertEquals(LIST_NAME, this.listEvent.getListName()); - assertEquals(index, ((ListAddEvent) this.listEvent).getIndex()); - assertEquals(item, ((ListAddEvent) this.listEvent).getItems().iterator().next()); - } - - private void verifyListRemoveEvent(int index, Object item) { - assertNotNull(this.listEvent); - assertEquals(this.testModel, this.listEvent.getSource()); - assertEquals(LIST_NAME, this.listEvent.getListName()); - assertEquals(index, ((ListRemoveEvent) this.listEvent).getIndex()); - assertEquals(item, ((ListRemoveEvent) this.listEvent).getItems().iterator().next()); - } - - private void verifyListReplaceEvent(int index, Object newItem, Object oldItem) { - assertNotNull(this.listEvent); - assertEquals(this.testModel, this.listEvent.getSource()); - assertEquals(LIST_NAME, this.listEvent.getListName()); - assertEquals(index, ((ListReplaceEvent) this.listEvent).getIndex()); - assertEquals(newItem, ((ListReplaceEvent) this.listEvent).getNewItems().iterator().next()); - assertEquals(oldItem, ((ListReplaceEvent) this.listEvent).getOldItems().iterator().next()); - } - - private void verifyListMoveEvent(int targetIndex, int sourceIndex) { - this.verifyListMoveEvent(targetIndex, sourceIndex, 1); - } - - private void verifyListMoveEvent(int targetIndex, int sourceIndex, int length) { - assertNotNull(this.listEvent); - assertEquals(this.testModel, this.listEvent.getSource()); - assertEquals(LIST_NAME, this.listEvent.getListName()); - assertEquals(targetIndex, ((ListMoveEvent) this.listEvent).getTargetIndex()); - assertEquals(sourceIndex, ((ListMoveEvent) this.listEvent).getSourceIndex()); - assertEquals(length, ((ListMoveEvent) this.listEvent).getLength()); - } - - private void verifyListClearEvent() { - assertNotNull(this.listEvent); - assertEquals(this.testModel, this.listEvent.getSource()); - assertEquals(LIST_NAME, this.listEvent.getListName()); - assertEquals(ListClearEvent.class, this.listEvent.getClass()); - } - - private void verifyListChangeEvent() { - assertNotNull(this.listEvent); - assertEquals(this.testModel, this.listEvent.getSource()); - assertEquals(LIST_NAME, this.listEvent.getListName()); - assertEquals(ListChangeEvent.class, this.listEvent.getClass()); - } - - - // ********** tree change tests ********** - - public void testFireNodeAddedTree() { - this.treeEvent = null; - this.nodeAddedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireNodeAddedTree(); - this.verifyTreeEvent(OBJECT_PATH); - assertTrue(this.nodeAddedCalled); - - this.treeEvent = null; - this.nodeAddedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireNodeAddedTree(); - assertNull(this.treeEvent); - assertFalse(this.nodeAddedCalled); - - this.treeEvent = null; - this.nodeAddedCalled = false; - this.testModel.addTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireNodeAddedTree(); - this.verifyTreeEvent(OBJECT_PATH); - assertTrue(this.nodeAddedCalled); - - this.treeEvent = null; - this.nodeAddedCalled = false; - this.testModel.removeTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireNodeAddedTree(); - assertNull(this.treeEvent); - assertFalse(this.nodeAddedCalled); - } - - public void testFireNodeAddedTreeEvent() { - this.treeEvent = null; - this.nodeAddedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireNodeAddedTreeEvent(); - this.verifyTreeEvent(OBJECT_PATH); - assertTrue(this.nodeAddedCalled); - - this.treeEvent = null; - this.nodeAddedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireNodeAddedTreeEvent(); - assertNull(this.treeEvent); - assertFalse(this.nodeAddedCalled); - - this.treeEvent = null; - this.nodeAddedCalled = false; - this.testModel.addTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireNodeAddedTreeEvent(); - this.verifyTreeEvent(OBJECT_PATH); - assertTrue(this.nodeAddedCalled); - - this.treeEvent = null; - this.nodeAddedCalled = false; - this.testModel.removeTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireNodeAddedTreeEvent(); - assertNull(this.treeEvent); - assertFalse(this.nodeAddedCalled); - } - - public void testFireNodeRemovedTreeEvent() { - this.treeEvent = null; - this.nodeRemovedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireNodeRemovedTreeEvent(); - this.verifyTreeEvent(OBJECT_PATH); - assertTrue(this.nodeRemovedCalled); - - this.treeEvent = null; - this.nodeRemovedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireNodeRemovedTreeEvent(); - assertNull(this.treeEvent); - assertFalse(this.nodeRemovedCalled); - - this.treeEvent = null; - this.nodeRemovedCalled = false; - this.testModel.addTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireNodeRemovedTreeEvent(); - this.verifyTreeEvent(OBJECT_PATH); - assertTrue(this.nodeRemovedCalled); - - this.treeEvent = null; - this.nodeRemovedCalled = false; - this.testModel.removeTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireNodeRemovedTreeEvent(); - assertNull(this.treeEvent); - assertFalse(this.nodeRemovedCalled); - } - - public void testFireNodeRemovedTree() { - this.treeEvent = null; - this.nodeRemovedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireNodeRemovedTree(); - this.verifyTreeEvent(OBJECT_PATH); - assertTrue(this.nodeRemovedCalled); - - this.treeEvent = null; - this.nodeRemovedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireNodeRemovedTree(); - assertNull(this.treeEvent); - assertFalse(this.nodeRemovedCalled); - - this.treeEvent = null; - this.nodeRemovedCalled = false; - this.testModel.addTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireNodeRemovedTree(); - this.verifyTreeEvent(OBJECT_PATH); - assertTrue(this.nodeRemovedCalled); - - this.treeEvent = null; - this.nodeRemovedCalled = false; - this.testModel.removeTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireNodeRemovedTree(); - assertNull(this.treeEvent); - assertFalse(this.nodeRemovedCalled); - } - - public void testFireTreeClearedEvent() { - this.treeEvent = null; - this.treeClearedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireTreeClearedEvent(); - this.verifyTreeEvent(null); - assertTrue(this.treeClearedCalled); - - this.treeEvent = null; - this.treeClearedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireTreeClearedEvent(); - assertNull(this.treeEvent); - assertFalse(this.treeClearedCalled); - - this.treeEvent = null; - this.treeClearedCalled = false; - this.testModel.addTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireTreeClearedEvent(); - this.verifyTreeEvent(null); - assertTrue(this.treeClearedCalled); - - this.treeEvent = null; - this.treeClearedCalled = false; - this.testModel.removeTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireTreeClearedEvent(); - assertNull(this.treeEvent); - assertFalse(this.treeClearedCalled); - } - - public void testFireTreeCleared() { - this.treeEvent = null; - this.treeClearedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireTreeCleared(); - this.verifyTreeEvent(null); - assertTrue(this.treeClearedCalled); - - this.treeEvent = null; - this.treeClearedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireTreeCleared(); - assertNull(this.treeEvent); - assertFalse(this.treeClearedCalled); - - this.treeEvent = null; - this.treeClearedCalled = false; - this.testModel.addTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireTreeCleared(); - this.verifyTreeEvent(null); - assertTrue(this.treeClearedCalled); - - this.treeEvent = null; - this.treeClearedCalled = false; - this.testModel.removeTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireTreeCleared(); - assertNull(this.treeEvent); - assertFalse(this.treeClearedCalled); - } - - public void testFireTreeChangedEvent() { - this.treeEvent = null; - this.treeChangedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireTreeChangedEvent(); - this.verifyTreeEvent(null); - assertTrue(this.treeChangedCalled); - - this.treeEvent = null; - this.treeChangedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireTreeChangedEvent(); - assertNull(this.treeEvent); - assertFalse(this.treeChangedCalled); - - this.treeEvent = null; - this.treeChangedCalled = false; - this.testModel.addTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireTreeChangedEvent(); - this.verifyTreeEvent(null); - assertTrue(this.treeChangedCalled); - - this.treeEvent = null; - this.treeChangedCalled = false; - this.testModel.removeTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireTreeChangedEvent(); - assertNull(this.treeEvent); - assertFalse(this.treeChangedCalled); - } - - public void testFireTreeChanged() { - this.treeEvent = null; - this.treeChangedCalled = false; - this.testModel.addChangeListener(this.changeListener); - this.testModel.testFireTreeChanged(); - this.verifyTreeEvent(null); - assertTrue(this.treeChangedCalled); - - this.treeEvent = null; - this.treeChangedCalled = false; - this.testModel.removeChangeListener(this.changeListener); - this.testModel.testFireTreeChanged(); - assertNull(this.treeEvent); - assertFalse(this.treeChangedCalled); - - this.treeEvent = null; - this.treeChangedCalled = false; - this.testModel.addTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireTreeChanged(); - this.verifyTreeEvent(null); - assertTrue(this.treeChangedCalled); - - this.treeEvent = null; - this.treeChangedCalled = false; - this.testModel.removeTreeChangeListener(TREE_NAME, this.changeListener); - this.testModel.testFireTreeChanged(); - assertNull(this.treeEvent); - assertFalse(this.treeChangedCalled); - } - - public void testHasAnyTreeChangeListeners() { - assertTrue(this.testModel.hasNoTreeChangeListeners(TREE_NAME)); - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.hasAnyTreeChangeListeners(TREE_NAME)); - this.testModel.removeChangeListener(this.changeListener); - assertTrue(this.testModel.hasNoTreeChangeListeners(TREE_NAME)); - - assertTrue(this.testModel.hasNoTreeChangeListeners(TREE_NAME)); - this.testModel.addTreeChangeListener(TREE_NAME, this.changeListener); - assertTrue(this.testModel.hasAnyTreeChangeListeners(TREE_NAME)); - this.testModel.removeTreeChangeListener(TREE_NAME, this.changeListener); - assertTrue(this.testModel.hasNoTreeChangeListeners(TREE_NAME)); - } - - public void testAddNullTreeListener() { - boolean exCaught = false; - try { - this.testModel.addTreeChangeListener("foo", null); - } catch (NullPointerException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testRemoveBogusTreeListener() { - boolean exCaught = false; - try { - this.testModel.removeTreeChangeListener("foo", this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addPropertyChangeListener("foo", this.changeListener); - exCaught = false; - try { - this.testModel.removeTreeChangeListener("foo", this.changeListener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - this.testModel.addTreeChangeListener("foo", this.changeListener); - exCaught = false; - try { - this.testModel.removeTreeChangeListener("foo", new TreeChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - - exCaught = false; - try { - this.testModel.removeTreeChangeListener("foo", new TreeChangeAdapter()); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - private void verifyTreeEvent(List<?> path) { - assertNotNull(this.treeEvent); - assertEquals(this.testModel, this.treeEvent.getSource()); - assertEquals(TREE_NAME, this.treeEvent.getTreeName()); - assertEquals(path, this.getListPath()); - } - - private List<?> getListPath() { - Iterable<?> iterable = this.getPath(); - return (iterable == null) ? null : CollectionTools.list(iterable); - } - - private Iterable<?> getPath() { - if (this.treeEvent instanceof TreeAddEvent) { - return ((TreeAddEvent) this.treeEvent).getPath(); - } - if (this.treeEvent instanceof TreeRemoveEvent) { - return ((TreeRemoveEvent) this.treeEvent).getPath(); - } - return null; - } - - - - // ********** convenience method tests ********** - - public void testElementsAreEqual() { - Collection<String> c1 = new ArrayList<String>(); - c1.add("foo"); - c1.add("bar"); - c1.add("baz"); - Collection<String> c2 = new ArrayList<String>(); - c2.add("foo"); - c2.add("bar"); - c2.add("baz"); - assertTrue(this.testModel.testElementsAreEqual(c1, c2)); - } - - public void testElementsAreDifferent() { - Collection<String> c1 = new ArrayList<String>(); - c1.add("foo"); - c1.add("bar"); - c1.add("baz"); - Collection<String> c2 = new ArrayList<String>(); - c2.add("baz"); - c2.add("bar"); - c2.add("foo"); - assertTrue(this.testModel.testElementsAreDifferent(c1, c2)); - } - - - // ********** AbstractModel tests ********** - - public void testAbstractModelValuesAreEqual1() { - assertTrue(this.testModel.testValuesAreEqual(null, null)); - } - - public void testAbstractModelValuesAreEqual2() { - assertTrue(this.testModel.testValuesAreEqual("foo", "foo")); - } - - public void testAbstractModelValuesAreEqual3() { - assertFalse(this.testModel.testValuesAreEqual("foo", null)); - } - - public void testAbstractModelValuesAreEqual4() { - assertFalse(this.testModel.testValuesAreEqual(null, "foo")); - } - - public void testAbstractModelValuesAreEqual5() { - assertFalse(this.testModel.testValuesAreEqual("bar", "foo")); - } - - public void testAbstractModelValuesAreDifferent1() { - assertFalse(this.testModel.testValuesAreDifferent(null, null)); - } - - public void testAbstractModelValuesAreDifferent2() { - assertFalse(this.testModel.testValuesAreDifferent("foo", "foo")); - } - - public void testAbstractModelValuesAreDifferent3() { - assertTrue(this.testModel.testValuesAreDifferent("foo", null)); - } - - public void testAbstractModelValuesAreDifferent4() { - assertTrue(this.testModel.testValuesAreDifferent(null, "foo")); - } - - public void testAbstractModelValuesAreDifferent5() { - assertTrue(this.testModel.testValuesAreDifferent("bar", "foo")); - } - - public void testAbstractModelAttributeValueHasChanged1() { - assertFalse(this.testModel.testAttributeValueHasChanged(null, null)); - } - - public void testAbstractModelAttributeValueHasChanged2() { - assertFalse(this.testModel.testAttributeValueHasChanged("foo", "foo")); - } - - public void testAbstractModelAttributeValueHasChanged3() { - assertTrue(this.testModel.testAttributeValueHasChanged("foo", null)); - } - - public void testAbstractModelAttributeValueHasChanged4() { - assertTrue(this.testModel.testAttributeValueHasChanged(null, "foo")); - } - - public void testAbstractModelAttributeValueHasChanged5() { - assertTrue(this.testModel.testAttributeValueHasChanged("bar", "foo")); - } - - public void testAbstractModelAttributeValueHasNotChanged1() { - assertTrue(this.testModel.testAttributeValueHasNotChanged(null, null)); - } - - public void testAbstractModelAttributeValueHasNotChanged2() { - assertTrue(this.testModel.testAttributeValueHasNotChanged("foo", "foo")); - } - - public void testAbstractModelAttributeValueHasNotChanged3() { - assertFalse(this.testModel.testAttributeValueHasNotChanged("foo", null)); - } - - public void testAbstractModelAttributeValueHasNotChanged4() { - assertFalse(this.testModel.testAttributeValueHasNotChanged(null, "foo")); - } - - public void testAbstractModelAttributeValueHasNotChanged5() { - assertFalse(this.testModel.testAttributeValueHasNotChanged("bar", "foo")); - } - - public void testAbstractModelClone() { - assertFalse(this.testModel.hasAnyPropertyChangeListeners(PROPERTY_NAME)); - this.testModel.addChangeListener(this.changeListener); - assertTrue(this.testModel.hasAnyPropertyChangeListeners(PROPERTY_NAME)); - - // verify that the clone does not have any listeners - TestModel clone = this.testModel.clone(); - assertFalse(clone.hasAnyPropertyChangeListeners(PROPERTY_NAME)); - clone.addChangeListener(this.changeListener); - assertTrue(clone.hasAnyPropertyChangeListeners(PROPERTY_NAME)); - // check original - assertTrue(this.testModel.hasAnyPropertyChangeListeners(PROPERTY_NAME)); - - // now test events fired by original - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - this.testModel.testFirePropertyChangedObjectObject(); - this.verifyPropertyChangeEvent(OLD_OBJECT_VALUE, NEW_OBJECT_VALUE); - assertTrue(this.propertyChangeCalled); - - // now test events fired by clone - this.propertyChangeEvent = null; - this.propertyChangeCalled = false; - clone.testFirePropertyChangedObjectObject(); - this.verifyPropertyChangeEvent(clone, OLD_OBJECT_VALUE, NEW_OBJECT_VALUE); - assertTrue(this.propertyChangeCalled); - } - - public void testAbstractModelToString() { - assertTrue(this.testModel.toString().contains('(' + TEST_TO_STRING + ')')); - } - - - // ********** listener implementations ********** - - class Adapter implements ChangeListener { - public void stateChanged(StateChangeEvent e) { - ChangeSupportTests.this.stateChangedCalled = true; - ChangeSupportTests.this.stateChangeEvent = e; - } - - public void propertyChanged(PropertyChangeEvent e) { - ChangeSupportTests.this.propertyChangeCalled = true; - ChangeSupportTests.this.propertyChangeEvent = e; - } - - - public void itemsAdded(CollectionAddEvent e) { - ChangeSupportTests.this.itemsAddedCollectionCalled = true; - ChangeSupportTests.this.collectionEvent = e; - } - public void itemsRemoved(CollectionRemoveEvent e) { - ChangeSupportTests.this.itemsRemovedCollectionCalled = true; - ChangeSupportTests.this.collectionEvent = e; - } - public void collectionCleared(CollectionClearEvent e) { - ChangeSupportTests.this.collectionClearedCalled = true; - ChangeSupportTests.this.collectionEvent = e; - } - public void collectionChanged(CollectionChangeEvent e) { - ChangeSupportTests.this.collectionChangedCalled = true; - ChangeSupportTests.this.collectionEvent = e; - } - - public void itemsAdded(ListAddEvent e) { - ChangeSupportTests.this.itemsAddedListCalled = true; - ChangeSupportTests.this.listEvent = e; - } - public void itemsRemoved(ListRemoveEvent e) { - ChangeSupportTests.this.itemsRemovedListCalled = true; - ChangeSupportTests.this.listEvent = e; - } - public void itemsReplaced(ListReplaceEvent e) { - ChangeSupportTests.this.itemsReplacedListCalled = true; - ChangeSupportTests.this.listEvent = e; - } - public void itemsMoved(ListMoveEvent e) { - ChangeSupportTests.this.itemsMovedListCalled = true; - ChangeSupportTests.this.listEvent = e; - } - public void listCleared(ListClearEvent e) { - ChangeSupportTests.this.listClearedCalled = true; - ChangeSupportTests.this.listEvent = e; - } - public void listChanged(ListChangeEvent e) { - ChangeSupportTests.this.listChangedCalled = true; - ChangeSupportTests.this.listEvent = e; - } - - public void nodeAdded(TreeAddEvent e) { - ChangeSupportTests.this.nodeAddedCalled = true; - ChangeSupportTests.this.treeEvent = e; - } - public void nodeRemoved(TreeRemoveEvent e) { - ChangeSupportTests.this.nodeRemovedCalled = true; - ChangeSupportTests.this.treeEvent = e; - } - public void treeCleared(TreeClearEvent e) { - ChangeSupportTests.this.treeClearedCalled = true; - ChangeSupportTests.this.treeEvent = e; - } - public void treeChanged(TreeChangeEvent e) { - ChangeSupportTests.this.treeChangedCalled = true; - ChangeSupportTests.this.treeEvent = e; - } - } - - - // ********** inner class ********** - - private static class TestModel extends AbstractModel implements Cloneable { - TestModel() { - super(); - } - - // ***** state - public void testFireStateChange() { - this.fireStateChanged(); - } - - // ***** property - public void testFirePropertyChangedEvent() { - this.firePropertyChanged(new PropertyChangeEvent(this, PROPERTY_NAME, OLD_OBJECT_VALUE, NEW_OBJECT_VALUE)); - } - - public void testFirePropertyChangedEventNoChange() { - this.firePropertyChanged(new PropertyChangeEvent(this, PROPERTY_NAME, OLD_OBJECT_VALUE, OLD_OBJECT_VALUE)); - } - - public void testFirePropertyChangedObjectObject() { - this.firePropertyChanged(PROPERTY_NAME, OLD_OBJECT_VALUE, NEW_OBJECT_VALUE); - } - - public void testFirePropertyChangedObjectObjectNoChange() { - this.firePropertyChanged(PROPERTY_NAME, OLD_OBJECT_VALUE, OLD_OBJECT_VALUE); - } - - public void testFirePropertyChangedObject() { - this.firePropertyChanged(PROPERTY_NAME, NEW_OBJECT_VALUE); - } - - public void testFirePropertyChangedObjectNoChange() { - this.firePropertyChanged(PROPERTY_NAME, null); - } - - public void testFirePropertyChangedIntInt() { - this.firePropertyChanged(PROPERTY_NAME, OLD_INT_VALUE.intValue(), NEW_INT_VALUE.intValue()); - } - - public void testFirePropertyChangedIntIntNoChange() { - this.firePropertyChanged(PROPERTY_NAME, OLD_INT_VALUE.intValue(), OLD_INT_VALUE.intValue()); - } - - public void testFirePropertyChangedBooleanBoolean() { - this.firePropertyChanged(PROPERTY_NAME, OLD_BOOLEAN_VALUE.booleanValue(), NEW_BOOLEAN_VALUE.booleanValue()); - } - - public void testFirePropertyChangedBooleanBooleanNoChange() { - this.firePropertyChanged(PROPERTY_NAME, OLD_BOOLEAN_VALUE.booleanValue(), OLD_BOOLEAN_VALUE.booleanValue()); - } - - // ***** collection - public void testFireItemsAddedCollectionEvent() { - this.fireItemsAdded(new CollectionAddEvent(this, COLLECTION_NAME, ADDED_OBJECT_VALUE)); - } - - public void testFireItemsAddedCollectionEventNoChange() { - this.fireItemsAdded(new CollectionAddEvent(this, COLLECTION_NAME, Collections.emptySet())); - } - - public void testFireItemsAddedCollection() { - this.fireItemsAdded(COLLECTION_NAME, Collections.singleton(ADDED_OBJECT_VALUE)); - } - - public void testFireItemsAddedCollectionNoChange() { - this.fireItemsAdded(COLLECTION_NAME, Collections.emptySet()); - } - - public void testFireItemAddedCollection() { - this.fireItemAdded(COLLECTION_NAME, ADDED_OBJECT_VALUE); - } - - public void testFireItemsRemovedCollectionEvent() { - this.fireItemsRemoved(new CollectionRemoveEvent(this, COLLECTION_NAME, REMOVED_OBJECT_VALUE)); - } - - public void testFireItemsRemovedCollectionEventNoChange() { - this.fireItemsRemoved(new CollectionRemoveEvent(this, COLLECTION_NAME, Collections.emptySet())); - } - - public void testFireItemsRemovedCollection() { - this.fireItemsRemoved(COLLECTION_NAME, Collections.singleton(REMOVED_OBJECT_VALUE)); - } - - public void testFireItemsRemovedCollectionNoChange() { - this.fireItemsRemoved(COLLECTION_NAME, Collections.emptySet()); - } - - public void testFireItemRemovedCollection() { - this.fireItemRemoved(COLLECTION_NAME, REMOVED_OBJECT_VALUE); - } - - public void testFireCollectionCleared() { - this.fireCollectionCleared(COLLECTION_NAME); - } - - public void testFireCollectionChangedEvent() { - this.fireCollectionChanged(new CollectionChangeEvent(this, COLLECTION_NAME, Collections.emptySet())); - } - - public void testFireCollectionChanged() { - this.fireCollectionChanged(COLLECTION_NAME, Collections.emptySet()); - } - - public boolean testAddItemToCollection() { - return this.addItemToCollection(ADDED_OBJECT_VALUE, new ArrayList<Object>(), COLLECTION_NAME); - } - - public boolean testAddItemToCollectionNoChange() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(ADDED_OBJECT_VALUE); - return this.addItemToCollection(ADDED_OBJECT_VALUE, collection, COLLECTION_NAME); - } - - public boolean testAddItemsToCollection() { - return this.addItemsToCollection(Collections.singleton(ADDED_OBJECT_VALUE), new ArrayList<Object>(), COLLECTION_NAME); - } - - public boolean testAddItemsToCollectionNoChange() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(ADDED_OBJECT_VALUE); - return this.addItemsToCollection(Collections.singleton(ADDED_OBJECT_VALUE), collection, COLLECTION_NAME); - } - - public boolean testAddItemsToCollectionMixed() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(ADDED_OBJECT_VALUE); - return this.addItemsToCollection(new Object[] {ADDED_OBJECT_VALUE, ADDED_OBJECT_VALUE_2}, collection, COLLECTION_NAME); - } - - public boolean testRemoveItemFromCollection() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(REMOVED_OBJECT_VALUE); - return this.removeItemFromCollection(REMOVED_OBJECT_VALUE, collection, COLLECTION_NAME); - } - - public boolean testRemoveItemFromCollectionNoChange() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(REMOVED_OBJECT_VALUE); - return this.removeItemFromCollection("foo", collection, COLLECTION_NAME); - } - - public boolean testRemoveItemsFromCollection() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(REMOVED_OBJECT_VALUE); - collection.add("foo"); - collection.add("bar"); - return this.removeItemsFromCollection(new Object[] {"foo", "bar", REMOVED_OBJECT_VALUE}, collection, COLLECTION_NAME); - } - - public boolean testRemoveItemsFromCollectionNoChange1() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(REMOVED_OBJECT_VALUE); - return this.removeItemsFromCollection(Collections.emptySet(), collection, COLLECTION_NAME); - } - - public boolean testRemoveItemsFromCollectionNoChange2() { - Collection<Object> collection = new HashSet<Object>(); - return this.removeItemsFromCollection(Collections.singleton("foo"), collection, COLLECTION_NAME); - } - - public boolean testRemoveItemsFromCollectionNoChange3() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(REMOVED_OBJECT_VALUE); - return this.removeItemsFromCollection(Collections.singleton("foo"), collection, COLLECTION_NAME); - } - - public boolean testRetainItemsInCollection1() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(REMOVED_OBJECT_VALUE); - collection.add("foo"); - collection.add("bar"); - return this.retainItemsInCollection(new Object[] {"foo", "bar"}, collection, COLLECTION_NAME); - } - - public boolean testRetainItemsInCollection2() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(REMOVED_OBJECT_VALUE); - collection.add("foo"); - collection.add("bar"); - return this.retainItemsInCollection(Collections.emptySet(), collection, COLLECTION_NAME); - } - - public boolean testRetainItemsInCollectionNoChange1() { - Collection<Object> collection = new HashSet<Object>(); - return this.retainItemsInCollection(new Object[] {"foo", "bar"}, collection, COLLECTION_NAME); - } - - public boolean testRetainItemsInCollectionNoChange2() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(REMOVED_OBJECT_VALUE); - collection.add("foo"); - collection.add("bar"); - return this.retainItemsInCollection(new Object[] {"foo", "bar", REMOVED_OBJECT_VALUE}, collection, COLLECTION_NAME); - } - - public boolean testClearCollection() { - Collection<Object> collection = new HashSet<Object>(); - collection.add(REMOVED_OBJECT_VALUE); - collection.add("foo"); - collection.add("bar"); - return this.clearCollection(collection, COLLECTION_NAME); - } - - public boolean testClearCollectionNoChange() { - Collection<Object> collection = new HashSet<Object>(); - return this.clearCollection(collection, COLLECTION_NAME); - } - - public boolean testSynchronizeCollection1() { - Collection<Object> collection = new HashSet<Object>(); - collection.add("foo"); - collection.add("bar"); - collection.add("baz"); - Collection<Object> newCollection = new HashSet<Object>(); - newCollection.add("joo"); - newCollection.add("jar"); - newCollection.add("baz"); - boolean result = this.synchronizeCollection(newCollection, collection, COLLECTION_NAME); - assertEquals(newCollection, collection); - return result; - } - - public boolean testSynchronizeCollection2() { - Collection<Object> collection = new HashSet<Object>(); - collection.add("foo"); - collection.add("bar"); - collection.add("baz"); - Collection<Object> newCollection = new HashSet<Object>(); - boolean result = this.synchronizeCollection(newCollection, collection, COLLECTION_NAME); - assertEquals(newCollection, collection); - return result; - } - - public boolean testSynchronizeCollection3() { - Collection<Object> collection = new HashSet<Object>(); - Collection<Object> newCollection = new HashSet<Object>(); - newCollection.add("joo"); - newCollection.add("jar"); - newCollection.add("baz"); - boolean result = this.synchronizeCollection(newCollection, collection, COLLECTION_NAME); - assertEquals(newCollection, collection); - return result; - } - - // ***** list - public void testFireItemsAddedListEvent() { - this.fireItemsAdded(new ListAddEvent(this, LIST_NAME, ADD_INDEX, ADDED_OBJECT_VALUE)); - } - - public void testFireItemsAddedListEventNoChange() { - this.fireItemsAdded(new ListAddEvent(this, LIST_NAME, ADD_INDEX, Collections.emptyList())); - } - - public void testFireItemsAddedList() { - this.fireItemsAdded(LIST_NAME, ADD_INDEX, Collections.singletonList(ADDED_OBJECT_VALUE)); - } - - public void testFireItemsAddedListNoChange() { - this.fireItemsAdded(LIST_NAME, ADD_INDEX, Collections.emptyList()); - } - - public void testFireItemAddedList() { - this.fireItemAdded(LIST_NAME, ADD_INDEX, ADDED_OBJECT_VALUE); - } - - public void testFireItemsRemovedListEvent() { - this.fireItemsRemoved(new ListRemoveEvent(this, LIST_NAME, REMOVE_INDEX, REMOVED_OBJECT_VALUE)); - } - - public void testFireItemsRemovedListEventNoChange() { - this.fireItemsRemoved(new ListRemoveEvent(this, LIST_NAME, REMOVE_INDEX, Collections.emptyList())); - } - - public void testFireItemsRemovedList() { - this.fireItemsRemoved(LIST_NAME, REMOVE_INDEX, Collections.singletonList(REMOVED_OBJECT_VALUE)); - } - - public void testFireItemsRemovedListNoChange() { - this.fireItemsRemoved(LIST_NAME, REMOVE_INDEX, Collections.emptyList()); - } - - public void testFireItemRemovedList() { - this.fireItemRemoved(LIST_NAME, REMOVE_INDEX, REMOVED_OBJECT_VALUE); - } - - public void testFireItemsReplacedListEvent() { - this.fireItemsReplaced(new ListReplaceEvent(this, LIST_NAME, REPLACE_INDEX, ADDED_OBJECT_VALUE, REMOVED_OBJECT_VALUE)); - } - - public void testFireItemsReplacedListEventNoChange() { - this.fireItemsReplaced(new ListReplaceEvent(this, LIST_NAME, REPLACE_INDEX, Collections.emptyList(), Collections.emptyList())); - } - - public void testFireItemsReplacedList() { - this.fireItemsReplaced(LIST_NAME, REPLACE_INDEX, Collections.singletonList(ADDED_OBJECT_VALUE), Collections.singletonList(REMOVED_OBJECT_VALUE)); - } - - public void testFireItemsReplacedListNoChange() { - this.fireItemsReplaced(LIST_NAME, REPLACE_INDEX, Collections.emptyList(), Collections.emptyList()); - } - - public void testFireItemReplacedList() { - this.fireItemReplaced(LIST_NAME, REPLACE_INDEX, ADDED_OBJECT_VALUE, REMOVED_OBJECT_VALUE); - } - - public void testFireItemsMovedListEvent() { - this.fireItemsMoved(new ListMoveEvent(this, LIST_NAME, TARGET_INDEX, SOURCE_INDEX, 1)); - } - - public void testFireItemsMovedListEventNoChange() { - this.fireItemsMoved(new ListMoveEvent(this, LIST_NAME, SOURCE_INDEX, SOURCE_INDEX, 1)); - } - - public void testFireItemsMovedList() { - this.fireItemsMoved(LIST_NAME, TARGET_INDEX, SOURCE_INDEX, 1); - } - - public void testFireItemsMovedListNoChange() { - this.fireItemsMoved(LIST_NAME, SOURCE_INDEX, SOURCE_INDEX, 1); - } - - public void testFireItemMovedList() { - this.fireItemMoved(LIST_NAME, TARGET_INDEX, SOURCE_INDEX); - } - - public void testFireListClearedEvent() { - this.fireListCleared(new ListClearEvent(this, LIST_NAME)); - } - - public void testFireListCleared() { - this.fireListCleared(LIST_NAME); - } - - public void testFireListChangedEvent() { - this.fireListChanged(new ListChangeEvent(this, LIST_NAME, Collections.emptyList())); - } - - public void testFireListChanged() { - this.fireListChanged(LIST_NAME, Collections.emptyList()); - } - - public void testAddItemToListIndex() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.addItemToList(2, "joo", list, LIST_NAME); - } - - public void testAddItemToList() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.addItemToList("joo", list, LIST_NAME); - } - - public void testAddItemsToListIndex() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.addItemsToList(2, Collections.singletonList("joo"), list, LIST_NAME); - } - - public void testAddItemsToListIndexNoChange() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.addItemsToList(2, Collections.<String>emptyList(), list, LIST_NAME); - } - - public void testAddItemsToList() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.addItemsToList(Collections.singletonList("joo"), list, LIST_NAME); - } - - public void testAddItemsToListNoChange() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.addItemsToList(Collections.<String>emptyList(), list, LIST_NAME); - } - - public void testRemoveItemFromListIndex() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.removeItemFromList(1, list, LIST_NAME); - } - - public void testRemoveItemFromList() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.removeItemFromList("bar", list, LIST_NAME); - } - - public void testRemoveItemsFromListIndex() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.removeItemsFromList(1, 1, list, LIST_NAME); - } - - public void testRemoveItemsFromListIndexNoChange() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.removeItemsFromList(2, 0, list, LIST_NAME); - } - - public void testRemoveItemsFromList() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.removeItemsFromList(Collections.singletonList("bar"), list, LIST_NAME); - } - - public void testRemoveItemsFromListNoChange() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.addItemsToList(Collections.<String>emptyList(), list, LIST_NAME); - } - - public void testRetainItemsInList() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.retainItemsInList(new String[] {"bar", "baz"}, list, LIST_NAME); - } - - public void testReplaceItemInList() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.replaceItemInList("bar", "xxx", list, LIST_NAME); - } - - public void testSetItemsInList() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.setItemsInList(1, new String[] {"xxx"}, list, LIST_NAME); - } - - public void testMoveItemsInList() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - list.add("xxx"); - list.add("yyy"); - list.add("zzz"); - this.moveItemsInList(2, 4, 2, list, LIST_NAME); - } - - public void testClearList() { - List<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - list.add("baz"); - this.clearList(list, LIST_NAME); - } - - public void testSynchronizeList() { - List<String> oldList = new ArrayList<String>(); - oldList.add("foo"); - oldList.add("bar"); - oldList.add("baz"); - oldList.add("xxx"); - oldList.add("yyy"); - oldList.add("zzz"); - List<String> newList = new ArrayList<String>(); - newList.add("foo"); - newList.add("ppp"); - newList.add("baz"); - newList.add("xxx"); - newList.add("qqq"); - this.synchronizeList(newList, oldList, LIST_NAME); - assertEquals(newList, oldList); - } - - // ***** tree - public void testFireNodeAddedTreeEvent() { - this.fireNodeAdded(new TreeAddEvent(this, TREE_NAME, OBJECT_PATH)); - } - - public void testFireNodeAddedTree() { - this.fireNodeAdded(TREE_NAME, OBJECT_PATH); - } - - public void testFireNodeRemovedTreeEvent() { - this.fireNodeRemoved(new TreeRemoveEvent(this, TREE_NAME, OBJECT_PATH)); - } - - public void testFireNodeRemovedTree() { - this.fireNodeRemoved(TREE_NAME, OBJECT_PATH); - } - - public void testFireTreeClearedEvent() { - this.fireTreeCleared(new TreeClearEvent(this, TREE_NAME)); - } - - public void testFireTreeCleared() { - this.fireTreeCleared(TREE_NAME); - } - - public void testFireTreeChangedEvent() { - this.fireTreeChanged(new TreeChangeEvent(this, TREE_NAME, OBJECT_PATH)); - } - - public void testFireTreeChanged() { - this.fireTreeChanged(TREE_NAME, OBJECT_PATH); - } - - public boolean testAttributeValueHasChanged(Object value1, Object value2) { - return this.attributeValueHasChanged(value1, value2); - } - - public boolean testAttributeValueHasNotChanged(Object value1, Object value2) { - return this.attributeValueHasNotChanged(value1, value2); - } - - // ***** misc - @Override - public TestModel clone() { - try { - return (TestModel) super.clone(); - } catch (CloneNotSupportedException ex) { - throw new InternalError(); - } - } - - public boolean testValuesAreDifferent(Object value1, Object value2) { - return this.valuesAreDifferent(value1, value2); - } - - public boolean testValuesAreEqual(Object value1, Object value2) { - return this.valuesAreEqual(value1, value2); - } - - public boolean testElementsAreDifferent(Iterable<?> iterable1, Iterable<?> iterable2) { - return this.getChangeSupport().elementsAreDifferent(iterable1, iterable2); - } - - public boolean testElementsAreEqual(Iterable<?> iterable1, Iterable<?> iterable2) { - return this.getChangeSupport().elementsAreEqual(iterable1, iterable2); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(TEST_TO_STRING); - } - - } - - - // ********** serialization test ********** - //TODO - This test doesn't pass in the Eclipse build environment (Linux) for some reason -// public void testSerialization() throws java.io.IOException, ClassNotFoundException { -// LocalModel model1 = new LocalModel(); -// Foo foo1 = new Foo(); -// Bar bar1 = new Bar(); -// Joo joo1 = new Joo(); -// Jar jar1 = new Jar(); -// model1.addStateChangeListener(foo1); -// model1.addStateChangeListener(bar1); -// model1.addListChangeListener(joo1); -// model1.addListChangeListener(jar1); -// -// ChangeListener[] listeners1 = this.getListeners(model1, StateChangeListener.class); -// assertEquals(2, listeners1.length); -// // the order of these could change... -// assertEquals(Foo.class, listeners1[0].getClass()); -// assertEquals(Bar.class, listeners1[1].getClass()); -// -// listeners1 = this.getListeners(model1, ListChangeListener.class); -// assertEquals(2, listeners1.length); -// // the order of these could change... -// assertEquals(Joo.class, listeners1[0].getClass()); -// assertEquals(Jar.class, listeners1[1].getClass()); -// -// LocalModel model2 = TestTools.serialize(model1); -// -// ChangeListener[] listeners2 = this.getListeners(model2, StateChangeListener.class); -// assertEquals(1, listeners2.length); -// assertEquals(Foo.class, listeners2[0].getClass()); -// -// listeners2 = this.getListeners(model2, ListChangeListener.class); -// assertEquals(1, listeners2.length); -// assertEquals(Joo.class, listeners2[0].getClass()); -// } -// -// private ChangeListener[] getListeners(LocalModel model, Class<? extends ChangeListener> listenerClass) { -// ChangeSupport changeSupport = (ChangeSupport) ClassTools.fieldValue(model, "changeSupport"); -// return (ChangeListener[]) ClassTools.executeMethod(changeSupport, "getListeners", Class.class, listenerClass); -// } -// -// private static class LocalModel extends AbstractModel { -// LocalModel() { -// super(); -// } -// } -// -// private static class Foo implements Serializable, StateChangeListener { -// Foo() { -// super(); -// } -// public void stateChanged(StateChangeEvent event) { -// // do nothing -// } -// } -// -// private static class Bar implements StateChangeListener { -// Bar() { -// super(); -// } -// public void stateChanged(StateChangeEvent event) { -// // do nothing -// } -// } -// -// private static class Joo extends ListChangeAdapter implements Serializable { -//// private static final ObjectStreamField[] serialPersistentFields = {new ObjectStreamField("changeSupport", ChangeSupport.class)}; -// Joo() { -// super(); -// } -// } -// -// private static class Jar extends ListChangeAdapter { -// Jar() { -// super(); -// } -// } - - - // ********** bug(?) test ********** - - private static final String ISE_MESSAGE = "this object is no longer listening to localA"; - - /** - * Test the following situation: - * - both B and C are listening to A - * - C is also listening to B - * - when B receives an event from A, it will fire an event to C - * - when C receives an event from B, it will STOP listening to A - * - the event from B to C may be preceded or followed (depending on - * the hash positions of listeners) by an event from A to C: - * - if the A to C event comes first, no problem - * - but if the A to B event comes first, the A to C event should NOT happen - */ - public void testIndirectRemoveStateListener() { - this.verifyIndirectRemoveListener( - new NotifyCommand() { - public void notifyListeners(LocalA localA) { - localA.notifyStateListeners(); - } - } - ); - } - - public void testIndirectRemovePropertyListener() { - this.verifyIndirectRemoveListener( - new NotifyCommand() { - public void notifyListeners(LocalA localA) { - localA.notifyPropertyListeners(); - } - } - ); - } - - public void testIndirectRemoveCollectionListener() { - this.verifyIndirectRemoveListener( - new NotifyCommand() { - public void notifyListeners(LocalA localA) { - localA.notifyCollectionListeners(); - } - } - ); - } - - public void testIndirectRemoveListListener() { - this.verifyIndirectRemoveListener( - new NotifyCommand() { - public void notifyListeners(LocalA localA) { - localA.notifyListListeners(); - } - } - ); - } - - public void testIndirectRemoveTreeListener() { - this.verifyIndirectRemoveListener( - new NotifyCommand() { - public void notifyListeners(LocalA localA) { - localA.notifyTreeListeners(); - } - } - ); - } - - public void verifyIndirectRemoveListener(NotifyCommand command) { - LocalA localA = new LocalA(); - LocalB localB = new LocalB(localA); - - // build a bunch of LocalCs so at least one of them is notified AFTER the LocalB; - // using 1000 seemed to fail very consistently before ChangeSupport was fixed - LocalC[] localCs = new LocalC[1000]; - for (int i = localCs.length; i-- > 0; ) { - localCs[i] = new LocalC(localA, localB); - } - - boolean exCaught = false; - try { - command.notifyListeners(localA); - } catch (IllegalStateException ex) { - if (ex.getMessage() == ISE_MESSAGE) { - exCaught = true; - } else { - throw ex; - } - } - assertFalse(exCaught); - - for (int i = localCs.length; i-- > 0; ) { - assertFalse(localCs[i].isListeningToLocalA()); - } - } - - private interface NotifyCommand { - void notifyListeners(LocalA localA); - } - - /** - * This object simply fires a state change event. Both LocalB and LocalC - * will be listeners. - */ - private static class LocalA extends AbstractModel { - LocalA() { - super(); - } - void notifyStateListeners() { - this.fireStateChanged(); - } - void notifyPropertyListeners() { - this.firePropertyChanged("foo", 1, 2); - } - void notifyCollectionListeners() { - this.fireCollectionChanged("foo", Collections.emptySet()); - } - void notifyListListeners() { - this.fireListChanged("foo", Collections.emptyList()); - } - void notifyTreeListeners() { - this.fireTreeChanged("foo", Collections.emptySet()); - } - } - - /** - * This object will fire state change events whenever it receives - * a state change event from localA. - */ - private static class LocalB - extends AbstractModel - implements ChangeListener - { - LocalB(LocalA localA) { - super(); - localA.addChangeListener(this); - } - - public void stateChanged(StateChangeEvent e) { - this.fireStateChanged(); - } - - public void propertyChanged(PropertyChangeEvent evt) { - this.firePropertyChanged("bar", 1, 2); - } - - public void collectionChanged(CollectionChangeEvent e) { - this.fireCollectionChanged("bar", Collections.emptySet()); - } - public void collectionCleared(CollectionClearEvent e) {/*ignore*/} - public void itemsAdded(CollectionAddEvent e) {/*ignore*/} - public void itemsRemoved(CollectionRemoveEvent e) {/*ignore*/} - - public void listChanged(ListChangeEvent e) { - this.fireListChanged("bar", Collections.emptyList()); - } - public void listCleared(ListClearEvent e) {/*ignore*/} - public void itemsAdded(ListAddEvent e) {/*ignore*/} - public void itemsRemoved(ListRemoveEvent e) {/*ignore*/} - public void itemsReplaced(ListReplaceEvent e) {/*ignore*/} - public void itemsMoved(ListMoveEvent e) {/*ignore*/} - - public void treeChanged(TreeChangeEvent e) { - this.fireTreeChanged("bar", Collections.emptySet()); - } - public void treeCleared(TreeClearEvent e) {/*ignore*/} - public void nodeAdded(TreeAddEvent e) {/*ignore*/} - public void nodeRemoved(TreeRemoveEvent e) {/*ignore*/} - - } - - /** - * This object will listen to two other objects, localA and localB. - * If this object receives notification from localB, it will stop listening to - * localA. If this object receives notification from localA, it will check to - * see whether it still listening to localA. If this object is no longer - * listening to localA, it will complain about receiving the event and - * throw an exception. - */ - private static class LocalC - extends AbstractModel - implements ChangeListener - { - private LocalA localA; - private LocalB localB; - private boolean listeningToLocalA; - - LocalC(LocalA localA, LocalB localB) { - super(); - this.localA = localA; - this.localB = localB; - - localA.addChangeListener(this); - this.listeningToLocalA = true; - - localB.addChangeListener(this); - } - boolean isListeningToLocalA() { - return this.listeningToLocalA; - } - - public void stateChanged(StateChangeEvent e) { - Object source = e.getSource(); - if (source == this.localA) { - if ( ! this.listeningToLocalA) { - throw new IllegalStateException(ISE_MESSAGE); - } - } else if (source == this.localB) { - this.localA.removeChangeListener(this); - this.listeningToLocalA = false; - } else { - throw new IllegalStateException("bogus event source: " + source); - } - } - - public void propertyChanged(PropertyChangeEvent e) { - Object source = e.getSource(); - if (source == this.localA) { - if ( ! this.listeningToLocalA) { - throw new IllegalStateException(ISE_MESSAGE); - } - } else if (source == this.localB) { - this.localA.removeChangeListener(this); - this.listeningToLocalA = false; - } else { - throw new IllegalStateException("bogus event source: " + source); - } - } - - public void collectionChanged(CollectionChangeEvent e) { - Object source = e.getSource(); - if (source == this.localA) { - if ( ! this.listeningToLocalA) { - throw new IllegalStateException(ISE_MESSAGE); - } - } else if (source == this.localB) { - this.localA.removeChangeListener(this); - this.listeningToLocalA = false; - } else { - throw new IllegalStateException("bogus event source: " + source); - } - } - public void collectionCleared(CollectionClearEvent e) {/*ignore*/} - public void itemsAdded(CollectionAddEvent e) {/*ignore*/} - public void itemsRemoved(CollectionRemoveEvent e) {/*ignore*/} - - public void listChanged(ListChangeEvent e) { - Object source = e.getSource(); - if (source == this.localA) { - if ( ! this.listeningToLocalA) { - throw new IllegalStateException(ISE_MESSAGE); - } - } else if (source == this.localB) { - this.localA.removeChangeListener(this); - this.listeningToLocalA = false; - } else { - throw new IllegalStateException("bogus event source: " + source); - } - } - public void listCleared(ListClearEvent e) {/*ignore*/} - public void itemsAdded(ListAddEvent e) {/*ignore*/} - public void itemsRemoved(ListRemoveEvent e) {/*ignore*/} - public void itemsReplaced(ListReplaceEvent e) {/*ignore*/} - public void itemsMoved(ListMoveEvent e) {/*ignore*/} - - public void treeChanged(TreeChangeEvent e) { - Object source = e.getSource(); - if (source == this.localA) { - if ( ! this.listeningToLocalA) { - throw new IllegalStateException(ISE_MESSAGE); - } - } else if (source == this.localB) { - this.localA.removeChangeListener(this); - this.listeningToLocalA = false; - } else { - throw new IllegalStateException("bogus event source: " + source); - } - } - public void treeCleared(TreeClearEvent e) {/*ignore*/} - public void nodeAdded(TreeAddEvent e) {/*ignore*/} - public void nodeRemoved(TreeRemoveEvent e) {/*ignore*/} - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/JptUtilityModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/JptUtilityModelTests.java deleted file mode 100644 index ebd6330401..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/JptUtilityModelTests.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model; - -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.utility.tests.internal.model.listener.JptUtilityModelListenerTests; -import org.eclipse.jpt.utility.tests.internal.model.value.JptUtilityModelValueTests; - -public class JptUtilityModelTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptUtilityModelTests.class.getPackage().getName()); - - suite.addTest(JptUtilityModelListenerTests.suite()); - suite.addTest(JptUtilityModelValueTests.suite()); - - suite.addTestSuite(ChangeSupportTests.class); - suite.addTestSuite(NewEventTests.class); - suite.addTestSuite(SingleAspectChangeSupportTests.class); - - return suite; - } - - private JptUtilityModelTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/NewEventTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/NewEventTests.java deleted file mode 100644 index 22276502f7..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/NewEventTests.java +++ /dev/null @@ -1,181 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model; - -import java.util.EventListener; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.ListenerList; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.ChangeSupport; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.ChangeEvent; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -/** - * test what it takes to add a new type of event to - * model and change support - */ -public class NewEventTests extends TestCase { - private Foo foo; - - public NewEventTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.foo = new Foo(); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testHasNoFooChangeListeners() { - assertTrue(this.foo.hasNoFooChangeListeners()); - LocalListener listener = new LocalListener(); - this.foo.addFooChangeListener(listener); - assertFalse(this.foo.hasNoFooChangeListeners()); - this.foo.removeFooChangeListener(listener); - assertTrue(this.foo.hasNoFooChangeListeners()); - } - - public void testHasAnyFooChangeListeners() { - assertFalse(this.foo.hasAnyFooChangeListeners()); - LocalListener listener = new LocalListener(); - this.foo.addFooChangeListener(listener); - assertTrue(this.foo.hasAnyFooChangeListeners()); - this.foo.removeFooChangeListener(listener); - assertFalse(this.foo.hasAnyFooChangeListeners()); - } - - public void testFireFooChangeEvent() { - LocalListener listener = new LocalListener(); - assertFalse(listener.receivedFooEvent); - this.foo.addFooChangeListener(listener); - this.foo.foo(); - assertTrue(listener.receivedFooEvent); - } - - - // ********** harness classes ********** - - class Foo extends AbstractFooModel { - Foo() { - super(); - } - void foo() { - this.fireFooChangeEvent(); - } - } - - class LocalListener implements FooChangeListener { - boolean receivedFooEvent = false; - LocalListener() { - super(); - } - public void fooChanged(FooChangeEvent event) { - this.receivedFooEvent = true; - } - } - - interface FooModel extends Model { - void addFooChangeListener(FooChangeListener listener); - void removeFooChangeListener(FooChangeListener listener); - } - - interface FooChangeListener extends EventListener { - void fooChanged(FooChangeEvent event); - } - - static class FooChangeEvent extends ChangeEvent { - private static final long serialVersionUID = 1L; - public FooChangeEvent(FooModel source) { - super(source); - } - public FooChangeEvent clone(Model newSource) { - return new FooChangeEvent((FooModel) newSource); - } - } - - static class AbstractFooModel extends AbstractModel implements FooModel { - @Override - protected synchronized FooChangeSupport getChangeSupport() { - return (FooChangeSupport) super.getChangeSupport(); - } - @Override - protected ChangeSupport buildChangeSupport() { - return new FooChangeSupport(this); - } - public void addFooChangeListener(FooChangeListener listener) { - this.getChangeSupport().addFooChangeListener(listener); - } - public void removeFooChangeListener(FooChangeListener listener) { - this.getChangeSupport().removeFooChangeListener(listener); - } - protected void fireFooChangeEvent() { - this.getChangeSupport().fireFooChanged(); - } - public boolean hasAnyFooChangeListeners() { - return this.getChangeSupport().hasAnyFooChangeListeners(); - } - public boolean hasNoFooChangeListeners() { - return ! this.hasAnyFooChangeListeners(); - } - } - - static class FooChangeSupport extends ChangeSupport { - FooChangeSupport(FooModel source) { - super(source); - } - protected static final Class<FooChangeListener> FOO_CHANGE_LISTENER_CLASS = FooChangeListener.class; - void addFooChangeListener(FooChangeListener listener) { - this.addListener(FOO_CHANGE_LISTENER_CLASS, listener); - } - void removeFooChangeListener(FooChangeListener listener) { - this.removeListener(FOO_CHANGE_LISTENER_CLASS, listener); - } - public boolean hasAnyFooChangeListeners() { - return this.hasAnyListeners(FOO_CHANGE_LISTENER_CLASS); - } - private ListenerList<FooChangeListener> getFooChangeListenerList() { - return this.getListenerList(FOO_CHANGE_LISTENER_CLASS); - } - private Iterable<FooChangeListener> getFooChangeListeners() { - ListenerList<FooChangeListener> listenerList = this.getFooChangeListenerList(); - return (listenerList == null) ? null : listenerList.getListeners(); - } - private boolean hasFooChangeListener(FooChangeListener listener) { - return CollectionTools.contains(this.getFooChangeListeners(), listener); - } - public void fireFooChanged() { - Iterable<FooChangeListener> listeners = this.getFooChangeListeners(); - if (listeners != null) { - FooChangeEvent event = null; - for (FooChangeListener listener : listeners) { - if (this.hasFooChangeListener(listener)) { - if (event == null) { - // here's the reason for the duplicate code... - event = new FooChangeEvent((FooModel) this.source); - } - listener.fooChanged(event); - } - } - } - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/SingleAspectChangeSupportTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/SingleAspectChangeSupportTests.java deleted file mode 100644 index f934ec18ce..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/SingleAspectChangeSupportTests.java +++ /dev/null @@ -1,192 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.ChangeSupport; -import org.eclipse.jpt.utility.internal.model.SingleAspectChangeSupport; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.listener.CollectionChangeAdapter; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.listener.StateChangeListener; -import org.eclipse.jpt.utility.model.listener.TreeChangeAdapter; -import org.eclipse.jpt.utility.model.listener.TreeChangeListener; - -@SuppressWarnings("nls") -public class SingleAspectChangeSupportTests extends TestCase { - - public SingleAspectChangeSupportTests(String name) { - super(name); - } - - public void testAddPropertyChangeListenerInvalidClass() { - Model model = new StateTestModel(); - boolean exCaught = false; - PropertyChangeListener listener = new PropertyChangeAdapter(); - try { - model.addPropertyChangeListener("foo", listener); - fail("bogus listener: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testAddPropertyChangeListenerInvalidAspect() { - Model model = new PropertyTestModel(); - boolean exCaught = false; - PropertyChangeListener listener = new PropertyChangeAdapter(); - try { - model.addPropertyChangeListener("bar", listener); - fail("bogus listener: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testAddCollectionChangeListenerInvalidClass() { - Model model = new StateTestModel(); - boolean exCaught = false; - CollectionChangeListener listener = new CollectionChangeAdapter(); - try { - model.addCollectionChangeListener("foo", listener); - fail("bogus listener: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testAddCollectionChangeListenerInvalidAspect() { - Model model = new CollectionTestModel(); - boolean exCaught = false; - CollectionChangeListener listener = new CollectionChangeAdapter(); - try { - model.addCollectionChangeListener("bar", listener); - fail("bogus listener: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testAddListChangeListenerInvalidClass() { - Model model = new StateTestModel(); - boolean exCaught = false; - ListChangeListener listener = new ListChangeAdapter(); - try { - model.addListChangeListener("foo", listener); - fail("bogus listener: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testAddListChangeListenerInvalidAspect() { - Model model = new ListTestModel(); - boolean exCaught = false; - ListChangeListener listener = new ListChangeAdapter(); - try { - model.addListChangeListener("bar", listener); - fail("bogus listener: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testAddTreeChangeListenerInvalidClass() { - Model model = new StateTestModel(); - boolean exCaught = false; - TreeChangeListener listener = new TreeChangeAdapter(); - try { - model.addTreeChangeListener("foo", listener); - fail("bogus listener: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testAddTreeChangeListenerInvalidAspect() { - Model model = new TreeTestModel(); - boolean exCaught = false; - TreeChangeListener listener = new TreeChangeAdapter(); - try { - model.addTreeChangeListener("bar", listener); - fail("bogus listener: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - - // ********** test models ********** - - static class StateTestModel extends AbstractModel { - StateTestModel() { - super(); - } - @Override - protected ChangeSupport buildChangeSupport() { - return new SingleAspectChangeSupport(this, StateChangeListener.class, null); - } - } - - static class PropertyTestModel extends AbstractModel { - PropertyTestModel() { - super(); - } - @Override - protected ChangeSupport buildChangeSupport() { - return new SingleAspectChangeSupport(this, PropertyChangeListener.class, "foo"); - } - } - - static class CollectionTestModel extends AbstractModel { - CollectionTestModel() { - super(); - } - @Override - protected ChangeSupport buildChangeSupport() { - return new SingleAspectChangeSupport(this, CollectionChangeListener.class, "foo"); - } - } - - static class ListTestModel extends AbstractModel { - ListTestModel() { - super(); - } - @Override - protected ChangeSupport buildChangeSupport() { - return new SingleAspectChangeSupport(this, ListChangeListener.class, "foo"); - } - } - - static class TreeTestModel extends AbstractModel { - TreeTestModel() { - super(); - } - @Override - protected ChangeSupport buildChangeSupport() { - return new SingleAspectChangeSupport(this, TreeChangeListener.class, "foo"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/JptUtilityModelListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/JptUtilityModelListenerTests.java deleted file mode 100644 index 084a9b8ab3..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/JptUtilityModelListenerTests.java +++ /dev/null @@ -1,34 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.listener; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptUtilityModelListenerTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptUtilityModelListenerTests.class.getPackage().getName()); - - suite.addTestSuite(ReflectiveCollectionChangeListenerTests.class); - suite.addTestSuite(ReflectiveListChangeListenerTests.class); - suite.addTestSuite(ReflectivePropertyChangeListenerTests.class); - suite.addTestSuite(ReflectiveStateChangeListenerTests.class); - suite.addTestSuite(ReflectiveTreeChangeListenerTests.class); - - return suite; - } - - private JptUtilityModelListenerTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveCollectionChangeListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveCollectionChangeListenerTests.java deleted file mode 100644 index 76a759d76f..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveCollectionChangeListenerTests.java +++ /dev/null @@ -1,331 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.listener; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.ReflectiveChangeListener; - -@SuppressWarnings("nls") -public class ReflectiveCollectionChangeListenerTests extends TestCase { - - public ReflectiveCollectionChangeListenerTests(String name) { - super(name); - } - - private CollectionChangeListener buildZeroArgumentListener(Object target) { - return ReflectiveChangeListener.buildCollectionChangeListener(target, "itemAddedZeroArgument", "itemRemovedZeroArgument", "collectionClearedZeroArgument", "collectionChangedZeroArgument"); - } - - private CollectionChangeListener buildSingleArgumentListener(Object target) { - return ReflectiveChangeListener.buildCollectionChangeListener(target, "itemAddedSingleArgument", "itemRemovedSingleArgument", "collectionClearedSingleArgument", "collectionChangedSingleArgument"); - } - - public void testItemAddedZeroArgumentNamedCollection() { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - testModel.addCollectionChangeListener(TestModel.STRINGS_COLLECTION, this.buildZeroArgumentListener(target)); - testModel.addString(string); - assertTrue(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.collectionClearedZeroArgumentFlag); - assertFalse(target.collectionClearedSingleArgumentFlag); - assertFalse(target.collectionChangedZeroArgumentFlag); - assertFalse(target.collectionChangedSingleArgumentFlag); - } - - public void testItemAddedSingleArgumentNamedCollection() { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - testModel.addCollectionChangeListener(TestModel.STRINGS_COLLECTION, this.buildSingleArgumentListener(target)); - testModel.addString(string); - assertFalse(target.itemAddedZeroArgumentFlag); - assertTrue(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.collectionClearedZeroArgumentFlag); - assertFalse(target.collectionClearedSingleArgumentFlag); - assertFalse(target.collectionChangedZeroArgumentFlag); - assertFalse(target.collectionChangedSingleArgumentFlag); - } - - public void testItemRemovedZeroArgumentNamedCollection() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - testModel.addCollectionChangeListener(TestModel.STRINGS_COLLECTION, this.buildZeroArgumentListener(target)); - testModel.removeString(string); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertTrue(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.collectionClearedZeroArgumentFlag); - assertFalse(target.collectionClearedSingleArgumentFlag); - assertFalse(target.collectionChangedZeroArgumentFlag); - assertFalse(target.collectionChangedSingleArgumentFlag); - } - - public void testItemRemovedSingleArgumentNamedCollection() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - testModel.addCollectionChangeListener(TestModel.STRINGS_COLLECTION, this.buildSingleArgumentListener(target)); - testModel.removeString(string); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertTrue(target.itemRemovedSingleArgumentFlag); - assertFalse(target.collectionClearedZeroArgumentFlag); - assertFalse(target.collectionClearedSingleArgumentFlag); - assertFalse(target.collectionChangedZeroArgumentFlag); - assertFalse(target.collectionChangedSingleArgumentFlag); - } - - public void testCollectionClearedZeroArgumentNamedCollection() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - testModel.addCollectionChangeListener(TestModel.STRINGS_COLLECTION, this.buildZeroArgumentListener(target)); - testModel.clearStrings(); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertTrue(target.collectionClearedZeroArgumentFlag); - assertFalse(target.collectionClearedSingleArgumentFlag); - assertFalse(target.collectionChangedZeroArgumentFlag); - assertFalse(target.collectionChangedSingleArgumentFlag); - } - - public void testCollectionClearedSingleArgumentNamedCollection() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - testModel.addCollectionChangeListener(TestModel.STRINGS_COLLECTION, this.buildSingleArgumentListener(target)); - testModel.clearStrings(); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.collectionClearedZeroArgumentFlag); - assertTrue(target.collectionClearedSingleArgumentFlag); - assertFalse(target.collectionChangedZeroArgumentFlag); - assertFalse(target.collectionChangedSingleArgumentFlag); - } - - public void testCollectionChangedZeroArgumentNamedCollection() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - testModel.addCollectionChangeListener(TestModel.STRINGS_COLLECTION, this.buildZeroArgumentListener(target)); - testModel.replaceStrings(new String[] {"bar", "baz"}); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.collectionClearedZeroArgumentFlag); - assertFalse(target.collectionClearedSingleArgumentFlag); - assertTrue(target.collectionChangedZeroArgumentFlag); - assertFalse(target.collectionChangedSingleArgumentFlag); - } - - public void testCollectionChangedSingleArgumentNamedCollection() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - testModel.addCollectionChangeListener(TestModel.STRINGS_COLLECTION, this.buildSingleArgumentListener(target)); - testModel.replaceStrings(new String[] {"bar", "baz"}); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.collectionClearedZeroArgumentFlag); - assertFalse(target.collectionClearedSingleArgumentFlag); - assertFalse(target.collectionChangedZeroArgumentFlag); - assertTrue(target.collectionChangedSingleArgumentFlag); - } - - public void testBogusDoubleArgument1() { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - boolean exCaught = false; - try { - CollectionChangeListener listener = ReflectiveChangeListener.buildCollectionChangeListener(target, "collectionChangedDoubleArgument"); - fail("bogus listener: " + listener); - } catch (RuntimeException ex) { - if (ex.getCause().getClass() == NoSuchMethodException.class) { - exCaught = true; - } - } - assertTrue(exCaught); - } - - public void testBogusDoubleArgument2() throws Exception { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - Method method = ClassTools.method(target, "collectionChangedDoubleArgument", new Class[] {CollectionChangeEvent.class, Object.class}); - boolean exCaught = false; - try { - CollectionChangeListener listener = ReflectiveChangeListener.buildCollectionChangeListener(target, method); - fail("bogus listener: " + listener); - } catch (RuntimeException ex) { - if (ex.getMessage().equals(method.toString())) { - exCaught = true; - } - } - assertTrue(exCaught); - } - - public void testListenerMismatch() { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_COLLECTION, string); - // build a COLLECTION change listener and hack it so we - // can add it as a LIST change listener - Object listener = ReflectiveChangeListener.buildCollectionChangeListener(target, "collectionEventSingleArgument"); - testModel.addListChangeListener("bogus list", (ListChangeListener) listener); - - boolean exCaught = false; - try { - testModel.changeList(); - fail("listener mismatch: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - - class TestModel extends AbstractModel { - private Collection<String> strings = new ArrayList<String>(); - public static final String STRINGS_COLLECTION = "strings"; - TestModel() { - super(); - } - Iterator<String> strings() { - return new CloneIterator<String>(this.strings) { - @Override - protected void remove(String s) { - TestModel.this.removeString(s); - } - }; - } - void addString(String string) { - this.addItemToCollection(string, this.strings, STRINGS_COLLECTION); - } - void removeString(String string) { - this.removeItemFromCollection(string, this.strings, STRINGS_COLLECTION); - } - void clearStrings() { - this.clearCollection(this.strings, STRINGS_COLLECTION); - } - void replaceStrings(String[] newStrings) { - this.strings.clear(); - CollectionTools.addAll(this.strings, newStrings); - this.fireCollectionChanged(STRINGS_COLLECTION, this.strings); - } - void changeList() { - this.fireListChanged("bogus list", Collections.emptyList()); - } - } - - class Target { - TestModel testModel; - String collectionName; - String string; - boolean itemAddedZeroArgumentFlag = false; - boolean itemAddedSingleArgumentFlag = false; - boolean itemRemovedZeroArgumentFlag = false; - boolean itemRemovedSingleArgumentFlag = false; - boolean collectionClearedZeroArgumentFlag = false; - boolean collectionClearedSingleArgumentFlag = false; - boolean collectionChangedZeroArgumentFlag = false; - boolean collectionChangedSingleArgumentFlag = false; - boolean collectionEventSingleArgumentFlag = false; - Target(TestModel testModel, String collectionName, String string) { - super(); - this.testModel = testModel; - this.collectionName = collectionName; - this.string = string; - } - void itemAddedZeroArgument() { - this.itemAddedZeroArgumentFlag = true; - } - void itemAddedSingleArgument(CollectionAddEvent e) { - this.itemAddedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.collectionName, e.getCollectionName()); - assertEquals(this.string, e.getItems().iterator().next()); - } - void itemRemovedZeroArgument() { - this.itemRemovedZeroArgumentFlag = true; - } - void itemRemovedSingleArgument(CollectionRemoveEvent e) { - this.itemRemovedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.collectionName, e.getCollectionName()); - assertEquals(this.string, e.getItems().iterator().next()); - } - void collectionClearedZeroArgument() { - this.collectionClearedZeroArgumentFlag = true; - } - void collectionClearedSingleArgument(CollectionClearEvent e) { - this.collectionClearedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.collectionName, e.getCollectionName()); - } - void collectionChangedZeroArgument() { - this.collectionChangedZeroArgumentFlag = true; - } - void collectionChangedSingleArgument(CollectionChangeEvent e) { - this.collectionChangedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.collectionName, e.getCollectionName()); - } - void collectionEventSingleArgument(CollectionEvent e) { - this.collectionEventSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.collectionName, e.getCollectionName()); - } - void collectionChangedDoubleArgument(CollectionChangeEvent e, Object o) { - fail("bogus event: " + e + " object: " + o); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveListChangeListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveListChangeListenerTests.java deleted file mode 100644 index ad8b76b362..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveListChangeListenerTests.java +++ /dev/null @@ -1,498 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.listener; - -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; -import java.util.ListIterator; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneListIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.ReflectiveChangeListener; - -@SuppressWarnings("nls") -public class ReflectiveListChangeListenerTests extends TestCase { - - public ReflectiveListChangeListenerTests(String name) { - super(name); - } - - private ListChangeListener buildZeroArgumentListener(Object target) { - return ReflectiveChangeListener.buildListChangeListener(target, "itemAddedZeroArgument", "itemRemovedZeroArgument", "itemReplacedZeroArgument", "itemMovedZeroArgument", "listClearedZeroArgument", "listChangedZeroArgument"); - } - - private ListChangeListener buildSingleArgumentListener(Object target) { - return ReflectiveChangeListener.buildListChangeListener(target, "itemAddedSingleArgument", "itemRemovedSingleArgument", "itemReplacedSingleArgument", "itemMovedSingleArgument", "listClearedSingleArgument", "listChangedSingleArgument"); - } - - public void testItemAddedZeroArgumentNamedList() { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_LIST, string, 0); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildZeroArgumentListener(target)); - testModel.addString(string); - assertTrue(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testItemAddedSingleArgumentNamedList() { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_LIST, string, 0); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildSingleArgumentListener(target)); - testModel.addString(string); - assertFalse(target.itemAddedZeroArgumentFlag); - assertTrue(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testItemRemovedZeroArgumentNamedList() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_LIST, string, 0); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildZeroArgumentListener(target)); - testModel.removeString(string); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertTrue(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testItemRemovedSingleArgumentNamedList() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_LIST, string, 0); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildSingleArgumentListener(target)); - testModel.removeString(string); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertTrue(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testItemReplacedZeroArgumentNamedList() { - TestModel testModel = new TestModel(); - String oldString = "foo"; - String newString = "bar"; - testModel.addString(oldString); - Target target = new Target(testModel, TestModel.STRINGS_LIST, newString, 0, oldString); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildZeroArgumentListener(target)); - testModel.replaceString(oldString, newString); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertTrue(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testItemReplacedSingleArgumentNamedList() { - TestModel testModel = new TestModel(); - String oldString = "foo"; - String newString = "bar"; - testModel.addString(oldString); - Target target = new Target(testModel, TestModel.STRINGS_LIST, newString, 0, oldString); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildSingleArgumentListener(target)); - testModel.replaceString(oldString, newString); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertTrue(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testItemMovedZeroArgumentNamedList() { - TestModel testModel = new TestModel(); - testModel.addString("zero"); - testModel.addString("one"); - testModel.addString("two"); - testModel.addString("three"); - Target target = new Target(testModel, TestModel.STRINGS_LIST, 0, 2); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildZeroArgumentListener(target)); - testModel.moveString(0, 2); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertTrue(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testItemMovedSingleArgumentNamedList() { - TestModel testModel = new TestModel(); - testModel.addString("zero"); - testModel.addString("one"); - testModel.addString("two"); - testModel.addString("three"); - Target target = new Target(testModel, TestModel.STRINGS_LIST, 0, 2); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildSingleArgumentListener(target)); - testModel.moveString(0, 2); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertTrue(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testListClearedZeroArgumentNamedList() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_LIST, null, -1); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildZeroArgumentListener(target)); - testModel.clearStrings(); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertTrue(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testListClearedSingleArgumentNamedList() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_LIST, null, -1); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildSingleArgumentListener(target)); - testModel.clearStrings(); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertTrue(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testListChangedZeroArgumentNamedList() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_LIST, null, -1); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildZeroArgumentListener(target)); - testModel.replaceAllStrings(new String[] {"bar", "baz"}); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertTrue(target.listChangedZeroArgumentFlag); - assertFalse(target.listChangedSingleArgumentFlag); - } - - public void testListChangedSingleArgumentNamedList() { - TestModel testModel = new TestModel(); - String string = "foo"; - testModel.addString(string); - Target target = new Target(testModel, TestModel.STRINGS_LIST, null, -1); - testModel.addListChangeListener(TestModel.STRINGS_LIST, this.buildSingleArgumentListener(target)); - testModel.replaceAllStrings(new String[] {"bar", "baz"}); - assertFalse(target.itemAddedZeroArgumentFlag); - assertFalse(target.itemAddedSingleArgumentFlag); - assertFalse(target.itemRemovedZeroArgumentFlag); - assertFalse(target.itemRemovedSingleArgumentFlag); - assertFalse(target.itemReplacedZeroArgumentFlag); - assertFalse(target.itemReplacedSingleArgumentFlag); - assertFalse(target.itemMovedZeroArgumentFlag); - assertFalse(target.itemMovedSingleArgumentFlag); - assertFalse(target.listClearedZeroArgumentFlag); - assertFalse(target.listClearedSingleArgumentFlag); - assertFalse(target.listChangedZeroArgumentFlag); - assertTrue(target.listChangedSingleArgumentFlag); - } - - public void testBogusDoubleArgument1() { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_LIST, string, 0); - boolean exCaught = false; - try { - ListChangeListener listener = ReflectiveChangeListener.buildListChangeListener(target, "listChangedDoubleArgument"); - fail("bogus listener: " + listener); - } catch (RuntimeException ex) { - if (ex.getCause().getClass() == NoSuchMethodException.class) { - exCaught = true; - } - } - assertTrue(exCaught); - } - - public void testBogusDoubleArgument2() throws Exception { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_LIST, string, 0); - Method method = ClassTools.method(target, "listChangedDoubleArgument", new Class[] {ListChangeEvent.class, Object.class}); - boolean exCaught = false; - try { - ListChangeListener listener = ReflectiveChangeListener.buildListChangeListener(target, method); - fail("bogus listener: " + listener); - } catch (RuntimeException ex) { - if (ex.getMessage().equals(method.toString())) { - exCaught = true; - } - } - assertTrue(exCaught); - } - - public void testListenerMismatch() { - TestModel testModel = new TestModel(); - String string = "foo"; - Target target = new Target(testModel, TestModel.STRINGS_LIST, string, 0); - // build a LIST change listener and hack it so we - // can add it as a COLLECTION change listener - Object listener = ReflectiveChangeListener.buildListChangeListener(target, "listEventSingleArgument"); - testModel.addCollectionChangeListener("bogus collection", (CollectionChangeListener) listener); - - boolean exCaught = false; - try { - testModel.changeCollection(); - fail("listener mismatch: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - - class TestModel extends AbstractModel { - private List<String> strings = new ArrayList<String>(); - public static final String STRINGS_LIST = "strings"; - TestModel() { - super(); - } - ListIterator<String> strings() { - return new CloneListIterator<String>(this.strings); - } - void addString(String string) { - this.addItemToList(string, this.strings, STRINGS_LIST); - } - void removeString(String string) { - this.removeItemFromList(this.strings.indexOf(string), this.strings, STRINGS_LIST); - } - void replaceString(String oldString, String newString) { - this.setItemInList(this.strings.indexOf(oldString), newString, this.strings, STRINGS_LIST); - } - void moveString(int targetIndex, int sourceIndex) { - this.moveItemInList(targetIndex, sourceIndex, this.strings, STRINGS_LIST); - } - void clearStrings() { - this.clearList(this.strings, STRINGS_LIST); - } - void replaceAllStrings(String[] newStrings) { - this.strings.clear(); - CollectionTools.addAll(this.strings, newStrings); - this.fireListChanged(STRINGS_LIST, this.strings); - } - void changeCollection() { - this.fireCollectionChanged("bogus collection", Collections.emptySet()); - } - } - - class Target { - TestModel testModel; - String listName; - String string; - int index; - String replacedString; - int sourceIndex; - boolean itemAddedZeroArgumentFlag = false; - boolean itemAddedSingleArgumentFlag = false; - boolean itemRemovedZeroArgumentFlag = false; - boolean itemRemovedSingleArgumentFlag = false; - boolean itemReplacedZeroArgumentFlag = false; - boolean itemReplacedSingleArgumentFlag = false; - boolean itemMovedZeroArgumentFlag = false; - boolean itemMovedSingleArgumentFlag = false; - boolean listClearedZeroArgumentFlag = false; - boolean listClearedSingleArgumentFlag = false; - boolean listChangedZeroArgumentFlag = false; - boolean listChangedSingleArgumentFlag = false; - boolean listEventSingleArgumentFlag = false; - Target(TestModel testModel, String listName, String string, int index) { - super(); - this.testModel = testModel; - this.listName = listName; - this.string = string; - this.index = index; - } - Target(TestModel testModel, String listName, String string, int index, String replacedString) { - this(testModel, listName, string, index); - this.replacedString = replacedString; - } - Target(TestModel testModel, String listName, int targetIndex, int sourceIndex) { - super(); - this.testModel = testModel; - this.listName = listName; - this.index = targetIndex; - this.sourceIndex = sourceIndex; - } - void itemAddedZeroArgument() { - this.itemAddedZeroArgumentFlag = true; - } - void itemAddedSingleArgument(ListAddEvent e) { - this.itemAddedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.listName, e.getListName()); - assertEquals(this.string, e.getItems().iterator().next()); - assertEquals(this.index, e.getIndex()); - } - void itemRemovedZeroArgument() { - this.itemRemovedZeroArgumentFlag = true; - } - void itemRemovedSingleArgument(ListRemoveEvent e) { - this.itemRemovedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.listName, e.getListName()); - assertEquals(this.string, e.getItems().iterator().next()); - assertEquals(this.index, e.getIndex()); - } - void itemReplacedZeroArgument() { - this.itemReplacedZeroArgumentFlag = true; - } - void itemReplacedSingleArgument(ListReplaceEvent e) { - this.itemReplacedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.listName, e.getListName()); - assertEquals(this.string, e.getNewItems().iterator().next()); - assertEquals(this.replacedString, e.getOldItems().iterator().next()); - assertEquals(this.index, e.getIndex()); - } - void itemMovedZeroArgument() { - this.itemMovedZeroArgumentFlag = true; - } - void itemMovedSingleArgument(ListMoveEvent e) { - this.itemMovedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.listName, e.getListName()); - assertEquals(this.index, e.getTargetIndex()); - assertEquals(this.sourceIndex, e.getSourceIndex()); - } - void listChangedZeroArgument() { - this.listChangedZeroArgumentFlag = true; - } - void listClearedSingleArgument(ListClearEvent e) { - this.listClearedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.listName, e.getListName()); - } - void listClearedZeroArgument() { - this.listClearedZeroArgumentFlag = true; - } - void listChangedSingleArgument(ListChangeEvent e) { - this.listChangedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.listName, e.getListName()); - } - void listChangedDoubleArgument(ListChangeEvent e, Object o) { - fail("bogus event: " + e + " - object: " + o); - } - void listEventSingleArgument(ListEvent e) { - this.listEventSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.listName, e.getListName()); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectivePropertyChangeListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectivePropertyChangeListenerTests.java deleted file mode 100644 index 59d6e8dbce..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectivePropertyChangeListenerTests.java +++ /dev/null @@ -1,176 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.listener; - -import java.lang.reflect.Method; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.listener.ReflectiveChangeListener; -import org.eclipse.jpt.utility.model.listener.StateChangeListener; - -@SuppressWarnings("nls") -public class ReflectivePropertyChangeListenerTests extends TestCase { - - public ReflectivePropertyChangeListenerTests(String name) { - super(name); - } - - public void testZeroArgumentNamedProperty() { - TestModel testModel = new TestModel(7); - Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); - testModel.addPropertyChangeListener(TestModel.VALUE_PROPERTY, ReflectiveChangeListener.buildPropertyChangeListener(target, "propertyChangedZeroArgument")); - testModel.setValue(99); - assertTrue(target.zeroArgumentFlag); - assertFalse(target.singleArgumentFlag); - } - - /** - * test method that has more general method parameter type - */ - public void testSingleArgument2() throws Exception { - TestModel testModel = new TestModel(7); - Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); - Method method = ClassTools.method(target, "propertyChangedSingleArgument2", new Class[] {Object.class}); - testModel.addPropertyChangeListener(TestModel.VALUE_PROPERTY, ReflectiveChangeListener.buildPropertyChangeListener(target, method)); - testModel.setValue(99); - assertFalse(target.zeroArgumentFlag); - assertTrue(target.singleArgumentFlag); - } - - public void testSingleArgumentNamedProperty() { - TestModel testModel = new TestModel(7); - Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); - testModel.addPropertyChangeListener(TestModel.VALUE_PROPERTY, ReflectiveChangeListener.buildPropertyChangeListener(target, "propertyChangedSingleArgument")); - testModel.setValue(99); - assertFalse(target.zeroArgumentFlag); - assertTrue(target.singleArgumentFlag); - } - - /** - * test method that has more general method parameter type - */ - public void testSingleArgumentNamedProperty2() throws Exception { - TestModel testModel = new TestModel(7); - Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); - Method method = ClassTools.method(target, "propertyChangedSingleArgument2", new Class[] {Object.class}); - testModel.addPropertyChangeListener(TestModel.VALUE_PROPERTY, ReflectiveChangeListener.buildPropertyChangeListener(target, method)); - testModel.setValue(99); - assertFalse(target.zeroArgumentFlag); - assertTrue(target.singleArgumentFlag); - } - - public void testListenerMismatch() { - TestModel testModel = new TestModel(7); - Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); - // build a PROPERTY change listener and hack it so we - // can add it as a STATE change listener - Object listener = ReflectiveChangeListener.buildPropertyChangeListener(target, "propertyChangedSingleArgument"); - testModel.addStateChangeListener((StateChangeListener) listener); - - boolean exCaught = false; - try { - testModel.setValue(99); - fail("listener mismatch: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testBogusDoubleArgument1() { - TestModel testModel = new TestModel(7); - Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); - boolean exCaught = false; - try { - PropertyChangeListener listener = ReflectiveChangeListener.buildPropertyChangeListener(target, "stateChangedDoubleArgument"); - fail("bogus listener: " + listener); - } catch (RuntimeException ex) { - if (ex.getCause().getClass() == NoSuchMethodException.class) { - exCaught = true; - } - } - assertTrue(exCaught); - } - - public void testBogusDoubleArgument2() throws Exception { - TestModel testModel = new TestModel(7); - Target target = new Target(testModel, TestModel.VALUE_PROPERTY, 7, 99); - Method method = ClassTools.method(target, "propertyChangedDoubleArgument", new Class[] {PropertyChangeEvent.class, Object.class}); - boolean exCaught = false; - try { - PropertyChangeListener listener = ReflectiveChangeListener.buildPropertyChangeListener(target, method); - fail("bogus listener: " + listener); - } catch (RuntimeException ex) { - if (ex.getMessage().equals(method.toString())) { - exCaught = true; - } - } - assertTrue(exCaught); - } - - - class TestModel extends AbstractModel { - private int value = 0; - public static final String VALUE_PROPERTY = "value"; - TestModel(int value) { - super(); - this.value = value; - } - void setValue(int value) { - int old = this.value; - this.value = value; - this.firePropertyChanged(VALUE_PROPERTY, old, value); - if (old != value) { - this.fireStateChanged(); - } - } - } - - class Target { - TestModel testModel; - String propertyName; - Object oldValue; - Object newValue; - boolean zeroArgumentFlag = false; - boolean singleArgumentFlag = false; - Target(TestModel testModel, String propertyName, int oldValue, int newValue) { - super(); - this.testModel = testModel; - this.propertyName = propertyName; - this.oldValue = new Integer(oldValue); - this.newValue = new Integer(newValue); - } - void propertyChangedZeroArgument() { - this.zeroArgumentFlag = true; - } - void propertyChangedSingleArgument(PropertyChangeEvent e) { - this.singleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.propertyName, e.getPropertyName()); - assertEquals(this.oldValue, e.getOldValue()); - assertEquals(this.newValue, e.getNewValue()); - } - void propertyChangedSingleArgument2(Object o) { - PropertyChangeEvent e = (PropertyChangeEvent) o; - this.singleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.propertyName, e.getPropertyName()); - assertEquals(this.oldValue, e.getOldValue()); - assertEquals(this.newValue, e.getNewValue()); - } - void propertyChangedDoubleArgument(PropertyChangeEvent e, Object o) { - fail("bogus event: " + e + " - object: " + o); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveStateChangeListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveStateChangeListenerTests.java deleted file mode 100644 index 4848960509..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveStateChangeListenerTests.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.listener; - -import java.lang.reflect.Method; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.model.event.StateChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.listener.ReflectiveChangeListener; -import org.eclipse.jpt.utility.model.listener.StateChangeListener; - -@SuppressWarnings("nls") -public class ReflectiveStateChangeListenerTests extends TestCase { - - public ReflectiveStateChangeListenerTests(String name) { - super(name); - } - - public void testZeroArgument() { - TestModel testModel = new TestModel(); - Target target = new Target(testModel); - testModel.addStateChangeListener(ReflectiveChangeListener.buildStateChangeListener(target, "stateChangedZeroArgument")); - testModel.changeState(); - assertTrue(target.zeroArgumentFlag); - assertFalse(target.singleArgumentFlag); - } - - public void testSingleArgument() { - TestModel testModel = new TestModel(); - Target target = new Target(testModel); - testModel.addStateChangeListener(ReflectiveChangeListener.buildStateChangeListener(target, "stateChangedSingleArgument")); - testModel.changeState(); - assertFalse(target.zeroArgumentFlag); - assertTrue(target.singleArgumentFlag); - } - - /** - * test method that has more general method parameter type - */ - public void testSingleArgument2() throws Exception { - TestModel testModel = new TestModel(); - Target target = new Target(testModel); - Method method = ClassTools.method(target, "stateChangedSingleArgument2", new Class[] {Object.class}); - testModel.addStateChangeListener(ReflectiveChangeListener.buildStateChangeListener(target, method)); - testModel.changeState(); - assertFalse(target.zeroArgumentFlag); - assertTrue(target.singleArgumentFlag); - } - - public void testListenerMismatch() { - TestModel testModel = new TestModel(); - Target target = new Target(testModel); - // build a STATE change listener and hack it so we - // can add it as a PROPERTY change listener - Object listener = ReflectiveChangeListener.buildStateChangeListener(target, "stateChangedSingleArgument"); - testModel.addPropertyChangeListener("value", (PropertyChangeListener) listener); - - boolean exCaught = false; - try { - testModel.changeProperty(); - fail("listener mismatch: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testBogusDoubleArgument1() { - TestModel testModel = new TestModel(); - Target target = new Target(testModel); - boolean exCaught = false; - try { - StateChangeListener listener = ReflectiveChangeListener.buildStateChangeListener(target, "stateChangedDoubleArgument"); - fail("bogus listener: " + listener); - } catch (RuntimeException ex) { - if (ex.getCause().getClass() == NoSuchMethodException.class) { - exCaught = true; - } - } - assertTrue(exCaught); - } - - public void testBogusDoubleArgument2() throws Exception { - TestModel testModel = new TestModel(); - Target target = new Target(testModel); - Method method = ClassTools.method(target, "stateChangedDoubleArgument", new Class[] {StateChangeEvent.class, Object.class}); - boolean exCaught = false; - try { - StateChangeListener listener = ReflectiveChangeListener.buildStateChangeListener(target, method); - fail("bogus listener: " + listener); - } catch (RuntimeException ex) { - if (ex.getMessage().equals(method.toString())) { - exCaught = true; - } - } - assertTrue(exCaught); - } - - - class TestModel extends AbstractModel { - TestModel() { - super(); - } - void changeState() { - this.fireStateChanged(); - } - void changeProperty() { - this.firePropertyChanged("value", 55, 42); - } - } - - class Target { - TestModel testModel; - boolean zeroArgumentFlag = false; - boolean singleArgumentFlag = false; - Target(TestModel testModel) { - super(); - this.testModel = testModel; - } - void stateChangedZeroArgument() { - this.zeroArgumentFlag = true; - } - void stateChangedSingleArgument(StateChangeEvent e) { - this.singleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - } - void stateChangedSingleArgument2(Object e) { - this.singleArgumentFlag = true; - assertSame(this.testModel, ((StateChangeEvent) e).getSource()); - } - void stateChangedDoubleArgument(StateChangeEvent e, Object o) { - fail("bogus event: " + e + " - object: " + o); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveTreeChangeListenerTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveTreeChangeListenerTests.java deleted file mode 100644 index 52581adaa4..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/listener/ReflectiveTreeChangeListenerTests.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.listener; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.Iterator; -import java.util.List; -import java.util.Map; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.model.event.TreeAddEvent; -import org.eclipse.jpt.utility.model.event.TreeChangeEvent; -import org.eclipse.jpt.utility.model.event.TreeClearEvent; -import org.eclipse.jpt.utility.model.event.TreeEvent; -import org.eclipse.jpt.utility.model.event.TreeRemoveEvent; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.listener.ReflectiveChangeListener; -import org.eclipse.jpt.utility.model.listener.TreeChangeListener; - -@SuppressWarnings("nls") -public class ReflectiveTreeChangeListenerTests extends TestCase { - - public ReflectiveTreeChangeListenerTests(String name) { - super(name); - } - - private TreeChangeListener buildZeroArgumentListener(Object target) { - return ReflectiveChangeListener.buildTreeChangeListener(target, "nodeAddedZeroArgument", "nodeRemovedZeroArgument", "treeClearedZeroArgument", "treeChangedZeroArgument"); - } - - private TreeChangeListener buildSingleArgumentListener(Object target) { - return ReflectiveChangeListener.buildTreeChangeListener(target, "nodeAddedSingleArgument", "nodeRemovedSingleArgument", "treeClearedSingleArgument", "treeChangedSingleArgument"); - } - - public void testNodeAddedZeroArgumentNamedTree() { - TestModel testModel = new TestModel("root"); - Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[]{"root", "child"}); - testModel.addTreeChangeListener(TestModel.STRINGS_TREE, this.buildZeroArgumentListener(target)); - testModel.addNode("root", "child"); - assertTrue(target.nodeAddedZeroArgumentFlag); - assertFalse(target.nodeAddedSingleArgumentFlag); - assertFalse(target.nodeRemovedZeroArgumentFlag); - assertFalse(target.nodeRemovedSingleArgumentFlag); - assertFalse(target.treeClearedZeroArgumentFlag); - assertFalse(target.treeClearedSingleArgumentFlag); - assertFalse(target.treeChangedZeroArgumentFlag); - assertFalse(target.treeChangedSingleArgumentFlag); - } - - public void testNodeAddedSingleArgumentNamedTree() { - TestModel testModel = new TestModel("root"); - Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[]{"root", "child"}); - testModel.addTreeChangeListener(TestModel.STRINGS_TREE, this.buildSingleArgumentListener(target)); - testModel.addNode("root", "child"); - assertFalse(target.nodeAddedZeroArgumentFlag); - assertTrue(target.nodeAddedSingleArgumentFlag); - assertFalse(target.nodeRemovedZeroArgumentFlag); - assertFalse(target.nodeRemovedSingleArgumentFlag); - assertFalse(target.treeClearedZeroArgumentFlag); - assertFalse(target.treeClearedSingleArgumentFlag); - assertFalse(target.treeChangedZeroArgumentFlag); - assertFalse(target.treeChangedSingleArgumentFlag); - } - - public void testNodeRemovedZeroArgumentNamedTree() { - TestModel testModel = new TestModel("root"); - testModel.addNode("root", "child"); - Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[]{"root", "child"}); - testModel.addTreeChangeListener(TestModel.STRINGS_TREE, this.buildZeroArgumentListener(target)); - testModel.removeNode("child"); - assertFalse(target.nodeAddedZeroArgumentFlag); - assertFalse(target.nodeAddedSingleArgumentFlag); - assertTrue(target.nodeRemovedZeroArgumentFlag); - assertFalse(target.nodeRemovedSingleArgumentFlag); - assertFalse(target.treeClearedZeroArgumentFlag); - assertFalse(target.treeClearedSingleArgumentFlag); - assertFalse(target.treeChangedZeroArgumentFlag); - assertFalse(target.treeChangedSingleArgumentFlag); - } - - public void testNodeRemovedSingleArgumentNamedTree() { - TestModel testModel = new TestModel("root"); - testModel.addNode("root", "child"); - Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[]{"root", "child"}); - testModel.addTreeChangeListener(TestModel.STRINGS_TREE, this.buildSingleArgumentListener(target)); - testModel.removeNode("child"); - assertFalse(target.nodeAddedZeroArgumentFlag); - assertFalse(target.nodeAddedSingleArgumentFlag); - assertFalse(target.nodeRemovedZeroArgumentFlag); - assertTrue(target.nodeRemovedSingleArgumentFlag); - assertFalse(target.treeClearedZeroArgumentFlag); - assertFalse(target.treeClearedSingleArgumentFlag); - assertFalse(target.treeChangedZeroArgumentFlag); - assertFalse(target.treeChangedSingleArgumentFlag); - } - - public void testTreeClearedZeroArgumentNamedTree() { - TestModel testModel = new TestModel("root"); - testModel.addNode("root", "child"); - testModel.addNode("child", "grandchild"); - Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[0]); - testModel.addTreeChangeListener(TestModel.STRINGS_TREE, this.buildZeroArgumentListener(target)); - testModel.clearTree(); - assertFalse(target.nodeAddedZeroArgumentFlag); - assertFalse(target.nodeAddedSingleArgumentFlag); - assertFalse(target.nodeRemovedZeroArgumentFlag); - assertFalse(target.nodeRemovedSingleArgumentFlag); - assertTrue(target.treeClearedZeroArgumentFlag); - assertFalse(target.treeClearedSingleArgumentFlag); - assertFalse(target.treeChangedZeroArgumentFlag); - assertFalse(target.treeChangedSingleArgumentFlag); - } - - public void testTreeClearedSingleArgumentNamedTree() { - TestModel testModel = new TestModel("root"); - testModel.addNode("root", "child"); - testModel.addNode("child", "grandchild"); - Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[0]); - testModel.addTreeChangeListener(TestModel.STRINGS_TREE, this.buildSingleArgumentListener(target)); - testModel.clearTree(); - assertFalse(target.nodeAddedZeroArgumentFlag); - assertFalse(target.nodeAddedSingleArgumentFlag); - assertFalse(target.nodeRemovedZeroArgumentFlag); - assertFalse(target.nodeRemovedSingleArgumentFlag); - assertFalse(target.treeClearedZeroArgumentFlag); - assertTrue(target.treeClearedSingleArgumentFlag); - assertFalse(target.treeChangedZeroArgumentFlag); - assertFalse(target.treeChangedSingleArgumentFlag); - } - - public void testTreeChangedZeroArgumentNamedTree() { - TestModel testModel = new TestModel("root"); - testModel.addNode("root", "child"); - Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[]{"root", "another child"}); - testModel.addTreeChangeListener(TestModel.STRINGS_TREE, this.buildZeroArgumentListener(target)); - testModel.replaceNode("child", "another child"); - assertFalse(target.nodeAddedZeroArgumentFlag); - assertFalse(target.nodeAddedSingleArgumentFlag); - assertFalse(target.nodeRemovedZeroArgumentFlag); - assertFalse(target.nodeRemovedSingleArgumentFlag); - assertFalse(target.treeClearedZeroArgumentFlag); - assertFalse(target.treeClearedSingleArgumentFlag); - assertTrue(target.treeChangedZeroArgumentFlag); - assertFalse(target.treeChangedSingleArgumentFlag); - } - - public void testTreeChangedSingleArgumentNamedTree() { - TestModel testModel = new TestModel("root"); - testModel.addNode("root", "child"); - Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[]{"root", "another child"}); - testModel.addTreeChangeListener(TestModel.STRINGS_TREE, this.buildSingleArgumentListener(target)); - testModel.replaceNode("child", "another child"); - assertFalse(target.nodeAddedZeroArgumentFlag); - assertFalse(target.nodeAddedSingleArgumentFlag); - assertFalse(target.nodeRemovedZeroArgumentFlag); - assertFalse(target.nodeRemovedSingleArgumentFlag); - assertFalse(target.treeClearedZeroArgumentFlag); - assertFalse(target.treeClearedSingleArgumentFlag); - assertFalse(target.treeChangedZeroArgumentFlag); - assertTrue(target.treeChangedSingleArgumentFlag); - } - - public void testListenerMismatch() { - TestModel testModel = new TestModel("root"); - testModel.addNode("root", "child"); - Target target = new Target(testModel, TestModel.STRINGS_TREE, new String[]{"root", "child"}); - // build a TREE change listener and hack it so we - // can add it as a COLLECTION change listener - Object listener = ReflectiveChangeListener.buildTreeChangeListener(target, "treeEventSingleArgument"); - testModel.addCollectionChangeListener("bogus collection", (CollectionChangeListener) listener); - - boolean exCaught = false; - try { - testModel.changeCollection(); - fail("listener mismatch: " + listener); - } catch (IllegalArgumentException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - - class TestModel extends AbstractModel { - private final String root; - private Map<String, Collection<String>> childrenLists = new HashMap<String, Collection<String>>(); - private Map<String, String> parents = new HashMap<String, String>(); - public static final String STRINGS_TREE = "strings"; - TestModel(String root) { - super(); - if (root == null) { - throw new NullPointerException(); - } - this.root = root; - this.childrenLists.put(root, new ArrayList<String>()); - this.parents.put(root, null); - } - String getRoot() { - return this.root; - } - private List<String> path(String node) { - String temp = node; - List<String> reversePath = new ArrayList<String>(); - do { - reversePath.add(temp); - temp = this.parents.get(temp); - } while (temp != null); - return CollectionTools.reverse(reversePath); - } - Iterator<String> strings() { - return new CloneIterator<String>(this.childrenLists.keySet()) { - @Override - protected void remove(String s) { - TestModel.this.removeNode(s); - } - }; - } - void addNode(String parent, String child) { - if ((parent == null) || (child == null)) { - throw new NullPointerException(); - } - - Collection<String> children = this.childrenLists.get(parent); - if (children == null) { - throw new IllegalStateException("cannot add a child to a non-existent parent"); - } - - if (this.childrenLists.get(child) != null) { - throw new IllegalStateException("cannot add a child that is already in the tree"); - } - - children.add(child); - this.childrenLists.put(child, new ArrayList<String>()); - this.parents.put(child, parent); - this.fireNodeAdded(STRINGS_TREE, this.path(child)); - } - void removeNode(String node) { - if (node == null) { - throw new NullPointerException(); - } - - Collection<String> children = this.childrenLists.get(node); - if (children == null) { - throw new IllegalStateException("node is not in tree"); - } - List<String> path = this.path(node); - for (String s : children) { - this.removeNode(s); - } - this.childrenLists.remove(node); - this.parents.remove(node); - this.fireNodeRemoved(STRINGS_TREE, path); - } - void replaceNode(String oldNode, String newNode) { - if ((oldNode == null) || (newNode == null)) { - throw new NullPointerException(); - } - - Collection<String> children = this.childrenLists.remove(oldNode); - if (children == null) { - throw new IllegalStateException("old node is not in tree"); - } - this.childrenLists.put(newNode, children); - for (String child : children) { - this.parents.put(child, newNode); - } - - String parent = this.parents.remove(oldNode); - this.parents.put(newNode, parent); - - this.fireTreeChanged(STRINGS_TREE, this.path(newNode)); - } - void clearTree() { - this.childrenLists.clear(); - this.childrenLists.put(root, new ArrayList<String>()); - this.parents.clear(); - this.parents.put(root, null); - this.fireTreeCleared(STRINGS_TREE); - } - void changeCollection() { - this.fireCollectionChanged("bogus collection", Collections.emptySet()); - } - } - - class Target { - TestModel testModel; - String treeName; - List<String> path; - boolean nodeAddedZeroArgumentFlag = false; - boolean nodeAddedSingleArgumentFlag = false; - boolean nodeRemovedZeroArgumentFlag = false; - boolean nodeRemovedSingleArgumentFlag = false; - boolean treeClearedZeroArgumentFlag = false; - boolean treeClearedSingleArgumentFlag = false; - boolean treeChangedZeroArgumentFlag = false; - boolean treeChangedSingleArgumentFlag = false; - boolean treeEventSingleArgumentFlag = false; - Target(TestModel testModel, String treeName, String[] path) { - super(); - this.testModel = testModel; - this.treeName = treeName; - this.path = Arrays.asList(path); - } - void nodeAddedZeroArgument() { - this.nodeAddedZeroArgumentFlag = true; - } - void nodeAddedSingleArgument(TreeAddEvent e) { - this.nodeAddedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.treeName, e.getTreeName()); - assertEquals(this.path, CollectionTools.list(e.getPath())); - } - void nodeRemovedZeroArgument() { - this.nodeRemovedZeroArgumentFlag = true; - } - void nodeRemovedSingleArgument(TreeRemoveEvent e) { - this.nodeRemovedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.treeName, e.getTreeName()); - assertEquals(this.path, CollectionTools.list(e.getPath())); - } - void treeClearedZeroArgument() { - this.treeClearedZeroArgumentFlag = true; - } - void treeClearedSingleArgument(TreeClearEvent e) { - this.treeClearedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.treeName, e.getTreeName()); - } - void treeChangedZeroArgument() { - this.treeChangedZeroArgumentFlag = true; - } - void treeChangedSingleArgument(TreeChangeEvent e) { - this.treeChangedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.treeName, e.getTreeName()); - } - void treeEventSingleArgument(TreeEvent e) { - this.treeChangedSingleArgumentFlag = true; - assertSame(this.testModel, e.getSource()); - assertEquals(this.treeName, e.getTreeName()); - } - void collectionChangedDoubleArgument(TreeChangeEvent e, Object o) { - fail("bogus event: " + e + " - object: " + o); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/BufferedWritablePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/BufferedWritablePropertyValueModelTests.java deleted file mode 100644 index 366cb55312..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/BufferedWritablePropertyValueModelTests.java +++ /dev/null @@ -1,504 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Date; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.BufferedWritablePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class BufferedWritablePropertyValueModelTests extends TestCase { - private Employee employee; - private WritablePropertyValueModel<Employee> employeeHolder; - PropertyChangeEvent employeeEvent; - - private WritablePropertyValueModel<Integer> idAdapter; - private WritablePropertyValueModel<String> nameAdapter; - private WritablePropertyValueModel<Date> hireDateAdapter; - PropertyChangeEvent adapterEvent; - - private BufferedWritablePropertyValueModel.Trigger trigger; - private BufferedWritablePropertyValueModel<Integer> bufferedIDHolder; - private BufferedWritablePropertyValueModel<String> bufferedNameHolder; - private BufferedWritablePropertyValueModel<Date> bufferedHireDateHolder; - PropertyChangeEvent bufferedEvent; - - public BufferedWritablePropertyValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - this.employee = new Employee(17, "Freddy", new Date()); - this.employeeHolder = new SimplePropertyValueModel<Employee>(this.employee); - - this.trigger = new BufferedWritablePropertyValueModel.Trigger(); - - this.idAdapter = this.buildIDAdapter(this.employeeHolder); - this.bufferedIDHolder = new BufferedWritablePropertyValueModel<Integer>(this.idAdapter, this.trigger); - - this.nameAdapter = this.buildNameAdapter(this.employeeHolder); - this.bufferedNameHolder = new BufferedWritablePropertyValueModel<String>(this.nameAdapter, this.trigger); - - this.hireDateAdapter = this.buildHireDateAdapter(this.employeeHolder); - this.bufferedHireDateHolder = new BufferedWritablePropertyValueModel<Date>(this.hireDateAdapter, this.trigger); - } - - private WritablePropertyValueModel<Integer> buildIDAdapter(PropertyValueModel<Employee> eHolder) { - return new PropertyAspectAdapter<Employee, Integer>(eHolder, Employee.ID_PROPERTY) { - @Override - protected Integer buildValue_() { - return new Integer(this.subject.getID()); - } - @Override - protected void setValue_(Integer value) { - this.subject.setID(value.intValue()); - } - }; - } - - private WritablePropertyValueModel<String> buildNameAdapter(PropertyValueModel<Employee> eHolder) { - return new PropertyAspectAdapter<Employee, String>(eHolder, Employee.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return this.subject.getName(); - } - @Override - protected void setValue_(String value) { - this.subject.setName(value); - } - }; - } - - private WritablePropertyValueModel<Date> buildHireDateAdapter(PropertyValueModel<Employee> eHolder) { - return new PropertyAspectAdapter<Employee, Date>(eHolder, Employee.HIRE_DATE_PROPERTY) { - @Override - protected Date buildValue_() { - return this.subject.getHireDate(); - } - @Override - protected void setValue_(Date value) { - this.subject.setHireDate(value); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testGetValue() { - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedIDHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedHireDateHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - assertEquals(new Integer(17), this.idAdapter.getValue()); - assertEquals(new Integer(17), this.bufferedIDHolder.getValue()); - - assertEquals("Freddy", this.employee.getName()); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Freddy", this.bufferedNameHolder.getValue()); - - Date temp = this.employee.getHireDate(); - assertEquals(temp, this.employee.getHireDate()); - assertEquals(temp, this.hireDateAdapter.getValue()); - assertEquals(temp, this.bufferedHireDateHolder.getValue()); - - this.bufferedIDHolder.setValue(new Integer(323)); - assertEquals(17, this.employee.getID()); - assertEquals(new Integer(17), this.idAdapter.getValue()); - assertEquals(new Integer(323), this.bufferedIDHolder.getValue()); - - this.bufferedNameHolder.setValue("Ripley"); - assertEquals("Freddy", this.employee.getName()); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - - this.bufferedHireDateHolder.setValue(null); - assertEquals(temp, this.employee.getHireDate()); - assertEquals(temp, this.hireDateAdapter.getValue()); - assertEquals(null, this.bufferedHireDateHolder.getValue()); - } - - public void testTriggerAccept() { - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedIDHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedHireDateHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - this.bufferedIDHolder.setValue(new Integer(323)); - assertEquals(17, this.employee.getID()); - assertEquals(new Integer(17), this.idAdapter.getValue()); - assertEquals(new Integer(323), this.bufferedIDHolder.getValue()); - - this.bufferedNameHolder.setValue("Ripley"); - assertEquals("Freddy", this.employee.getName()); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - - Date temp = this.employee.getHireDate(); - this.bufferedHireDateHolder.setValue(null); - assertEquals(temp, this.employee.getHireDate()); - assertEquals(temp, this.hireDateAdapter.getValue()); - assertEquals(null, this.bufferedHireDateHolder.getValue()); - - this.trigger.accept(); - - assertEquals(323, this.employee.getID()); - assertEquals(new Integer(323), this.idAdapter.getValue()); - assertEquals(new Integer(323), this.bufferedIDHolder.getValue()); - - assertEquals("Ripley", this.employee.getName()); - assertEquals("Ripley", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - - assertEquals(null, this.employee.getHireDate()); - assertEquals(null, this.hireDateAdapter.getValue()); - assertEquals(null, this.bufferedHireDateHolder.getValue()); - } - - public void testTriggerReset() { - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedIDHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedHireDateHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - this.bufferedIDHolder.setValue(new Integer(323)); - assertEquals(17, this.employee.getID()); - assertEquals(new Integer(17), this.idAdapter.getValue()); - assertEquals(new Integer(323), this.bufferedIDHolder.getValue()); - - this.bufferedNameHolder.setValue("Ripley"); - assertEquals("Freddy", this.employee.getName()); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - - Date temp = this.employee.getHireDate(); - this.bufferedHireDateHolder.setValue(null); - assertEquals(temp, this.employee.getHireDate()); - assertEquals(temp, this.hireDateAdapter.getValue()); - assertEquals(null, this.bufferedHireDateHolder.getValue()); - - this.trigger.reset(); - - assertEquals(17, this.employee.getID()); - assertEquals(new Integer(17), this.idAdapter.getValue()); - assertEquals(new Integer(17), this.bufferedIDHolder.getValue()); - - assertEquals("Freddy", this.employee.getName()); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Freddy", this.bufferedNameHolder.getValue()); - - assertEquals(temp, this.employee.getHireDate()); - assertEquals(temp, this.hireDateAdapter.getValue()); - assertEquals(temp, this.bufferedHireDateHolder.getValue()); - } - - public void testLazyListening() { - assertTrue(((AbstractModel) this.bufferedIDHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.bufferedNameHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.bufferedHireDateHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - assertTrue(((AbstractModel) this.idAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.nameAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.hireDateAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.ID_PROPERTY)); - assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.NAME_PROPERTY)); - assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.HIRE_DATE_PROPERTY)); - - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedIDHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedHireDateHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - assertTrue(((AbstractModel) this.bufferedIDHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.bufferedNameHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.bufferedHireDateHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - assertTrue(((AbstractModel) this.idAdapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.nameAdapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.hireDateAdapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - assertTrue(this.employee.hasAnyPropertyChangeListeners(Employee.ID_PROPERTY)); - assertTrue(this.employee.hasAnyPropertyChangeListeners(Employee.NAME_PROPERTY)); - assertTrue(this.employee.hasAnyPropertyChangeListeners(Employee.HIRE_DATE_PROPERTY)); - - this.bufferedIDHolder.removePropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedNameHolder.removePropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - this.bufferedHireDateHolder.removePropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - assertTrue(((AbstractModel) this.bufferedIDHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.bufferedNameHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.bufferedHireDateHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - assertTrue(((AbstractModel) this.idAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.nameAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.hireDateAdapter).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.ID_PROPERTY)); - assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.NAME_PROPERTY)); - assertTrue(this.employee.hasNoPropertyChangeListeners(Employee.HIRE_DATE_PROPERTY)); - } - - public void testPropertyChange1() { - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - PropertyChangeListener adapterListener = this.buildAdapterListener(); - this.nameAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, adapterListener); - - PropertyChangeListener employeeListener = this.buildEmployeeListener(); - this.employee.addPropertyChangeListener(Employee.NAME_PROPERTY, employeeListener); - - this.verifyPropertyChanges(); - } - - public void testPropertyChange2() { - ChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedNameHolder.addChangeListener(bufferedListener); - - ChangeListener adapterListener = this.buildAdapterListener(); - this.nameAdapter.addChangeListener(adapterListener); - - ChangeListener employeeListener = this.buildEmployeeListener(); - this.employee.addChangeListener(employeeListener); - - this.verifyPropertyChanges(); - } - - private void verifyPropertyChanges() { - this.bufferedEvent = null; - this.adapterEvent = null; - this.employeeEvent = null; - this.bufferedNameHolder.setValue("Ripley"); - this.verifyEvent(this.bufferedEvent, this.bufferedNameHolder, PropertyValueModel.VALUE, "Freddy", "Ripley"); - assertNull(this.adapterEvent); - assertNull(this.employeeEvent); - - this.bufferedEvent = null; - this.adapterEvent = null; - this.employeeEvent = null; - this.bufferedNameHolder.setValue("Charlie"); - this.verifyEvent(this.bufferedEvent, this.bufferedNameHolder, PropertyValueModel.VALUE, "Ripley", "Charlie"); - assertNull(this.adapterEvent); - assertNull(this.employeeEvent); - - this.bufferedEvent = null; - this.adapterEvent = null; - this.employeeEvent = null; - this.trigger.accept(); - assertNull(this.bufferedEvent); - this.verifyEvent(this.adapterEvent, this.nameAdapter, PropertyValueModel.VALUE, "Freddy", "Charlie"); - this.verifyEvent(this.employeeEvent, this.employee, Employee.NAME_PROPERTY, "Freddy", "Charlie"); - - this.bufferedEvent = null; - this.adapterEvent = null; - this.employeeEvent = null; - this.bufferedNameHolder.setValue("Jason"); - this.verifyEvent(this.bufferedEvent, this.bufferedNameHolder, PropertyValueModel.VALUE, "Charlie", "Jason"); - assertNull(this.adapterEvent); - assertNull(this.employeeEvent); - - this.bufferedEvent = null; - this.adapterEvent = null; - this.employeeEvent = null; - this.trigger.reset(); - this.verifyEvent(this.bufferedEvent, this.bufferedNameHolder, PropertyValueModel.VALUE, "Jason", "Charlie"); - assertNull(this.adapterEvent); - assertNull(this.employeeEvent); - } - - /** - * changing the value should trigger buffering - */ - public void testBuffering1() { - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - this.bufferedNameHolder.setValue("Ripley"); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - assertTrue(this.bufferedNameHolder.isBuffering()); - } - - /** - * setting to the same value should not trigger buffering (?) - */ - public void testBuffering2() { - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - this.bufferedNameHolder.setValue("Freddy"); - assertEquals("Freddy", this.bufferedNameHolder.getValue()); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertFalse(this.bufferedNameHolder.isBuffering()); - } - - /** - * setting to the original value should not trigger buffering (?) - */ - public void testBuffering3() { - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - this.bufferedNameHolder.setValue("Ripley"); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - assertTrue(this.bufferedNameHolder.isBuffering()); - - this.bufferedNameHolder.setValue("Freddy"); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Freddy", this.bufferedNameHolder.getValue()); - assertFalse(this.bufferedNameHolder.isBuffering()); - } - - /** - * back-door changes are ignored - "Last One In Wins" - */ - public void testChangeConflict1() { - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - this.bufferedNameHolder.setValue("Ripley"); - assertEquals("Freddy", this.employee.getName()); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - - this.nameAdapter.setValue("Jason"); - assertEquals("Jason", this.employee.getName()); - assertEquals("Jason", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - - this.trigger.accept(); - // "Jason" is dropped on the floor... - assertEquals("Ripley", this.employee.getName()); - assertEquals("Ripley", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - } - - /** - * back-door changes can de-activate buffering (?) - */ - public void testChangeConflict2() { - PropertyChangeListener bufferedListener = this.buildBufferedListener(); - this.bufferedNameHolder.addPropertyChangeListener(PropertyValueModel.VALUE, bufferedListener); - - this.bufferedNameHolder.setValue("Ripley"); - assertEquals("Freddy", this.employee.getName()); - assertEquals("Freddy", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - assertTrue(this.bufferedNameHolder.isBuffering()); - - this.nameAdapter.setValue("Ripley"); - assertEquals("Ripley", this.employee.getName()); - assertEquals("Ripley", this.nameAdapter.getValue()); - assertEquals("Ripley", this.bufferedNameHolder.getValue()); - assertFalse(this.bufferedNameHolder.isBuffering()); - } - - private ChangeListener buildBufferedListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - BufferedWritablePropertyValueModelTests.this.bufferedEvent = e; - } - }; - } - - private ChangeListener buildAdapterListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - BufferedWritablePropertyValueModelTests.this.adapterEvent = e; - } - }; - } - - private ChangeListener buildEmployeeListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - BufferedWritablePropertyValueModelTests.this.employeeEvent = e; - } - }; - } - - private void verifyEvent(PropertyChangeEvent event, Object source, String propertyName, Object oldValue, Object newValue) { - assertEquals(source, event.getSource()); - assertEquals(propertyName, event.getPropertyName()); - assertEquals(oldValue, event.getOldValue()); - assertEquals(newValue, event.getNewValue()); - } - - - // ********** inner class ********** - - class Employee extends AbstractModel { - private int id; - public static final String ID_PROPERTY = "id"; - private String name; - public static final String NAME_PROPERTY = "name"; - private Date hireDate; - public static final String HIRE_DATE_PROPERTY = "hireDate"; - - Employee(int id, String name, Date hireDate) { - super(); - this.id = id; - this.name = name; - this.hireDate = hireDate; - } - int getID() { - return this.id; - } - void setID(int id) { - int old = this.id; - this.id = id; - this.firePropertyChanged(ID_PROPERTY, old, id); - } - String getName() { - return this.name; - } - void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - Date getHireDate() { - return this.hireDate; - } - void setHireDate(Date hireDate) { - Object old = this.hireDate; - this.hireDate = hireDate; - this.firePropertyChanged(HIRE_DATE_PROPERTY, old, hireDate); - } - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - } -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java deleted file mode 100644 index 0107fd0add..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationPropertyValueModelTests.java +++ /dev/null @@ -1,241 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.BidiTransformer; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.CachingTransformationPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class CachingTransformationPropertyValueModelTests extends TestCase { - private WritablePropertyValueModel<Person> objectHolder; - PropertyChangeEvent event; - - private PropertyValueModel<Person> transformationObjectHolder; - PropertyChangeEvent transformationEvent; - - public CachingTransformationPropertyValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null)); - this.transformationObjectHolder = new CachingTransformationPropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer()); - } - - private BidiTransformer<Person, Person> buildTransformer() { - return new BidiTransformer<Person, Person>() { - public Person transform(Person p) { - return (p == null) ? null : p.getParent(); - } - public Person reverseTransform(Person p) { - return (p == null) ? null : p.getChild(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testValue() { - ChangeListener listener = this.buildTransformationChangeListener(); - this.transformationObjectHolder.addChangeListener(listener); - - Person person = this.objectHolder.getValue(); - assertEquals("Karen", person.getName()); - Person parent = this.transformationObjectHolder.getValue(); - assertEquals(person.getParent().getName(), parent.getName()); - assertNotSame(person.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent, this.transformationObjectHolder.getValue()); - - Person person1 = new Person("Matt", "Mitch", null); - this.objectHolder.setValue(person1); - Person parent2 = this.transformationObjectHolder.getValue(); - assertEquals(person1.getParent().getName(), parent2.getName()); - assertNotSame(person1.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent2, this.transformationObjectHolder.getValue()); - - - this.objectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); - - Person person3 = new Person("Karen", "Peggy", null); - this.objectHolder.setValue(person3); - assertEquals("Karen", person3.getName()); - Person parent3 = this.transformationObjectHolder.getValue(); - assertEquals(person3.getParent().getName(), parent3.getName()); - assertNotSame(person3.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent3, this.transformationObjectHolder.getValue()); - } - - public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).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)); - } - - public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildChangeListener()); - this.transformationObjectHolder.addChangeListener(this.buildTransformationChangeListener()); - this.verifyPropertyChanges(); - } - - public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.transformationObjectHolder.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 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.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.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.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); - } - - private PropertyChangeListener buildListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CachingTransformationPropertyValueModelTests.this.event = e; - } - }; - } - - private PropertyChangeListener buildTransformationListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CachingTransformationPropertyValueModelTests.this.transformationEvent = e; - } - }; - } - - private ChangeListener buildChangeListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - CachingTransformationPropertyValueModelTests.this.event = e; - } - }; - } - - private ChangeListener buildTransformationChangeListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - CachingTransformationPropertyValueModelTests.this.transformationEvent = e; - } - }; - } - - private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) { - assertEquals(source, e.getSource()); - assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); - assertEquals(oldValue, e.getOldValue()); - assertEquals(newValue, e.getNewValue()); - } - - - class Person extends AbstractModel { - - private String name; - public static final String NAME_PROPERTY = "name"; - - private String parentName; - public static final String PARENT_NAME_PROPERTY = "parentName"; - - private Person child; - - public Person(String name, String parentName, Person child) { - this.name = name; - this.parentName = parentName; - this.child = child; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public Person getParent() { - return new Person(this.parentName, null, this); - } - - public String getParentName() { - return this.parentName; - } - - public void setParentName(String newParentName) { - String oldParentName = this.parentName; - this.parentName = newParentName; - firePropertyChanged(PARENT_NAME_PROPERTY, oldParentName, newParentName); - } - - public Person getChild() { - return this.child; - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java deleted file mode 100644 index 49905c2427..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CachingTransformationWritablePropertyValueModelTests.java +++ /dev/null @@ -1,253 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.BidiTransformer; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.CachingTransformationWritablePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class CachingTransformationWritablePropertyValueModelTests extends TestCase { - private WritablePropertyValueModel<Person> objectHolder; - PropertyChangeEvent event; - - private WritablePropertyValueModel<Person> transformationObjectHolder; - PropertyChangeEvent transformationEvent; - - public CachingTransformationWritablePropertyValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.objectHolder = new SimplePropertyValueModel<Person>(new Person("Karen", "Peggy", null)); - this.transformationObjectHolder = new CachingTransformationWritablePropertyValueModel<Person, Person>(this.objectHolder, this.buildTransformer()); - } - - private BidiTransformer<Person, Person> buildTransformer() { - return new BidiTransformer<Person, Person>() { - public Person transform(Person p) { - return (p == null) ? null : p.getParent(); - } - public Person reverseTransform(Person p) { - return (p == null) ? null : p.getChild(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testValue() { - ChangeListener listener = this.buildTransformationListener(); - this.transformationObjectHolder.addChangeListener(listener); - - - Person person = this.objectHolder.getValue(); - assertEquals("Karen", person.getName()); - Person parent = this.transformationObjectHolder.getValue(); - assertEquals(person.getParent().getName(), parent.getName()); - assertNotSame(person.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent, this.transformationObjectHolder.getValue()); - - Person person1 = new Person("Matt", "Mitch", null); - this.objectHolder.setValue(person1); - Person parent2 = this.transformationObjectHolder.getValue(); - assertEquals(person1.getParent().getName(), parent2.getName()); - assertNotSame(person1.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent2, this.transformationObjectHolder.getValue()); - - - this.objectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); - - Person person3 = new Person("Karen", "Peggy", null); - this.objectHolder.setValue(person3); - assertEquals("Karen", person3.getName()); - Person parent3 = this.transformationObjectHolder.getValue(); - assertEquals(person3.getParent().getName(), parent3.getName()); - assertNotSame(person3.getParent(), this.transformationObjectHolder.getValue()); - assertEquals(parent3, this.transformationObjectHolder.getValue()); - } - - public void testSetValue() { - ChangeListener listener = this.buildTransformationListener(); - this.transformationObjectHolder.addChangeListener(listener); - - Person person = new Person("Chris", "Noel", null); - this.transformationObjectHolder.setValue(person.getParent()); - assertEquals(person, this.objectHolder.getValue()); - assertEquals(person.getParent().getName(), this.transformationObjectHolder.getValue().getName()); - assertNotSame(person.getParent(), this.transformationObjectHolder.getValue()); - - Person person2 = new Person("Jon", "Elizabeth", null); - this.transformationObjectHolder.setValue(person2.getParent()); - assertEquals(person2, this.objectHolder.getValue()); - assertEquals(person2.getParent().getName(), this.transformationObjectHolder.getValue().getName()); - assertNotSame(person2.getParent(), this.transformationObjectHolder.getValue()); - - this.transformationObjectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); - - this.transformationObjectHolder.setValue(person.getParent()); - assertEquals(person, this.objectHolder.getValue()); - assertEquals(person.getParent().getName(), this.transformationObjectHolder.getValue().getName()); - assertNotSame(person.getParent(), this.transformationObjectHolder.getValue()); - } - - public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - ChangeListener listener = this.buildTransformationListener(); - 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)); - } - - public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildListener()); - this.transformationObjectHolder.addChangeListener(this.buildTransformationListener()); - this.verifyPropertyChanges(); - } - - public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); - this.verifyPropertyChanges(); - } - - private void verifyPropertyChanges() { - this.event = null; - this.transformationEvent = null; - Person oldPerson = this.objectHolder.getValue(); - Person oldParent = this.transformationObjectHolder.getValue(); - Person newPerson = new Person("Karen" , "Peggy", null); - this.objectHolder.setValue(newPerson); - Person newParent = this.transformationObjectHolder.getValue(); - this.verifyEvent(this.event, this.objectHolder, oldPerson, newPerson); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, oldParent, newParent); - -// -// this.event = null; -// this.transformationEvent = null; -// this.objectHolder.setValue("Foo"); -// this.verifyEvent(this.event, this.objectHolder, "baz", "Foo"); -// this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "BAZ", "FOO"); -// -// this.event = null; -// this.transformationEvent = null; -// this.objectHolder.setValue("FOO"); -// this.verifyEvent(this.event, this.objectHolder, "Foo", "FOO"); -// assertNull(this.transformationEvent); -// -// this.event = null; -// this.transformationEvent = null; -// this.objectHolder.setValue(null); -// this.verifyEvent(this.event, this.objectHolder, "FOO", null); -// this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "FOO", null); -// -// this.event = null; -// this.transformationEvent = null; -// this.objectHolder.setValue("bar"); -// this.verifyEvent(this.event, this.objectHolder, null, "bar"); -// this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, null, "BAR"); - } - - private ChangeListener buildListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - CachingTransformationWritablePropertyValueModelTests.this.event = e; - } - }; - } - - private ChangeListener buildTransformationListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - CachingTransformationWritablePropertyValueModelTests.this.transformationEvent = e; - } - }; - } - - private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) { - assertEquals(source, e.getSource()); - assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); - assertEquals(oldValue, e.getOldValue()); - assertEquals(newValue, e.getNewValue()); - } - - - class Person extends AbstractModel { - - private String name; - public static final String NAME_PROPERTY = "name"; - - private String parentName; - public static final String PARENT_NAME_PROPERTY = "parentName"; - - private Person child; - - public Person(String name, String parentName, Person child) { - this.name = name; - this.parentName = parentName; - this.child = child; - } - - public String getName() { - return this.name; - } - - public void setName(String newName) { - String oldName = this.name; - this.name = newName; - firePropertyChanged(NAME_PROPERTY, oldName, newName); - } - - public Person getParent() { - return new Person(this.parentName, null, this); - } - - public String getParentName() { - return this.parentName; - } - - public void setParentName(String newParentName) { - String oldParentName = this.parentName; - this.parentName = newParentName; - firePropertyChanged(PARENT_NAME_PROPERTY, oldParentName, newParentName); - } - - public Person getChild() { - return this.child; - } - } -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionAspectAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionAspectAdapterTests.java deleted file mode 100644 index 4d3008d116..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionAspectAdapterTests.java +++ /dev/null @@ -1,372 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class CollectionAspectAdapterTests extends TestCase { - private TestSubject subject1; - private WritablePropertyValueModel<TestSubject> subjectHolder1; - private LocalCollectionAspectAdapter aa1; - private CollectionEvent event1; - private CollectionChangeListener listener1; - private String event1Type; - - private static final String ADD = "add"; - private static final String REMOVE = "remove"; - private static final String CHANGE = "change"; - private static final String CLEAR = "clear"; - - private TestSubject subject2; - - public CollectionAspectAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject1 = new TestSubject(); - this.subject1.addNames(this.subject1Names()); - this.subject1.addDescriptions(this.subject1Descriptions()); - this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1); - this.aa1 = this.buildAspectAdapter(this.subjectHolder1); - this.listener1 = this.buildValueChangeListener1(); - this.aa1.addCollectionChangeListener(CollectionValueModel.VALUES, this.listener1); - this.event1 = null; - this.event1Type = null; - - this.subject2 = new TestSubject(); - this.subject2.addNames(this.subject2Names()); - this.subject2.addDescriptions(this.subject2Descriptions()); - } - - private Collection<String> subject1Names() { - Collection<String> result = new HashBag<String>(); - result.add("foo"); - result.add("bar"); - return result; - } - - private Collection<String> subject1Descriptions() { - Collection<String> result = new HashBag<String>(); - result.add("this.subject1 description1"); - result.add("this.subject1 description2"); - return result; - } - - private Collection<String> subject2Names() { - Collection<String> result = new HashBag<String>(); - result.add("baz"); - result.add("bam"); - return result; - } - - private Collection<String> subject2Descriptions() { - Collection<String> result = new HashBag<String>(); - result.add("this.subject2 description1"); - result.add("this.subject2 description2"); - return result; - } - - private LocalCollectionAspectAdapter buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { - return new LocalCollectionAspectAdapter(subjectHolder); - } - - private CollectionChangeListener buildValueChangeListener1() { - return new CollectionChangeListener() { - public void itemsAdded(CollectionAddEvent e) { - CollectionAspectAdapterTests.this.value1Changed(e, ADD); - } - public void itemsRemoved(CollectionRemoveEvent e) { - CollectionAspectAdapterTests.this.value1Changed(e, REMOVE); - } - public void collectionCleared(CollectionClearEvent e) { - CollectionAspectAdapterTests.this.value1Changed(e, CLEAR); - } - public void collectionChanged(CollectionChangeEvent e) { - CollectionAspectAdapterTests.this.value1Changed(e, CHANGE); - } - }; - } - - void value1Changed(CollectionEvent e, String eventType) { - this.event1 = e; - this.event1Type = eventType; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSubjectHolder() { - assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator())); - assertNull(this.event1); - - this.subjectHolder1.setValue(this.subject2); - assertNotNull(this.event1); - assertEquals(this.event1Type, CHANGE); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event1.getCollectionName()); - assertEquals(this.subject2Names(), CollectionTools.bag(this.aa1.iterator())); - - this.event1 = null; - this.event1Type = null; - this.subjectHolder1.setValue(null); - assertNotNull(this.event1); - assertEquals(this.event1Type, CHANGE); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event1.getCollectionName()); - assertFalse(this.aa1.iterator().hasNext()); - - this.event1 = null; - this.event1Type = null; - this.subjectHolder1.setValue(this.subject1); - assertNotNull(this.event1); - assertEquals(this.event1Type, CHANGE); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event1.getCollectionName()); - assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator())); - } - - public void testAdd() { - assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator())); - assertNull(this.event1); - - this.subject1.addName("jam"); - assertNotNull(this.event1); - assertEquals(this.event1Type, ADD); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event1.getCollectionName()); - assertEquals("jam", ((CollectionAddEvent) this.event1).getItems().iterator().next()); - Collection<String> namesPlus = this.subject1Names(); - namesPlus.add("jam"); - assertEquals(namesPlus, CollectionTools.bag(this.aa1.iterator())); - - this.event1 = null; - this.event1Type = null; - this.aa1.addAll(Collections.singleton("jaz")); - assertNotNull(this.event1); - assertEquals(this.event1Type, ADD); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event1.getCollectionName()); - assertEquals("jaz", ((CollectionAddEvent) this.event1).getItems().iterator().next()); - namesPlus.add("jaz"); - assertEquals(namesPlus, CollectionTools.bag(this.aa1.iterator())); - } - - public void testRemove() { - assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator())); - assertNull(this.event1); - - this.subject1.removeName("foo"); - assertNotNull(this.event1); - assertEquals(this.event1Type, REMOVE); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event1.getCollectionName()); - assertEquals("foo", ((CollectionRemoveEvent) this.event1).getItems().iterator().next()); - Collection<String> namesMinus = this.subject1Names(); - namesMinus.remove("foo"); - assertEquals(namesMinus, CollectionTools.bag(this.aa1.iterator())); - - this.event1 = null; - this.event1Type = null; - this.aa1.removeAll(Collections.singleton("bar")); - assertNotNull(this.event1); - assertEquals(this.event1Type, REMOVE); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event1.getCollectionName()); - assertEquals("bar", ((CollectionRemoveEvent) this.event1).getItems().iterator().next()); - namesMinus.remove("bar"); - assertEquals(namesMinus, CollectionTools.bag(this.aa1.iterator())); - } - - public void testCollectionChange() { - assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator())); - assertNull(this.event1); - - this.subject1.addTwoNames("jam", "jaz"); - assertNotNull(this.event1); - assertEquals(this.event1Type, CHANGE); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event1.getCollectionName()); - Collection<String> namesPlus2 = this.subject1Names(); - namesPlus2.add("jam"); - namesPlus2.add("jaz"); - assertEquals(namesPlus2, CollectionTools.bag(this.aa1.iterator())); - } - - public void testIterator() { - assertEquals(this.subject1Names(), CollectionTools.bag(this.subject1.names())); - assertEquals(this.subject1Names(), CollectionTools.bag(this.aa1.iterator())); - } - - public void testSize() { - assertEquals(this.subject1Names().size(), CollectionTools.size(this.subject1.names())); - assertEquals(this.subject1Names().size(), CollectionTools.size(this.aa1.iterator())); - } - - public void testHasListeners() { - assertTrue(this.aa1.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - assertTrue(this.subject1.hasAnyCollectionChangeListeners(TestSubject.NAMES_COLLECTION)); - this.aa1.removeCollectionChangeListener(CollectionValueModel.VALUES, this.listener1); - assertFalse(this.subject1.hasAnyCollectionChangeListeners(TestSubject.NAMES_COLLECTION)); - assertFalse(this.aa1.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - - ChangeListener listener2 = new ChangeAdapter(); - this.aa1.addChangeListener(listener2); - assertTrue(this.aa1.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - assertTrue(this.subject1.hasAnyCollectionChangeListeners(TestSubject.NAMES_COLLECTION)); - this.aa1.removeChangeListener(listener2); - assertFalse(this.subject1.hasAnyCollectionChangeListeners(TestSubject.NAMES_COLLECTION)); - assertFalse(this.aa1.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - } - - - // ********** inner class ********** - - private class TestSubject extends AbstractModel { - private Collection<String> names; - public static final String NAMES_COLLECTION = "names"; - private Collection<String> descriptions; - public static final String DESCRIPTIONS_COLLECTION = "descriptions"; - - public TestSubject() { - this.names = new HashBag<String>(); - this.descriptions = new HashBag<String>(); - } - public Iterator<String> names() { - return new ReadOnlyIterator<String>(this.names); - } - public void addName(String name) { - if (this.names.add(name)) { - this.fireItemAdded(NAMES_COLLECTION, name); - } - } - public void addNames(Iterator<String> newNames) { - while (newNames.hasNext()) { - this.addName(newNames.next()); - } - } - public void addNames(Collection<String> newNames) { - this.addNames(newNames.iterator()); - } - public void addTwoNames(String name1, String name2) { - if (this.names.add(name1) | this.names.add(name2)) { - this.fireCollectionChanged(NAMES_COLLECTION, this.names); - } - } - public void removeName(String name) { - if (this.names.remove(name)) { - this.fireItemRemoved(NAMES_COLLECTION, name); - } - } - public Iterator<String> descriptions() { - return new ReadOnlyIterator<String>(this.descriptions); - } - public void addDescription(String description) { - if (this.descriptions.add(description)) { - this.fireItemAdded(DESCRIPTIONS_COLLECTION, description); - } - } - public void addDescriptions(Iterator<String> newDescriptions) { - while (newDescriptions.hasNext()) { - this.addDescription(newDescriptions.next()); - } - } - public void addDescriptions(Collection<String> newDescriptions) { - this.addDescriptions(newDescriptions.iterator()); - } - public void removeDescription(String description) { - if (this.descriptions.remove(description)) { - this.fireItemRemoved(DESCRIPTIONS_COLLECTION, description); - } - } - } - - // this is not a typical aspect adapter - the value is determined by the aspect name - private class LocalCollectionAspectAdapter extends CollectionAspectAdapter<TestSubject, String> { - - LocalCollectionAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { - super(subjectHolder, TestSubject.NAMES_COLLECTION); - } - - @Override - protected Iterator<String> iterator_() { - if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) { - return this.subject.names(); - } - if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) { - return this.subject.descriptions(); - } - throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]); - } - - public void add(String item) { - if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) { - this.subject.addName(item); - } else if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) { - this.subject.addDescription(item); - } else { - throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]); - } - } - - public void addAll(Collection<String> items) { - for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) { - this.add(stream.next()); - } - } - - public void remove(Object item) { - if (this.collectionNames[0] == TestSubject.NAMES_COLLECTION) { - this.subject.removeName((String) item); - } else if (this.collectionNames[0] == TestSubject.DESCRIPTIONS_COLLECTION) { - this.subject.removeDescription((String) item); - } else { - throw new IllegalStateException("invalid aspect name: " + this.collectionNames[0]); - } - } - - public void removeAll(Collection<String> items) { - for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) { - this.remove(stream.next()); - } - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionListValueModelAdapterTests.java deleted file mode 100644 index 68357006c1..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionListValueModelAdapterTests.java +++ /dev/null @@ -1,247 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Collection; -import java.util.List; - -import javax.swing.JList; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.CollectionListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class CollectionListValueModelAdapterTests extends TestCase { - private ListValueModel<String> adapter; - private SimpleCollectionValueModel<String> wrappedCollectionHolder; - private Collection<String> wrappedCollection; - - public CollectionListValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.wrappedCollection = new HashBag<String>(); - this.wrappedCollectionHolder = new SimpleCollectionValueModel<String>(this.wrappedCollection); - this.adapter = new CollectionListValueModelAdapter<String>(this.wrappedCollectionHolder); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - }); - this.wrappedCollectionHolder.add("foo"); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - Collection<String> adapterCollection = this.adapterCollection(); - assertEquals(3, adapterCollection.size()); - assertEquals(this.wrappedCollection, adapterCollection); - } - - private Collection<String> adapterCollection() { - return CollectionTools.collection(this.adapter.iterator()); - } - - public void testStaleValue() { - ListChangeListener listener = new TestListChangeListener() { - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - }; - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, listener); - this.wrappedCollectionHolder.add("foo"); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - Collection<String> adapterCollection = this.adapterCollection(); - assertEquals(3, adapterCollection.size()); - assertEquals(this.wrappedCollection, adapterCollection); - - this.adapter.removeListChangeListener(ListValueModel.LIST_VALUES, listener); - adapterCollection = this.adapterCollection(); - assertEquals(0, adapterCollection.size()); - assertEquals(new HashBag<String>(), adapterCollection); - - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, listener); - adapterCollection = this.adapterCollection(); - assertEquals(3, adapterCollection.size()); - assertEquals(this.wrappedCollection, adapterCollection); - } - - public void testAdd() { - List<String> synchList = new CoordinatedList<String>(this.adapter); - Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder); - this.wrappedCollectionHolder.add("foo"); - assertTrue(this.wrappedCollection.contains("foo")); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - this.wrappedCollectionHolder.add("joo"); - this.wrappedCollectionHolder.add("jar"); - this.wrappedCollectionHolder.add("jaz"); - assertEquals(6, this.wrappedCollection.size()); - - Collection<String> adapterCollection = this.adapterCollection(); - assertEquals(this.wrappedCollection, adapterCollection); - assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator())); - assertEquals(this.wrappedCollection, synchCollection); - } - - public void testRemove() { - List<String> synchList = new CoordinatedList<String>(this.adapter); - Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder); - this.wrappedCollectionHolder.add("foo"); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - this.wrappedCollectionHolder.add("joo"); - this.wrappedCollectionHolder.add("jar"); - this.wrappedCollectionHolder.add("jaz"); - assertTrue(this.wrappedCollection.contains("jaz")); - this.wrappedCollectionHolder.remove("jaz"); - assertFalse(this.wrappedCollection.contains("jaz")); - this.wrappedCollectionHolder.remove("foo"); - assertFalse(this.wrappedCollection.contains("foo")); - assertEquals(4, this.wrappedCollection.size()); - - Collection<String> adapterCollection = this.adapterCollection(); - assertEquals(this.wrappedCollection, adapterCollection); - assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator())); - assertEquals(this.wrappedCollection, synchCollection); - } - - public void testListSynch() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - @Override - public void itemsRemoved(ListRemoveEvent e) {/* OK */} - }); - this.wrappedCollectionHolder.add("foo"); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - this.wrappedCollectionHolder.add("joo"); - this.wrappedCollectionHolder.add("jar"); - this.wrappedCollectionHolder.add("jaz"); - this.wrappedCollectionHolder.remove("jaz"); - assertFalse(this.wrappedCollection.contains("jaz")); - this.wrappedCollectionHolder.remove("foo"); - assertFalse(this.wrappedCollection.contains("foo")); - assertEquals(4, this.wrappedCollection.size()); - - Collection<String> adapterCollection = this.adapterCollection(); - assertEquals(this.wrappedCollection, adapterCollection); - } - - public void testHasListeners() { - assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - CoordinatedList<String> synchList = new CoordinatedList<String>(this.adapter); - assertTrue(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.adapter.removeListChangeListener(ListValueModel.LIST_VALUES, synchList); - assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - ChangeListener cl = new ChangeAdapter(); - this.adapter.addChangeListener(cl); - assertTrue(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.adapter.removeChangeListener(cl); - assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - public void testCollectionChangedToEmpty() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void listCleared(ListClearEvent e) {/* OK */} - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - }); - this.wrappedCollectionHolder.add("foo"); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - JList jList = new JList(new ListModelAdapter(this.adapter)); - this.wrappedCollectionHolder.setValues(new HashBag<String>()); - assertEquals(0, jList.getModel().getSize()); - } - - public void testCollectionChangedFromEmpty() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - @Override - public void itemsRemoved(ListRemoveEvent e) {/* OK */} - }); - JList jList = new JList(new ListModelAdapter(this.adapter)); - - HashBag<String> bag = new HashBag<String>(); - bag.add("foo"); - bag.add("bar"); - this.wrappedCollectionHolder.setValues(bag); - assertEquals(2, jList.getModel().getSize()); - } - - public void testCollectionChangedFromEmptyToEmpty() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - @Override - public void itemsRemoved(ListRemoveEvent e) {/* OK */} - }); - JList jList = new JList(new ListModelAdapter(this.adapter)); - - HashBag<String> bag = new HashBag<String>(); - this.wrappedCollectionHolder.setValues(bag); - assertEquals(0, jList.getModel().getSize()); - } - - - class TestListChangeListener implements ListChangeListener { - public void itemsAdded(ListAddEvent e) { - fail("unexpected event"); - } - public void itemsRemoved(ListRemoveEvent e) { - fail("unexpected event"); - } - public void itemsReplaced(ListReplaceEvent e) { - fail("unexpected event"); - } - public void itemsMoved(ListMoveEvent e) { - fail("unexpected event"); - } - public void listCleared(ListClearEvent e) { - fail("unexpected event"); - } - public void listChanged(ListChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java deleted file mode 100644 index c4e43d99e3..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CollectionPropertyValueModelAdapterTests.java +++ /dev/null @@ -1,240 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Collection; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.CollectionPropertyValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class CollectionPropertyValueModelAdapterTests extends TestCase { - private WritablePropertyValueModel<Boolean> adapter; - private SimpleCollectionValueModel<String> wrappedCollectionHolder; - PropertyChangeEvent event; - - public CollectionPropertyValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.wrappedCollectionHolder = new SimpleCollectionValueModel<String>(); - this.adapter = new LocalAdapter(this.wrappedCollectionHolder, "666"); - this.event = null; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - private boolean booleanValue() { - return this.adapter.getValue().booleanValue(); - } - - private Collection<String> wrappedCollection() { - return CollectionTools.collection(this.wrappedCollectionHolder.iterator()); - } - - public void testValue() { - this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) {/* OK */} - }); - assertFalse(this.booleanValue()); - assertFalse(this.wrappedCollection().contains("666")); - - this.wrappedCollectionHolder.add("111"); - assertFalse(this.booleanValue()); - - this.wrappedCollectionHolder.add("222"); - assertFalse(this.booleanValue()); - - this.wrappedCollectionHolder.add("666"); - assertTrue(this.booleanValue()); - assertTrue(this.wrappedCollection().contains("666")); - - this.wrappedCollectionHolder.remove("666"); - assertFalse(this.booleanValue()); - assertFalse(this.wrappedCollection().contains("666")); - - this.wrappedCollectionHolder.add("666"); - assertTrue(this.booleanValue()); - assertTrue(this.wrappedCollection().contains("666")); - - this.wrappedCollectionHolder.clear(); - assertFalse(this.booleanValue()); - assertFalse(this.wrappedCollection().contains("666")); - } - - public void testSetValue() { - this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) {/* OK */} - }); - assertFalse(this.booleanValue()); - assertFalse(this.wrappedCollection().contains("666")); - - this.adapter.setValue(Boolean.TRUE); - assertTrue(this.booleanValue()); - assertTrue(this.wrappedCollection().contains("666")); - - this.adapter.setValue(Boolean.FALSE); - assertFalse(this.booleanValue()); - assertFalse(this.wrappedCollection().contains("666")); - } - - public void testEventFiring() { - this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - CollectionPropertyValueModelAdapterTests.this.event = e; - } - }); - assertNull(this.event); - - this.wrappedCollectionHolder.add("111"); - assertNull(this.event); - - this.wrappedCollectionHolder.add("222"); - assertNull(this.event); - - this.wrappedCollectionHolder.add("666"); - this.verifyEvent(false, true); - - this.wrappedCollectionHolder.remove("666"); - this.verifyEvent(true, false); - - this.wrappedCollectionHolder.add("666"); - this.verifyEvent(false, true); - - this.wrappedCollectionHolder.clear(); - this.verifyEvent(true, false); - } - - private void verifyEvent(boolean oldValue, boolean newValue) { - assertEquals(this.adapter, this.event.getSource()); - assertEquals(Boolean.valueOf(oldValue), this.event.getOldValue()); - assertEquals(Boolean.valueOf(newValue), this.event.getNewValue()); - this.event = null; - } - - public void testStaleValue() { - PropertyChangeListener listener = new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) {/* OK */} - }; - this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - this.wrappedCollectionHolder.add("666"); - assertTrue(this.booleanValue()); - assertTrue(this.wrappedCollection().contains("666")); - - this.adapter.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertFalse(this.booleanValue()); - assertTrue(this.wrappedCollection().contains("666")); - - this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(this.booleanValue()); - assertTrue(this.wrappedCollection().contains("666")); - } - - public void testHasListeners() { - assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - - ChangeListener listener = new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) {/* OK */} - }; - this.adapter.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - - this.adapter.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - - this.adapter.addChangeListener(listener); - assertTrue(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - - this.adapter.removeChangeListener(listener); - assertFalse(((AbstractModel) this.adapter).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(((AbstractModel) this.wrappedCollectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - } - - - // ********** member class ********** - - /** - * the value is true if the wrapped collection contains the specified item, - * otherwise the value is false - */ - static class LocalAdapter - extends CollectionPropertyValueModelAdapter<Boolean> - implements WritablePropertyValueModel<Boolean> - { - private String item; - - LocalAdapter(CollectionValueModel<String> collectionHolder, String item) { - super(collectionHolder); - this.item = item; - } - - // ********** CollectionPropertyValueModelAdapter implementation ********** - /** - * always return a Boolean - */ - @Override - public Boolean getValue() { - Boolean result = super.getValue(); - return (result == null) ? Boolean.FALSE : result; - } - @SuppressWarnings("unchecked") - public void setValue(Boolean value) { - if (this.booleanValue()) { - if ( ! this.booleanValueOf(value)) { - // the value is changing from true to false - ((SimpleCollectionValueModel<String>) this.collectionHolder).remove(this.item); - } - } else { - if (this.booleanValueOf(value)) { - // the value is changing from false to true - ((SimpleCollectionValueModel<String>) this.collectionHolder).add(this.item); - } - } - } - @Override - protected Boolean buildValue() { - return Boolean.valueOf(CollectionTools.contains(this.collectionHolder.iterator(), this.item)); - } - - // ********** internal methods ********** - private boolean booleanValue() { - return this.booleanValueOf(this.value); - } - private boolean booleanValueOf(Object b) { - return (b == null) ? false : ((Boolean) b).booleanValue(); - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeCollectionValueModelTests.java deleted file mode 100644 index 1a7b688bd1..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeCollectionValueModelTests.java +++ /dev/null @@ -1,414 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.Transformer; -import org.eclipse.jpt.utility.internal.iterators.CompositeIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.CompositeCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class CompositeCollectionValueModelTests extends TestCase { - private Neighborhood neighborhood; - private WritablePropertyValueModel<Neighborhood> neighborhoodHolder; - - public CompositeCollectionValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.neighborhood = new Neighborhood("Hanna-Barbera"); - this.neighborhoodHolder = new SimplePropertyValueModel<Neighborhood>(this.neighborhood); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSynch1() { - this.verifySynch(this.buildAllMembersComposite(this.neighborhoodHolder)); - } - - public void testSynch2() { - this.verifySynch(this.buildAllMembersComposite2(this.neighborhoodHolder)); - } - - private void verifySynch(CollectionValueModel<Member> compositeCVM) { - assertEquals(0, CollectionTools.size(compositeCVM.iterator())); - Bag<Family> familiesSynch = new CoordinatedBag<Family>(this.buildFamiliesAspectAdapter(this.neighborhoodHolder)); - Bag<Member> membersSynch = new CoordinatedBag<Member>(compositeCVM); - this.populateNeighborhood(this.neighborhood); - - Family jetsons = this.neighborhood.familyNamed("Jetson"); - - assertEquals(3, familiesSynch.size()); - assertEquals(12, CollectionTools.size(this.neighborhood.allMembers())); - assertEquals(12, membersSynch.size()); - assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch); - assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator())); - - jetsons.removeMember(jetsons.memberNamed("Astro")); - assertEquals(3, familiesSynch.size()); - assertEquals(11, CollectionTools.size(this.neighborhood.allMembers())); - assertEquals(11, membersSynch.size()); - assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch); - assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator())); - - jetsons.removeMember(jetsons.memberNamed("Judy")); - assertEquals(3, familiesSynch.size()); - assertEquals(10, CollectionTools.size(this.neighborhood.allMembers())); - assertEquals(10, membersSynch.size()); - assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch); - assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator())); - - jetsons.addMember("Fido"); - assertEquals(3, familiesSynch.size()); - assertEquals(11, CollectionTools.size(this.neighborhood.allMembers())); - assertEquals(11, membersSynch.size()); - assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch); - assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator())); - - this.neighborhood.removeFamily(jetsons); - assertEquals(2, familiesSynch.size()); - assertEquals(7, CollectionTools.size(this.neighborhood.allMembers())); - assertEquals(7, membersSynch.size()); - assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch); - assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator())); - - Family bears = this.neighborhood.addFamily("Bear"); - bears.addMember("Yogi"); - assertEquals(3, familiesSynch.size()); - assertEquals(8, CollectionTools.size(this.neighborhood.allMembers())); - assertEquals(8, membersSynch.size()); - assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch); - assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator())); - - bears.addMember("Boo-Boo"); - assertEquals(3, familiesSynch.size()); - assertEquals(9, CollectionTools.size(this.neighborhood.allMembers())); - assertEquals(9, membersSynch.size()); - assertEquals(CollectionTools.bag(this.neighborhood.allMembers()), membersSynch); - assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator())); - - Neighborhood n2 = new Neighborhood("Hanna-Barbera 2"); - this.neighborhoodHolder.setValue(n2); - this.populateNeighborhood(n2); - assertEquals(3, familiesSynch.size()); - assertEquals(12, CollectionTools.size(n2.allMembers())); - assertEquals(12, membersSynch.size()); - assertEquals(CollectionTools.bag(n2.allMembers()), membersSynch); - assertEquals(membersSynch, CollectionTools.bag(compositeCVM.iterator())); - } - - public void testNoTransformer() { - SimpleCollectionValueModel<String> subCVM1 = new SimpleCollectionValueModel<String>(); - SimpleCollectionValueModel<String> subCVM2 = new SimpleCollectionValueModel<String>(); - Collection<CollectionValueModel<String>> collection = new ArrayList<CollectionValueModel<String>>(); - collection.add(subCVM1); - collection.add(subCVM2); - Bag<String> synchBag = new CoordinatedBag<String>(new CompositeCollectionValueModel<CollectionValueModel<String>, String>(collection)); - - assertEquals(0, synchBag.size()); - - subCVM1.add("foo"); - subCVM1.add("bar"); - subCVM1.add("baz"); - assertEquals(3, synchBag.size()); - assertTrue(synchBag.contains("foo")); - - subCVM2.add("joo"); - subCVM2.add("jar"); - subCVM2.add("jaz"); - assertEquals(6, synchBag.size()); - assertTrue(synchBag.contains("foo")); - assertTrue(synchBag.contains("jaz")); - - subCVM1.remove("baz"); - assertEquals(5, synchBag.size()); - assertFalse(synchBag.contains("baz")); - } - - public void testDuplicateItem() { - Bag<Member> synchBag = new CoordinatedBag<Member>(this.buildAllMembersComposite(this.neighborhoodHolder)); - this.populateNeighborhood(this.neighborhood); - boolean exCaught = false; - try { - this.neighborhood.addFamily(this.neighborhood.familyNamed("Jetson")); - } catch (IllegalStateException ex) { - if (ex.getMessage().indexOf("duplicate component") != -1) { - exCaught = true; - } - } - assertTrue(exCaught); - assertEquals(12, synchBag.size()); - } - - public void testHasListeners() { - CompositeCollectionValueModel<Family, Member> compositeCVM = this.buildAllMembersComposite(this.neighborhoodHolder); - CoordinatedBag<Member> synchBag = new CoordinatedBag<Member>(compositeCVM); - this.populateNeighborhood(this.neighborhood); - Family jetsons = this.neighborhood.familyNamed("Jetson"); - - assertTrue(compositeCVM.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - assertTrue(jetsons.hasAnyCollectionChangeListeners(Family.MEMBERS_COLLECTION)); - - compositeCVM.removeCollectionChangeListener(CollectionValueModel.VALUES, synchBag); - assertFalse(compositeCVM.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - assertFalse(jetsons.hasAnyCollectionChangeListeners(Family.MEMBERS_COLLECTION)); - - compositeCVM.addCollectionChangeListener(CollectionValueModel.VALUES, synchBag); - assertTrue(compositeCVM.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - assertTrue(jetsons.hasAnyCollectionChangeListeners(Family.MEMBERS_COLLECTION)); - } - - private void populateNeighborhood(Neighborhood n) { - Family family1 = n.addFamily("Flintstone"); - family1.addMember("Fred"); - family1.addMember("Wilma"); - family1.addMember("Pebbles"); - family1.addMember("Dino"); - Family family2 = n.addFamily("Rubble"); - family2.addMember("Barney"); - family2.addMember("Betty"); - family2.addMember("Bamm-Bamm"); - Family family3 = n.addFamily("Jetson"); - family3.addMember("George"); - family3.addMember("Jane"); - family3.addMember("Judy"); - family3.addMember("Elroy"); - family3.addMember("Astro"); - } - - private CollectionValueModel<Family> buildFamiliesAspectAdapter(PropertyValueModel<Neighborhood> communeHolder) { - return new CollectionAspectAdapter<Neighborhood, Family>(communeHolder, Neighborhood.FAMILIES_COLLECTION) { - @Override - protected Iterator<Family> iterator_() { - return this.subject.families(); - } - }; - } - - CollectionValueModel<Member> buildMembersAdapter(Family family) { - return new CollectionAspectAdapter<Family, Member>(Family.MEMBERS_COLLECTION, family) { - @Override - protected Iterator<Member> iterator_() { - return this.subject.members(); - } - }; - } - - private CompositeCollectionValueModel<Family, Member> buildAllMembersComposite(PropertyValueModel<Neighborhood> communeHolder) { - // override #transform(Object) - return new CompositeCollectionValueModel<Family, Member>(this.buildFamiliesAspectAdapter(communeHolder)) { - @Override - protected CollectionValueModel<Member> transform(Family family) { - return CompositeCollectionValueModelTests.this.buildMembersAdapter(family); - } - }; - } - - private CollectionValueModel<Member> buildAllMembersComposite2(PropertyValueModel<Neighborhood> communeHolder) { - // build a custom Transformer - return new CompositeCollectionValueModel<Family, Member>(this.buildFamiliesAspectAdapter(communeHolder), this.buildTransformer()); - } - - private Transformer<Family, CollectionValueModel<Member>> buildTransformer() { - return new Transformer<Family, CollectionValueModel<Member>>() { - public CollectionValueModel<Member> transform(Family family) { - return CompositeCollectionValueModelTests.this.buildMembersAdapter(family); - } - @Override - public String toString() { - return "Local Transformer"; - } - }; - } - - -// ********** inner classes ********** - - /** - * inner class - */ - private class Neighborhood extends AbstractModel { - private String name; - public static final String NAME_PROPERTY = "name"; - private Collection<Family> families = new ArrayList<Family>(); - public static final String FAMILIES_COLLECTION = "families"; - - public Neighborhood(String name) { - super(); - this.name = name; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - public Iterator<Family> families() { - return this.families.iterator(); - } - - public Family addFamily(String familyName) { - return this.addFamily(new Family(familyName)); - } - - // backdoor to allow duplicates - public Family addFamily(Family family) { - this.addItemToCollection(family, this.families, FAMILIES_COLLECTION); - return family; - } - - public void removeFamily(Family family) { - this.removeItemFromCollection(family, this.families, FAMILIES_COLLECTION); - } - - public Family familyNamed(String familyName) { - for (Family family : this.families) { - if (family.getName().equals(familyName)) { - return family; - } - } - throw new IllegalArgumentException(familyName); - } - - public Iterator<Member> allMembers() { - return new CompositeIterator<Member>(this.membersIterators()); - } - - private Iterator<Iterator<Member>> membersIterators() { - return new TransformationIterator<Family, Iterator<Member>>(this.families()) { - @Override - protected Iterator<Member> transform(Family family) { - return family.members(); - } - }; - } - - public Member memberNamed(String familyName, String memberName) { - return this.familyNamed(familyName).memberNamed(memberName); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - } - - - /** - * inner class - */ - private class Family extends AbstractModel { - private String name; - public static final String NAME_PROPERTY = "name"; - private Collection<Member> members = new ArrayList<Member>(); - public static final String MEMBERS_COLLECTION = "members"; - - public Family(String name) { - super(); - this.name = name; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - public Iterator<Member> members() { - return this.members.iterator(); - } - - public Member addMember(String memberName) { - Member member = new Member(memberName); - this.addItemToCollection(member, this.members, MEMBERS_COLLECTION); - return member; - } - - public void removeMember(Member member) { - this.removeItemFromCollection(member, this.members, MEMBERS_COLLECTION); - } - - public Member memberNamed(String memberName) { - for (Member member : this.members) { - if (member.getName().equals(memberName)) { - return member; - } - } - throw new IllegalArgumentException(memberName); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - } - - - /** - * inner class - */ - private class Member extends AbstractModel { - private String name; - public static final String NAME_PROPERTY = "name"; - - public Member(String name) { - super(); - this.name = name; - } - - public String getName() { - return this.name; - } - - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - @Override - public void toString(StringBuilder sb) { - sb.append(this.name); - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java deleted file mode 100644 index 5c1223ae4e..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositeListValueModelTests.java +++ /dev/null @@ -1,847 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.model.value.CompositeListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class CompositeListValueModelTests extends TestCase { - private SimpleListValueModel<String> lvm0; - private SimpleListValueModel<String> lvm1; - private SimpleListValueModel<String> lvm2; - private SimpleListValueModel<String> lvm3; - private SimpleListValueModel<SimpleListValueModel<String>> uberLVM; - private CompositeListValueModel<SimpleListValueModel<String>, String> compositeLVM; - - public CompositeListValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - - this.lvm0 = new SimpleListValueModel<String>(); - this.lvm0.add("aaa"); - this.lvm0.add("bbb"); - this.lvm0.add("ccc"); - - this.lvm1 = new SimpleListValueModel<String>(); - this.lvm1.add("ddd"); - this.lvm1.add("eee"); - - this.lvm2 = new SimpleListValueModel<String>(); - this.lvm2.add("fff"); - - this.lvm3 = new SimpleListValueModel<String>(); - this.lvm3.add("ggg"); - this.lvm3.add("hhh"); - this.lvm3.add("iii"); - this.lvm3.add("jjj"); - this.lvm3.add("kkk"); - - this.uberLVM = new SimpleListValueModel<SimpleListValueModel<String>>(); - this.uberLVM.add(this.lvm0); - this.uberLVM.add(this.lvm1); - this.uberLVM.add(this.lvm2); - this.uberLVM.add(this.lvm3); - - this.compositeLVM = new CompositeListValueModel<SimpleListValueModel<String>, String>((ListValueModel<SimpleListValueModel<String>>) this.uberLVM); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testGetInt() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - assertEquals("aaa", this.compositeLVM.get(0)); - assertEquals("aaa", coordList.get(0)); - assertEquals("bbb", this.compositeLVM.get(1)); - assertEquals("bbb", coordList.get(1)); - assertEquals("ccc", this.compositeLVM.get(2)); - assertEquals("ccc", coordList.get(2)); - - assertEquals("ddd", this.compositeLVM.get(3)); - assertEquals("ddd", coordList.get(3)); - assertEquals("eee", this.compositeLVM.get(4)); - assertEquals("eee", coordList.get(4)); - - assertEquals("fff", this.compositeLVM.get(5)); - assertEquals("fff", coordList.get(5)); - - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testIterator() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - assertEquals("aaa", this.compositeLVM.iterator().next()); - assertEquals("aaa", coordList.iterator().next()); - Iterator<String> stream1 = coordList.iterator(); - for (Iterator<String> stream2 = this.compositeLVM.iterator(); stream2.hasNext(); ) { - assertEquals(stream1.next(), stream2.next()); - } - assertFalse(stream1.hasNext()); - } - - public void testSize() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - assertEquals(11, this.compositeLVM.size()); - assertEquals(11, coordList.size()); - } - - public void testToArray() { - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - } - - public void testHasListeners() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - assertTrue(this.compositeLVM.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.lvm0.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - this.compositeLVM.removeListChangeListener(ListValueModel.LIST_VALUES, coordList); - assertFalse(this.compositeLVM.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.lvm0.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - this.compositeLVM.addListChangeListener(ListValueModel.LIST_VALUES, coordList); - assertTrue(this.compositeLVM.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.lvm0.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - public void testAddSource_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - SimpleListValueModel<String> lvm = new SimpleListValueModel<String>(); - lvm.add("xxx"); - lvm.add("yyy"); - lvm.add("zzz"); - this.uberLVM.add(0, lvm); - - Object[] expected = new Object[] { "xxx", "yyy", "zzz", "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(9)); - assertEquals("ggg", coordList.get(9)); - } - - public void testAddSource_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - SimpleListValueModel<String> lvm = new SimpleListValueModel<String>(); - lvm.add("xxx"); - lvm.add("yyy"); - lvm.add("zzz"); - this.uberLVM.add(2, lvm); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "xxx", "yyy", "zzz", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(9)); - assertEquals("ggg", coordList.get(9)); - } - - public void testAddSource_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - SimpleListValueModel<String> lvm = new SimpleListValueModel<String>(); - lvm.add("xxx"); - lvm.add("yyy"); - lvm.add("zzz"); - this.uberLVM.add(lvm); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "xxx", "yyy", "zzz" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testAddSources() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - SimpleListValueModel<String> lvmA = new SimpleListValueModel<String>(); - lvmA.add("xxx"); - lvmA.add("yyy"); - lvmA.add("zzz"); - SimpleListValueModel<String> lvmB = new SimpleListValueModel<String>(); - lvmB.add("ppp"); - lvmB.add("qqq"); - lvmB.add("rrr"); - Collection<SimpleListValueModel<String>> c = new ArrayList<SimpleListValueModel<String>>(); - c.add(lvmA); - c.add(lvmB); - this.uberLVM.addAll(2, c); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "xxx", "yyy", "zzz", "ppp", "qqq", "rrr", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(12)); - assertEquals("ggg", coordList.get(12)); - } - - public void testRemoveSource_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.remove(0); - - Object[] expected = new Object[] { "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(3)); - assertEquals("ggg", coordList.get(3)); - } - - public void testRemoveSource_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.remove(2); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(5)); - assertEquals("ggg", coordList.get(5)); - } - - public void testRemoveSource_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.remove(3); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("fff", this.compositeLVM.get(5)); - assertEquals("fff", coordList.get(5)); - } - - public void testRemoveSources() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.remove(2, 2); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("eee", this.compositeLVM.get(4)); - assertEquals("eee", coordList.get(4)); - } - - public void testReplaceSources() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - SimpleListValueModel<String> lvmA = new SimpleListValueModel<String>(); - lvmA.add("xxx"); - lvmA.add("yyy"); - lvmA.add("zzz"); - SimpleListValueModel<String> lvmB = new SimpleListValueModel<String>(); - lvmB.add("ppp"); - lvmB.add("qqq"); - lvmB.add("rrr"); - List<SimpleListValueModel<String>> list = new ArrayList<SimpleListValueModel<String>>(); - list.add(lvmA); - list.add(lvmB); - this.uberLVM.set(2, list); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "xxx", "yyy", "zzz", "ppp", "qqq", "rrr" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("qqq", this.compositeLVM.get(9)); - assertEquals("qqq", coordList.get(9)); - } - - public void testMoveSources_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.move(0, 2, 2); - - Object[] expected = new Object[] { "fff", "ggg", "hhh", "iii", "jjj", "kkk", "aaa", "bbb", "ccc", "ddd", "eee" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(1)); - assertEquals("ggg", coordList.get(1)); - } - - public void testMoveSources_Middle() { - SimpleListValueModel<String> lvm4 = new SimpleListValueModel<String>(); - lvm4.add("lll"); - lvm4.add("mmm"); - this.uberLVM.add(lvm4); - - SimpleListValueModel<String> lvm5 = new SimpleListValueModel<String>(); - lvm5.add("nnn"); - lvm5.add("ooo"); - lvm5.add("ppp"); - lvm5.add("qqq"); - this.uberLVM.add(lvm5); - - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.move(1, 3, 2); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm", "ddd", "eee", "fff", "nnn", "ooo", "ppp", "qqq" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(3)); - assertEquals("ggg", coordList.get(3)); - } - - public void testMoveSources_End() { - SimpleListValueModel<String> lvm4 = new SimpleListValueModel<String>(); - lvm4.add("lll"); - lvm4.add("mmm"); - this.uberLVM.add(lvm4); - - SimpleListValueModel<String> lvm5 = new SimpleListValueModel<String>(); - lvm5.add("nnn"); - lvm5.add("ooo"); - lvm5.add("ppp"); - lvm5.add("qqq"); - this.uberLVM.add(lvm5); - - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.move(3, 0, 3); - - Object[] expected = new Object[] { "ggg", "hhh", "iii", "jjj", "kkk", "lll", "mmm", "nnn", "ooo", "ppp", "qqq", "aaa", "bbb", "ccc", "ddd", "eee", "fff" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(0)); - assertEquals("ggg", coordList.get(0)); - } - - public void testMoveSource() { - SimpleListValueModel<String> lvm4 = new SimpleListValueModel<String>(); - lvm4.add("lll"); - lvm4.add("mmm"); - this.uberLVM.add(lvm4); - - SimpleListValueModel<String> lvm5 = new SimpleListValueModel<String>(); - lvm5.add("nnn"); - lvm5.add("ooo"); - lvm5.add("ppp"); - lvm5.add("qqq"); - this.uberLVM.add(lvm5); - - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.move(3, 1); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "ddd", "eee", "lll", "mmm", "nnn", "ooo", "ppp", "qqq" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ooo", this.compositeLVM.get(14)); - assertEquals("ooo", coordList.get(14)); - } - - public void testClearSources() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.clear(); - - Object[] expected = new Object[0]; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - } - - public void testChangeSources() { - List<SimpleListValueModel<String>> newList = new ArrayList<SimpleListValueModel<String>>(); - SimpleListValueModel<String> lvm4 = new SimpleListValueModel<String>(); - lvm4.add("lll"); - lvm4.add("mmm"); - newList.add(lvm4); - - SimpleListValueModel<String> lvm5 = new SimpleListValueModel<String>(); - lvm5.add("nnn"); - lvm5.add("ooo"); - lvm5.add("ppp"); - lvm5.add("qqq"); - newList.add(lvm5); - - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.uberLVM.setListValues(newList); - - Object[] expected = new Object[] { "lll", "mmm", "nnn", "ooo", "ppp", "qqq" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ooo", this.compositeLVM.get(3)); - assertEquals("ooo", coordList.get(3)); - } - - public void testAddItem_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.add(0, "xxx"); - - Object[] expected = new Object[] { "xxx", "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(7)); - assertEquals("ggg", coordList.get(7)); - } - - public void testAddItem_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm2.add(1, "xxx"); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "xxx", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(7)); - assertEquals("ggg", coordList.get(7)); - } - - public void testAddItem_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.add(5, "xxx"); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "xxx" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testAddItems_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.addAll(0, Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); - - Object[] expected = new Object[] { "xxx", "yyy", "zzz", "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(9)); - assertEquals("ggg", coordList.get(9)); - } - - public void testAddItems_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm2.addAll(1, Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "xxx", "yyy", "zzz", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(9)); - assertEquals("ggg", coordList.get(9)); - } - - public void testAddItems_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.addAll(5, Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk", "xxx", "yyy", "zzz" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testRemoveItem_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.remove(0); - - Object[] expected = new Object[] { "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(5)); - assertEquals("ggg", coordList.get(5)); - } - - public void testRemoveItem_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm2.remove(0); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(5)); - assertEquals("ggg", coordList.get(5)); - } - - public void testRemoveItem_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.remove(4); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testRemoveItems_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.remove(0, 3); - - Object[] expected = new Object[] { "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(3)); - assertEquals("ggg", coordList.get(3)); - } - - public void testRemoveItems_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.remove(1, 3); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("kkk", this.compositeLVM.get(7)); - assertEquals("kkk", coordList.get(7)); - } - - public void testRemoveItems_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.remove(3, 2); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testReplaceItem_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.set(0, "xxx"); - - Object[] expected = new Object[] { "xxx", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testReplaceItem_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm2.set(0, "xxx"); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "xxx", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testReplaceItem_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.set(4, "xxx"); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "xxx" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testReplaceItems_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.set(0, Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); - - Object[] expected = new Object[] { "xxx", "yyy", "zzz", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testReplaceItems_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.set(1, Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "xxx", "yyy", "zzz", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("kkk", this.compositeLVM.get(10)); - assertEquals("kkk", coordList.get(10)); - } - - public void testReplaceItems_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.set(3, Arrays.asList(new String[] { "xxx", "yyy" })); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "ggg", "hhh", "iii", "xxx", "yyy" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testMoveItem_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.move(2, 0); - - Object[] expected = new Object[] { "bbb", "ccc", "aaa", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testMoveItem_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm1.move(0, 1); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "eee", "ddd", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testMoveItem_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.move(0, 4); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "kkk", "ggg", "hhh", "iii", "jjj" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(7)); - assertEquals("ggg", coordList.get(7)); - } - - public void testMoveItems_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.move(1, 0, 2); - - Object[] expected = new Object[] { "ccc", "aaa", "bbb", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testMoveItems_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm1.add("eee.1"); - this.lvm1.add("eee.2"); - this.lvm1.add("eee.3"); - this.lvm1.move(1, 2, 3); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee.1", "eee.2", "eee.3", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(9)); - assertEquals("ggg", coordList.get(9)); - } - - public void testMoveItems_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.move(0, 2, 3); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "iii", "jjj", "kkk", "ggg", "hhh" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(9)); - assertEquals("ggg", coordList.get(9)); - } - - public void testClearItems_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.clear(); - - Object[] expected = new Object[] { "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(3)); - assertEquals("ggg", coordList.get(3)); - } - - public void testClearItems_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm1.clear(); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(4)); - assertEquals("ggg", coordList.get(4)); - } - - public void testClearItems_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.clear(); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("fff", this.compositeLVM.get(5)); - assertEquals("fff", coordList.get(5)); - } - - public void testChangeItems_Begin() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm0.setListValues(Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); - - Object[] expected = new Object[] { "xxx", "yyy", "zzz", "ddd", "eee", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(6)); - assertEquals("ggg", coordList.get(6)); - } - - public void testChangeItems_Middle() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm1.setListValues(Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "xxx", "yyy", "zzz", "fff", "ggg", "hhh", "iii", "jjj", "kkk" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("ggg", this.compositeLVM.get(7)); - assertEquals("ggg", coordList.get(7)); - } - - public void testChangeItems_End() { - CoordinatedList<String> coordList = new CoordinatedList<String>(this.compositeLVM); - - this.lvm3.setListValues(Arrays.asList(new String[] { "xxx", "yyy", "zzz" })); - - Object[] expected = new Object[] { "aaa", "bbb", "ccc", "ddd", "eee", "fff", "xxx", "yyy", "zzz" }; - assertEquals(expected.length, this.compositeLVM.size()); - assertEquals(expected.length, coordList.size()); - assertTrue(Arrays.equals(expected, this.compositeLVM.toArray())); - assertTrue(Arrays.equals(expected, coordList.toArray())); - assertEquals("fff", this.compositeLVM.get(5)); - assertEquals("fff", coordList.get(5)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositePropertyValueModelTests.java deleted file mode 100644 index f528b09fe2..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CompositePropertyValueModelTests.java +++ /dev/null @@ -1,195 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.value.CompositePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class CompositePropertyValueModelTests extends TestCase { - private SimplePropertyValueModel<Integer> pvm1; - private WritablePropertyValueModel<Integer> pvm2; - private WritablePropertyValueModel<Integer> pvm3; - private WritablePropertyValueModel<Integer> pvm4; - private Collection<WritablePropertyValueModel<Integer>> collection; - private SimpleCollectionValueModel<WritablePropertyValueModel<Integer>> cvm; - private PropertyValueModel<Integer> compositePVM; - PropertyChangeEvent event; - - - public CompositePropertyValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.pvm1 = new SimplePropertyValueModel<Integer>(Integer.valueOf(1)); - this.pvm2 = new SimplePropertyValueModel<Integer>(Integer.valueOf(2)); - this.pvm3 = new SimplePropertyValueModel<Integer>(Integer.valueOf(3)); - this.pvm4 = new SimplePropertyValueModel<Integer>(Integer.valueOf(4)); - this.collection = new ArrayList<WritablePropertyValueModel<Integer>>(); - this.collection.add(this.pvm1); - this.collection.add(this.pvm2); - this.collection.add(this.pvm3); - this.collection.add(this.pvm4); - this.cvm = new SimpleCollectionValueModel<WritablePropertyValueModel<Integer>>(this.collection); - - this.compositePVM = this.buildCompositePVM(cvm); - } - - private <T extends PropertyValueModel<?>> PropertyValueModel<Integer> buildCompositePVM(CollectionValueModel<T> pvms) { - return new CompositePropertyValueModel<Integer>(pvms) { - @SuppressWarnings("unchecked") - @Override - protected Integer buildValue() { - int sum = 0; - for (Object each : this.collectionHolder) { - sum += ((PropertyValueModel<Integer>) each).getValue().intValue(); - } - return Integer.valueOf(sum); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testGetValue() { - assertNull(this.compositePVM.getValue()); - ChangeListener listener = this.buildListener(); - this.compositePVM.addChangeListener(listener); - assertEquals(10, this.compositePVM.getValue().intValue()); - } - - public void testValueAndListeners1() { - assertNull(this.compositePVM.getValue()); - ChangeListener listener = this.buildListener(); - this.compositePVM.addChangeListener(listener); - assertEquals(10, this.compositePVM.getValue().intValue()); - this.compositePVM.removeChangeListener(listener); - assertNull(this.compositePVM.getValue()); - } - - public void testValueAndListeners2() { - assertNull(this.compositePVM.getValue()); - ChangeListener listener = this.buildListener(); - this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertEquals(10, this.compositePVM.getValue().intValue()); - this.compositePVM.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertNull(this.compositePVM.getValue()); - } - - public void testPropertyChange1() { - this.compositePVM.addChangeListener(this.buildListener()); - this.verifyPropertyChange(); - } - - public void testPropertyChange2() { - this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.verifyPropertyChange(); - } - - private void verifyPropertyChange() { - this.event = null; - this.pvm1.setValue(Integer.valueOf(5)); - this.verifyEvent(10, 14); - - this.event = null; - this.pvm4.setValue(Integer.valueOf(0)); - this.verifyEvent(14, 10); - } - - public void testCollectionChange1() { - this.compositePVM.addChangeListener(this.buildListener()); - this.verifyCollectionChange(); - } - - public void testCollectionChange2() { - this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.verifyCollectionChange(); - } - - private void verifyCollectionChange() { - this.event = null; - WritablePropertyValueModel<Integer> pvm = new SimplePropertyValueModel<Integer>(Integer.valueOf(77)); - this.cvm.add(pvm); - this.verifyEvent(10, 87); - - this.event = null; - this.cvm.remove(pvm); - this.verifyEvent(87, 10); - - this.event = null; - this.cvm.clear(); - this.verifyEvent(10, 0); - - Collection<WritablePropertyValueModel<Integer>> c2 = new ArrayList<WritablePropertyValueModel<Integer>>(); - c2.add(this.pvm1); - c2.add(this.pvm2); - this.event = null; - this.cvm.setValues(c2); - this.verifyEvent(0, 3); - } - - public void testLazyListening1() { - assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - ChangeListener listener = this.buildListener(); - - this.compositePVM.addChangeListener(listener); - assertTrue(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.compositePVM.removeChangeListener(listener); - assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - public void testLazyListening2() { - assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - ChangeListener listener = this.buildListener(); - - this.compositePVM.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.compositePVM.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertFalse(this.pvm1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - private ChangeListener buildListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - CompositePropertyValueModelTests.this.event = e; - } - }; - } - - private void verifyEvent(int oldValue, int newValue) { - assertEquals(this.compositePVM, this.event.getSource()); - assertEquals(PropertyValueModel.VALUE, this.event.getPropertyName()); - assertEquals(Integer.valueOf(oldValue), this.event.getOldValue()); - assertEquals(Integer.valueOf(newValue), this.event.getNewValue()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedBag.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedBag.java deleted file mode 100644 index d45fad6ff1..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedBag.java +++ /dev/null @@ -1,163 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Collection; -import java.util.Iterator; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; - -/** - * Helper class that keeps an internal collection in synch with the - * collection held by a collection value model. - */ -class CoordinatedBag<E> implements Bag<E>, CollectionChangeListener { - - private Bag<E> bag = new HashBag<E>(); - - CoordinatedBag(CollectionValueModel<E> cvm) { - cvm.addCollectionChangeListener(CollectionValueModel.VALUES, this); - } - - - // ********** Collection implementation ********** - - public boolean add(E o) { - return this.bag.add(o); - } - - public boolean addAll(Collection<? extends E> c) { - return this.bag.addAll(c); - } - - public void clear() { - this.bag.clear(); - } - - public boolean contains(Object o) { - return this.bag.contains(o); - } - - public boolean containsAll(Collection<?> c) { - return this.bag.containsAll(c); - } - - public boolean isEmpty() { - return this.bag.isEmpty(); - } - - public Iterator<E> iterator() { - return this.bag.iterator(); - } - - public boolean remove(Object o) { - return this.bag.remove(o); - } - - public boolean removeAll(Collection<?> c) { - return this.bag.removeAll(c); - } - - public boolean retainAll(Collection<?> c) { - return this.bag.retainAll(c); - } - - public int size() { - return this.bag.size(); - } - - public Object[] toArray() { - return this.bag.toArray(); - } - - public <T> T[] toArray(T[] a) { - return this.bag.toArray(a); - } - - - // ********** Bag implementation ********** - - public int count(Object o) { - return this.bag.count(o); - } - - public boolean add(E o, int count) { - return this.bag.add(o, count); - } - - public boolean remove(Object o, int count) { - return this.bag.remove(o, count); - } - - public Iterator<E> uniqueIterator() { - return this.bag.uniqueIterator(); - } - - public int uniqueCount() { - return this.bag.uniqueCount(); - } - - public Iterator<Bag.Entry<E>> entries() { - return this.bag.entries(); - } - - // ********** CollectionChangeListener implementation ********** - - @SuppressWarnings("unchecked") - public void itemsAdded(CollectionAddEvent event) { - for (E item : (Iterable<E>) event.getItems()) { - this.bag.add(item); - } - } - - @SuppressWarnings("unchecked") - public void itemsRemoved(CollectionRemoveEvent event) { - for (E item : (Iterable<E>) event.getItems()) { - this.bag.remove(item); - } - } - - public void collectionCleared(CollectionClearEvent event) { - this.bag.clear(); - } - - @SuppressWarnings("unchecked") - public void collectionChanged(CollectionChangeEvent event) { - this.bag.clear(); - CollectionTools.addAll(this.bag, ((CollectionValueModel<E>) event.getSource()).iterator()); - } - - - // ********** standard methods ********** - - @Override - public boolean equals(Object o) { - return this.bag.equals(o); - } - - @Override - public int hashCode() { - return this.bag.hashCode(); - } - - @Override - public String toString() { - return this.bag.toString(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedList.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedList.java deleted file mode 100644 index 70ea298224..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/CoordinatedList.java +++ /dev/null @@ -1,264 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import javax.swing.ListModel; -import javax.swing.event.ListDataEvent; -import javax.swing.event.ListDataListener; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * Helper class that keeps an internal list in synch with the - * list held by a list value model. - */ -public class CoordinatedList<E> implements List<E>, ListChangeListener, ListDataListener { - private List<E> list = new ArrayList<E>(); - - public CoordinatedList(ListValueModel<E> listValueModel) { - listValueModel.addListChangeListener(ListValueModel.LIST_VALUES, this); - for (Iterator<E> stream = listValueModel.iterator(); stream.hasNext(); ) { - this.add(stream.next()); - } - } - - public CoordinatedList(ListModel listModel) { - listModel.addListDataListener(this); - for (int i = 0; i < listModel.getSize(); i++) { - this.add(i, this.getElementAt(listModel, i)); - } - } - - - // ********** List implementation ********** - - public void add(int index, E element) { - this.list.add(index, element); - } - - public boolean add(E o) { - return this.list.add(o); - } - - public boolean addAll(Collection<? extends E> c) { - return this.list.addAll(c); - } - - public boolean addAll(int index, Collection<? extends E> c) { - return this.list.addAll(index, c); - } - - public void clear() { - this.list.clear(); - } - - public boolean contains(Object o) { - return this.list.contains(o); - } - - public boolean containsAll(Collection<?> c) { - return this.list.containsAll(c); - } - - public E get(int index) { - return this.list.get(index); - } - - public int indexOf(Object o) { - return this.list.indexOf(o); - } - - public boolean isEmpty() { - return this.list.isEmpty(); - } - - public Iterator<E> iterator() { - return this.list.iterator(); - } - - public int lastIndexOf(Object o) { - return this.list.lastIndexOf(o); - } - - public ListIterator<E> listIterator() { - return this.list.listIterator(); - } - - public ListIterator<E> listIterator(int index) { - return this.list.listIterator(index); - } - - public E remove(int index) { - return this.list.remove(index); - } - - public boolean remove(Object o) { - return this.list.remove(o); - } - - public boolean removeAll(Collection<?> c) { - return this.list.removeAll(c); - } - - public boolean retainAll(Collection<?> c) { - return this.list.retainAll(c); - } - - public E set(int index, E element) { - return this.list.set(index, element); - } - - public int size() { - return this.list.size(); - } - - public List<E> subList(int fromIndex, int toIndex) { - return this.list.subList(fromIndex, toIndex); - } - - public Object[] toArray() { - return this.list.toArray(); - } - - public <T> T[] toArray(T[] a) { - return this.list.toArray(a); - } - - - // ********** ListChangeListener implementation ********** - - public void itemsAdded(ListAddEvent e) { - int i = e.getIndex(); - for (E item : this.getItems(e)) { - this.list.add(i++, item); - } - } - - public void itemsRemoved(ListRemoveEvent e) { - int base = e.getIndex(); - for (int i = e.getItemsSize(); i-- > 0; ) { - this.list.remove(base + i); // remove from end - } - } - - public void itemsReplaced(ListReplaceEvent e) { - int i = e.getIndex(); - for (E item : this.getNewItems(e)) { - this.list.set(i++, item); - } - } - - public void itemsMoved(ListMoveEvent e) { - CollectionTools.move(this.list, e.getTargetIndex(), e.getSourceIndex(), e.getLength()); - } - - public void listCleared(ListClearEvent e) { - this.list.clear(); - } - - public void listChanged(ListChangeEvent e) { - this.list.clear(); - CollectionTools.addAll(this.list, this.getSource(e).iterator()); - } - - - // ********** ListDataListener implementation ********** - - public void contentsChanged(ListDataEvent e) { - this.list.clear(); - ListModel lm = (ListModel) e.getSource(); - int size = lm.getSize(); - for (int i = 0; i < size; i++) { - this.list.add(i, this.getElementAt(lm, i)); - } - } - - public void intervalAdded(ListDataEvent e) { - ListModel lm = (ListModel) e.getSource(); - int start = Math.min(e.getIndex0(), e.getIndex1()); - int end = Math.max(e.getIndex0(), e.getIndex1()); - for (int i = start; i <= end; i++) { - this.list.add(i, this.getElementAt(lm, i)); - } - } - - public void intervalRemoved(ListDataEvent e) { - int start = Math.min(e.getIndex0(), e.getIndex1()); - int end = Math.max(e.getIndex0(), e.getIndex1()); - int length = end - start + 1; - for (int i = 1; i <= length; i++) { - this.list.remove(start); - } - } - - - // ********** standard methods ********** - - @Override - public boolean equals(Object o) { - return this.list.equals(o); - } - - @Override - public int hashCode() { - return this.list.hashCode(); - } - - @Override - public String toString() { - return this.list.toString(); - } - - - // ********** internal methods ********** - - /** - * minimize the scope of the suppressed warnings.= - */ - @SuppressWarnings("unchecked") - private E getElementAt(ListModel listModel, int index) { - return (E) listModel.getElementAt(index); - } - - // minimized scope of suppressed warnings - @SuppressWarnings("unchecked") - private Iterable<E> getItems(ListAddEvent event) { - return (Iterable<E>) event.getItems(); - } - - // minimized scope of suppressed warnings - @SuppressWarnings("unchecked") - private Iterable<E> getNewItems(ListReplaceEvent event) { - return (Iterable<E>) event.getNewItems(); - } - - /** - * minimize the scope of the suppressed warnings.= - */ - @SuppressWarnings("unchecked") - private ListValueModel<E> getSource(ListChangeEvent event) { - return (ListValueModel<E>) event.getSource(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ExtendedListValueModelWrapperTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ExtendedListValueModelWrapperTests.java deleted file mode 100644 index 7f64503bd1..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ExtendedListValueModelWrapperTests.java +++ /dev/null @@ -1,313 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ExtendedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ExtendedListValueModelWrapperTests extends TestCase { - private SimpleListValueModel<String> listHolder; - private ListValueModel<String> extendedListHolder; - ListEvent event; - String eventType; - - private static final String ADD = "add"; - private static final String REMOVE = "remove"; - private static final String REPLACE = "replace"; - private static final String MOVE = "move"; - private static final String CLEAR = "clear"; - private static final String CHANGE = "change"; - - public ExtendedListValueModelWrapperTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.listHolder = new SimpleListValueModel<String>(this.buildList()); - this.extendedListHolder = this.buildExtendedListHolder(this.listHolder); - } - - private List<String> buildList() { - List<String> result = new ArrayList<String>(); - result.add("A"); - result.add("B"); - result.add("C"); - result.add("D"); - return result; - } - - private List<String> buildExtendedList() { - List<String> extendedList = new ArrayList<String>(); - extendedList.addAll(this.buildPrefix()); - extendedList.addAll(this.buildList()); - extendedList.addAll(this.buildSuffix()); - return extendedList; - } - - private List<String> buildPrefix() { - List<String> prefix = new ArrayList<String>(); - prefix.add("x"); - prefix.add("y"); - prefix.add("z"); - return prefix; - } - - private List<String> buildSuffix() { - List<String> suffix = new ArrayList<String>(); - suffix.add("i"); - suffix.add("j"); - return suffix; - } - - private ListValueModel<String> buildExtendedListHolder(ListValueModel<String> lvm) { - return new ExtendedListValueModelWrapper<String>(this.buildPrefix(), lvm, this.buildSuffix()); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - this.extendedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - assertEquals(this.buildExtendedList(), CollectionTools.list(this.extendedListHolder.iterator())); - } - - public void testSize() { - this.extendedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - assertEquals(this.buildExtendedList().size(), CollectionTools.size(this.extendedListHolder.iterator())); - assertEquals(this.buildExtendedList().size(), this.extendedListHolder.size()); - } - - private boolean extendedListContains(Object item) { - return CollectionTools.contains(this.extendedListHolder.iterator(), item); - } - - private boolean extendedListContainsAll(Collection<String> items) { - return CollectionTools.containsAll(this.extendedListHolder.iterator(), items); - } - - private boolean extendedListContainsAny(Collection<String> items) { - List<String> extendedList = CollectionTools.list(this.extendedListHolder.iterator()); - for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) { - if (extendedList.contains(stream.next())) { - return true; - } - } - return false; - } - - private boolean listContains(Object item) { - return CollectionTools.contains(this.listHolder.iterator(), item); - } - - private boolean listContainsAll(Collection<String> items) { - return CollectionTools.containsAll(this.listHolder.iterator(), items); - } - -// private boolean listContainsAny(Collection<String> items) { -// List<String> extendedList = CollectionTools.list(this.listHolder.iterator()); -// for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) { -// if (extendedList.contains(stream.next())) { -// return true; -// } -// } -// return false; -// } -// - public void testAdd1() { - this.extendedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - - assertFalse(this.extendedListContains("E")); - this.listHolder.add(4, "E"); - assertTrue(this.extendedListContains("E")); - assertTrue(this.listContains("E")); - } - - public void testAdd2() { - this.extendedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - - assertFalse(this.extendedListContains(null)); - this.listHolder.add(4, null); - assertTrue(this.extendedListContains(null)); - assertTrue(this.listContains(null)); - } - - private List<String> buildAddList() { - List<String> addList = new ArrayList<String>(); - addList.add("E"); - addList.add("F"); - return addList; - } - - public void testAddAll1() { - this.extendedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - - assertFalse(this.extendedListContainsAny(this.buildAddList())); - this.listHolder.addAll(4, this.buildAddList()); - assertTrue(this.extendedListContainsAll(this.buildAddList())); - assertTrue(this.listContainsAll(this.buildAddList())); - } - - public void testRemove1() { - this.extendedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - - assertTrue(this.extendedListContains("B")); - this.listHolder.remove(this.buildList().indexOf("B")); - assertFalse(this.extendedListContains("B")); - assertFalse(this.listContains("B")); - } - - public void testListChangeGeneric() { - this.extendedListHolder.addChangeListener(this.buildListener()); - this.verifyListChange(); - } - - public void testListChangeNamed() { - this.extendedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - this.verifyListChange(); - } - - private void verifyListChange() { - this.event = null; - this.eventType = null; - this.listHolder.add(4, "E"); - this.verifyEvent(ADD, 7, "E"); - - this.event = null; - this.eventType = null; - this.listHolder.add(5, null); - this.verifyEvent(ADD, 8, null); - - this.event = null; - this.eventType = null; - this.listHolder.remove(5); - this.verifyEvent(REMOVE, 8, null); - - this.event = null; - this.eventType = null; - this.listHolder.remove(4); - this.verifyEvent(REMOVE, 7, "E"); - - this.event = null; - this.eventType = null; - this.listHolder.addAll(0, this.buildList()); - this.verifyEvent(ADD); - assertEquals(this.buildList(), CollectionTools.list(((ListAddEvent) this.event).getItems())); - - this.event = null; - this.eventType = null; - this.listHolder.set(0, "AA"); - this.verifyEvent(REPLACE); - assertFalse(CollectionTools.contains(((ListReplaceEvent) this.event).getNewItems(), "A")); - assertTrue(CollectionTools.contains(((ListReplaceEvent) this.event).getNewItems(), "AA")); - } - - private ChangeListener buildListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(ListAddEvent e) { - ExtendedListValueModelWrapperTests.this.eventType = ADD; - ExtendedListValueModelWrapperTests.this.event = e; - } - @Override - public void itemsRemoved(ListRemoveEvent e) { - ExtendedListValueModelWrapperTests.this.eventType = REMOVE; - ExtendedListValueModelWrapperTests.this.event = e; - } - @Override - public void itemsReplaced(ListReplaceEvent e) { - ExtendedListValueModelWrapperTests.this.eventType = REPLACE; - ExtendedListValueModelWrapperTests.this.event = e; - } - @Override - public void itemsMoved(ListMoveEvent e) { - ExtendedListValueModelWrapperTests.this.eventType = MOVE; - ExtendedListValueModelWrapperTests.this.event = e; - } - @Override - public void listCleared(ListClearEvent e) { - ExtendedListValueModelWrapperTests.this.eventType = CLEAR; - ExtendedListValueModelWrapperTests.this.event = e; - } - @Override - public void listChanged(ListChangeEvent e) { - ExtendedListValueModelWrapperTests.this.eventType = CHANGE; - ExtendedListValueModelWrapperTests.this.event = e; - } - }; - } - - private void verifyEvent(String type) { - assertEquals(type, this.eventType); - assertEquals(this.extendedListHolder, this.event.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event.getListName()); - } - - private void verifyEvent(String type, int index, Object item) { - this.verifyEvent(type); - if (type == ADD) { - assertEquals(index, ((ListAddEvent) this.event).getIndex()); - assertEquals(item, ((ListAddEvent) this.event).getItems().iterator().next()); - } else if (type == REMOVE) { - assertEquals(index, ((ListRemoveEvent) this.event).getIndex()); - assertEquals(item, ((ListRemoveEvent) this.event).getItems().iterator().next()); - } - } - - public void testHasListeners() { - /* - * adding listeners to the extended list will cause listeners - * to be added to the wrapped list; - * likewise, removing listeners from the extended list will - * cause listeners to be removed from the wrapped list - */ - assertFalse(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - ChangeListener listener = this.buildListener(); - - this.extendedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, listener); - assertTrue(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - this.extendedListHolder.removeListChangeListener(ListValueModel.LIST_VALUES, listener); - assertFalse(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - this.extendedListHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - this.extendedListHolder.removeChangeListener(listener); - assertFalse(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java deleted file mode 100644 index bf03010b88..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringCollectionValueModelTests.java +++ /dev/null @@ -1,348 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Collection; -import java.util.Iterator; -import java.util.Vector; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.Filter; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.FilteringCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class FilteringCollectionValueModelTests extends TestCase { - private SimpleCollectionValueModel<String> collectionHolder; - CollectionAddEvent addEvent; - CollectionRemoveEvent removeEvent; - CollectionClearEvent collectionClearedEvent; - CollectionChangeEvent collectionChangedEvent; - - private CollectionValueModel<String> filteredCollectionHolder; - CollectionAddEvent filteredAddEvent; - CollectionRemoveEvent filteredRemoveEvent; - CollectionClearEvent filteredCollectionClearedEvent; - CollectionChangeEvent filteredCollectionChangedEvent; - - public FilteringCollectionValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.collectionHolder = new SimpleCollectionValueModel<String>(buildCollection()); - this.filteredCollectionHolder = new FilteringCollectionValueModel<String>(this.collectionHolder, this.buildFilter()); - } - - private Collection<String> buildCollection() { - Collection<String> collection = new Vector<String>(); - collection.add("foo"); - return collection; - } - - private Filter<String> buildFilter() { - return new Filter<String>() { - public boolean accept(String s) { - return s.startsWith("b"); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - // add a listener to "activate" the wrapper - this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener()); - - assertEquals("foo", this.collectionHolder.iterator().next()); - assertFalse(this.filteredCollectionHolder.iterator().hasNext()); - - this.collectionHolder.add("bar"); - Iterator<String> collectionHolderValue = this.collectionHolder.iterator(); - assertEquals("foo", collectionHolderValue.next()); - assertEquals("bar", collectionHolderValue.next()); - assertTrue(this.filteredCollectionHolder.iterator().hasNext()); - assertEquals("bar", this.filteredCollectionHolder.iterator().next()); - - this.collectionHolder.remove("bar"); - assertEquals("foo", this.collectionHolder.iterator().next()); - assertFalse(this.filteredCollectionHolder.iterator().hasNext()); - - this.collectionHolder.remove("foo"); - assertFalse(this.collectionHolder.iterator().hasNext()); - assertFalse(this.filteredCollectionHolder.iterator().hasNext()); - - this.collectionHolder.add("foo"); - assertEquals("foo", this.collectionHolder.iterator().next()); - assertFalse(this.filteredCollectionHolder.iterator().hasNext()); - } - - public void testSetValue() { - // add a listener to "activate" the wrapper - this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener()); - - Collection<String> newCollection = new Vector<String>(); - newCollection.add("fox"); - newCollection.add("baz"); - - this.collectionHolder.setValues(newCollection); - - Iterator<String> collectionValues = this.collectionHolder.iterator(); - assertEquals("fox", collectionValues.next()); - assertEquals("baz", collectionValues.next()); - Iterator<String> filteredCollectionValues = this.filteredCollectionHolder.iterator(); - assertEquals("baz", filteredCollectionValues.next()); - assertFalse(filteredCollectionValues.hasNext()); - } - - public void testLazyListening() { - assertTrue(((AbstractModel) this.collectionHolder).hasNoCollectionChangeListeners(CollectionValueModel.VALUES)); - ChangeListener listener = this.buildFilteredChangeListener(); - this.filteredCollectionHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.collectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - this.filteredCollectionHolder.removeChangeListener(listener); - assertTrue(((AbstractModel) this.collectionHolder).hasNoCollectionChangeListeners(CollectionValueModel.VALUES)); - - this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, listener); - assertTrue(((AbstractModel) this.collectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - this.filteredCollectionHolder.removeCollectionChangeListener(CollectionValueModel.VALUES, listener); - assertTrue(((AbstractModel) this.collectionHolder).hasNoCollectionChangeListeners(CollectionValueModel.VALUES)); - } - - public void testCollectionChange1() { - this.collectionHolder.addChangeListener(this.buildChangeListener()); - this.filteredCollectionHolder.addChangeListener(this.buildFilteredChangeListener()); - this.verifyCollectionChanges(); - } - - public void testCollectionChange2() { - this.collectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildListener()); - this.filteredCollectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener()); - this.verifyCollectionChanges(); - } - - private void clearEvents() { - this.addEvent = null; - this.removeEvent = null; - this.collectionClearedEvent = null; - this.collectionChangedEvent = null; - this.filteredAddEvent = null; - this.filteredRemoveEvent = null; - this.filteredCollectionClearedEvent = null; - this.filteredCollectionChangedEvent = null; - } - - private void verifyCollectionChanges() { - clearEvents(); - this.collectionHolder.add("bar"); - Collection<String> tempCollection = new Vector<String>(); - tempCollection.add("bar"); - this.verifyEvent(this.addEvent, this.collectionHolder, tempCollection); - this.verifyEvent(this.filteredAddEvent, this.filteredCollectionHolder, tempCollection); - - clearEvents(); - this.collectionHolder.remove("foo"); - tempCollection.remove("bar"); - tempCollection.add("foo"); - this.verifyEvent(this.removeEvent, this.collectionHolder, tempCollection); - assertNull(this.filteredRemoveEvent); - - - clearEvents(); - this.collectionHolder.remove("bar"); - tempCollection.add("bar"); - tempCollection.remove("foo"); - this.verifyEvent(this.removeEvent, this.collectionHolder, tempCollection); - this.verifyEvent(this.filteredRemoveEvent, this.filteredCollectionHolder, tempCollection); - - - clearEvents(); - this.collectionHolder.add("foo"); - tempCollection.remove("bar"); - tempCollection.add("foo"); - this.verifyEvent(this.addEvent, this.collectionHolder, tempCollection); - assertNull(this.filteredAddEvent); - - - clearEvents(); - Collection<String> newCollection = new Vector<String>(); - newCollection.add("fox"); - newCollection.add("baz"); - - this.collectionHolder.setValues(newCollection); - - this.verifyEvent(this.collectionChangedEvent, this.collectionHolder); - - tempCollection.remove("foo"); - tempCollection.add("baz"); - this.verifyEvent(this.filteredCollectionChangedEvent, this.filteredCollectionHolder); - - } - - private CollectionChangeListener buildListener() { - return new CollectionChangeListener() { - public void itemsAdded(CollectionAddEvent e) { - FilteringCollectionValueModelTests.this.addEvent = e; - } - public void itemsRemoved(CollectionRemoveEvent e) { - FilteringCollectionValueModelTests.this.removeEvent = e; - } - public void collectionCleared(CollectionClearEvent e) { - FilteringCollectionValueModelTests.this.collectionClearedEvent = e; - } - public void collectionChanged(CollectionChangeEvent e) { - FilteringCollectionValueModelTests.this.collectionChangedEvent = e; - } - }; - } - - private ChangeListener buildChangeListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(CollectionAddEvent e) { - FilteringCollectionValueModelTests.this.addEvent = e; - } - @Override - public void itemsRemoved(CollectionRemoveEvent e) { - FilteringCollectionValueModelTests.this.removeEvent = e; - } - @Override - public void collectionCleared(CollectionClearEvent e) { - FilteringCollectionValueModelTests.this.collectionClearedEvent = e; - } - @Override - public void collectionChanged(CollectionChangeEvent e) { - FilteringCollectionValueModelTests.this.collectionChangedEvent = e; - } - }; - } - - private CollectionChangeListener buildFilteredListener() { - return new CollectionChangeListener() { - public void itemsAdded(CollectionAddEvent e) { - FilteringCollectionValueModelTests.this.filteredAddEvent = e; - } - public void itemsRemoved(CollectionRemoveEvent e) { - FilteringCollectionValueModelTests.this.filteredRemoveEvent = e; - } - public void collectionCleared(CollectionClearEvent e) { - FilteringCollectionValueModelTests.this.filteredCollectionClearedEvent = e; - } - public void collectionChanged(CollectionChangeEvent e) { - FilteringCollectionValueModelTests.this.filteredCollectionChangedEvent = e; - } - }; - } - - private ChangeListener buildFilteredChangeListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(CollectionAddEvent e) { - FilteringCollectionValueModelTests.this.filteredAddEvent = e; - } - @Override - public void itemsRemoved(CollectionRemoveEvent e) { - FilteringCollectionValueModelTests.this.filteredRemoveEvent = e; - } - @Override - public void collectionCleared(CollectionClearEvent e) { - FilteringCollectionValueModelTests.this.filteredCollectionClearedEvent = e; - } - @Override - public void collectionChanged(CollectionChangeEvent e) { - FilteringCollectionValueModelTests.this.filteredCollectionChangedEvent = e; - } - }; - } - - private void verifyEvent(CollectionChangeEvent event, Object source) { - assertEquals(source, event.getSource()); - assertEquals(CollectionValueModel.VALUES, event.getCollectionName()); - } - - private void verifyEvent(CollectionAddEvent event, Object source, Object items) { - assertEquals(source, event.getSource()); - assertEquals(CollectionValueModel.VALUES, event.getCollectionName()); - assertEquals(items, CollectionTools.vector(event.getItems())); - } - - private void verifyEvent(CollectionRemoveEvent event, Object source, Object items) { - assertEquals(source, event.getSource()); - assertEquals(CollectionValueModel.VALUES, event.getCollectionName()); - assertEquals(items, CollectionTools.vector(event.getItems())); - } - - public void testRemoveFilteredItem() { - // build collection with TestItems - SimpleCollectionValueModel<TestItem> tiHolder = new SimpleCollectionValueModel<TestItem>(this.buildCollection2()); - CollectionValueModel<TestItem> filteredTIHolder = new FilteringCollectionValueModel<TestItem>(tiHolder, this.buildFilter2()); - // add a listener to "activate" the wrapper - filteredTIHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildFilteredListener()); - - assertEquals(0, filteredTIHolder.size()); - - tiHolder.add(new TestItem("bar")); - assertEquals(1, filteredTIHolder.size()); - - TestItem baz = new TestItem("baz"); - tiHolder.add(baz); - assertEquals(2, filteredTIHolder.size()); - // before removing it, change the item so that it is filtered - baz.name = "jaz"; - tiHolder.remove(baz); - // this would fail because the item was not removed from - // the filtered collection cache... but we've fixed it now - assertEquals(1, filteredTIHolder.size()); - } - - private Collection<TestItem> buildCollection2() { - Collection<TestItem> collection = new Vector<TestItem>(); - collection.add(new TestItem("foo")); - return collection; - } - - private Filter<TestItem> buildFilter2() { - return new Filter<TestItem>() { - public boolean accept(TestItem ti) { - return ti.name.startsWith("b"); - } - }; - } - - - // ********** TestItem inner class ********** - - private class TestItem { - String name; - TestItem(String name) { - super(); - this.name = name; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java deleted file mode 100644 index b676dda6a5..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/FilteringPropertyValueModelTests.java +++ /dev/null @@ -1,191 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.BidiFilter; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.FilteringWritablePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class FilteringPropertyValueModelTests extends TestCase { - private WritablePropertyValueModel<String> objectHolder; - PropertyChangeEvent event; - - private WritablePropertyValueModel<String> filteredObjectHolder; - PropertyChangeEvent filteredEvent; - - public FilteringPropertyValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.objectHolder = new SimplePropertyValueModel<String>("foo"); - this.filteredObjectHolder = new FilteringWritablePropertyValueModel<String>(this.objectHolder, this.buildFilter()); - } - - private BidiFilter<String> buildFilter() { - return new BidiFilter<String>() { - public boolean accept(String s) { - return (s != null) && s.startsWith("b"); - } - public boolean reverseAccept(String s) { - return (s != null) && s.startsWith("b"); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - 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()); - } - - 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()); - } - - public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).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)); - } - - public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildListener()); - this.filteredObjectHolder.addChangeListener(this.buildFilteredListener()); - this.verifyPropertyChanges(); - } - - public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.filteredObjectHolder.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"); - } - - private ChangeListener buildListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - FilteringPropertyValueModelTests.this.event = e; - } - }; - } - - private ChangeListener buildFilteredListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - FilteringPropertyValueModelTests.this.filteredEvent = e; - } - }; - } - - private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) { - assertEquals(source, e.getSource()); - assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); - assertEquals(oldValue, e.getOldValue()); - assertEquals(newValue, e.getNewValue()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemCollectionListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemCollectionListValueModelAdapterTests.java deleted file mode 100644 index e35d3c137d..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemCollectionListValueModelAdapterTests.java +++ /dev/null @@ -1,243 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.swing.Icon; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ItemCollectionListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.swing.Displayable; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ItemCollectionListValueModelAdapterTests extends TestCase { - private Junk foo; - private Junk bar; - private Junk baz; - private Junk joo; - private Junk jar; - private Junk jaz; - - private Junk tom; - private Junk dick; - private Junk harry; - - public ItemCollectionListValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.foo = new Junk("foo"); - this.bar = new Junk("bar"); - this.baz = new Junk("baz"); - this.joo = new Junk("joo"); - this.jar = new Junk("jar"); - this.jaz = new Junk("jaz"); - - this.tom = new Junk("tom"); - this.dick = new Junk("dick"); - this.harry = new Junk("harry"); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testCollectionSynchronization() { - SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder(); - ListValueModel<Junk> listValueModel = new ItemCollectionListValueModelAdapter<Junk>(collectionHolder, Junk.STUFF_COLLECTION); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - collectionHolder.add(this.tom); - collectionHolder.add(this.dick); - collectionHolder.add(this.harry); - assertEquals(9, synchList.size()); - this.compare(listValueModel, synchList); - - collectionHolder.remove(this.foo); - collectionHolder.remove(this.jar); - collectionHolder.remove(this.harry); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - } - - public void testListSynchronization() { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemCollectionListValueModelAdapter<Junk>(listHolder, Junk.STUFF_COLLECTION); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - listHolder.add(6, this.tom); - listHolder.add(7, this.dick); - listHolder.add(8, this.harry); - assertEquals(9, synchList.size()); - this.compare(listValueModel, synchList); - - listHolder.remove(8); - listHolder.remove(0); - listHolder.remove(4); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - } - - private void compare(ListValueModel<Junk> listValueModel, List<Junk> list) { - assertEquals(listValueModel.size(), list.size()); - for (int i = 0; i < listValueModel.size(); i++) { - assertEquals(listValueModel.get(i), list.get(i)); - } - } - - - public void testHasListeners() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyListChangeListeners(Junk.STUFF_COLLECTION)); - assertFalse(this.jaz.hasAnyListChangeListeners(Junk.STUFF_COLLECTION)); - - ListValueModel<Junk> listValueModel = new ItemCollectionListValueModelAdapter<Junk>(listHolder, Junk.STUFF_COLLECTION); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION)); - assertFalse(this.jaz.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION)); - this.verifyHasNoListeners(listValueModel); - - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.foo.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION)); - assertTrue(this.jaz.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION)); - this.verifyHasListeners(listValueModel); - - listValueModel.removeListChangeListener(ListValueModel.LIST_VALUES, synchList); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION)); - assertFalse(this.jaz.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION)); - this.verifyHasNoListeners(listValueModel); - } - - public void testGetSize() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemCollectionListValueModelAdapter<Junk>(listHolder, Junk.STUFF_COLLECTION); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - this.verifyHasListeners(listValueModel); - assertEquals(6, listValueModel.size()); - assertEquals(6, synchList.size()); - } - - public void testGet() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new SortedListValueModelWrapper<Junk>(new ItemCollectionListValueModelAdapter<Junk>(listHolder, Junk.STUFF_COLLECTION)); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - this.verifyHasListeners(listValueModel); - assertEquals(this.bar, listValueModel.get(0)); - assertEquals(this.bar, synchList.get(0)); - this.bar.removeStuff("bar"); - this.bar.addStuff("zzz"); - this.bar.addStuff("bar"); - assertEquals(this.bar, listValueModel.get(5)); - assertEquals(this.bar, synchList.get(5)); - this.bar.removeStuff("zzz"); - } - - private void verifyHasNoListeners(ListValueModel<Junk> listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private void verifyHasListeners(ListValueModel<Junk> listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private SimpleCollectionValueModel<Junk> buildCollectionHolder() { - return new SimpleCollectionValueModel<Junk>(this.buildCollection()); - } - - private Collection<Junk> buildCollection() { - Bag<Junk> bag = new HashBag<Junk>(); - this.populateCollection(bag); - return bag; - } - - private SimpleListValueModel<Junk> buildListHolder() { - return new SimpleListValueModel<Junk>(this.buildList()); - } - - private List<Junk> buildList() { - List<Junk> list = new ArrayList<Junk>(); - this.populateCollection(list); - return list; - } - - private void populateCollection(Collection<Junk> c) { - c.add(this.foo); - c.add(this.bar); - c.add(this.baz); - c.add(this.joo); - c.add(this.jar); - c.add(this.jaz); - } - - - // ********** Junk class ********** - - private class Junk extends AbstractModel implements Displayable, Comparable<Junk> { - private Collection<String> stuff; - public static final String STUFF_COLLECTION = "stuff"; - - - public Junk(String stuffItem) { - this.stuff = new ArrayList<String>(); - this.stuff.add(stuffItem); - } - - public void addStuff(String stuffItem) { - this.addItemToCollection(stuffItem, this.stuff, STUFF_COLLECTION); - } - - public void removeStuff(String stuffItem) { - this.removeItemFromCollection(stuffItem, this.stuff, STUFF_COLLECTION); - } - - public String displayString() { - return toString(); - } - - public Icon icon() { - return null; - } - - public int compareTo(Junk o) { - return this.displayString().compareTo(o.displayString()); - } - - @Override - public String toString() { - return "Junk(" + this.stuff + ")"; - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemListListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemListListValueModelAdapterTests.java deleted file mode 100644 index aaaa7f8dba..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemListListValueModelAdapterTests.java +++ /dev/null @@ -1,244 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.swing.Icon; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ItemListListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.swing.Displayable; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ItemListListValueModelAdapterTests extends TestCase { - private Junk foo; - private Junk bar; - private Junk baz; - private Junk joo; - private Junk jar; - private Junk jaz; - - private Junk tom; - private Junk dick; - private Junk harry; - - public ItemListListValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.foo = new Junk("foo"); - this.bar = new Junk("bar"); - this.baz = new Junk("baz"); - this.joo = new Junk("joo"); - this.jar = new Junk("jar"); - this.jaz = new Junk("jaz"); - - this.tom = new Junk("tom"); - this.dick = new Junk("dick"); - this.harry = new Junk("harry"); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testCollectionSynchronization() { - SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder(); - ListValueModel<Junk> listValueModel = new ItemListListValueModelAdapter<Junk>(collectionHolder, Junk.STUFF_LIST); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - collectionHolder.add(this.tom); - collectionHolder.add(this.dick); - collectionHolder.add(this.harry); - assertEquals(9, synchList.size()); - this.compare(listValueModel, synchList); - - collectionHolder.remove(this.foo); - collectionHolder.remove(this.jar); - collectionHolder.remove(this.harry); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - } - - public void testListSynchronization() { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemListListValueModelAdapter<Junk>(listHolder, Junk.STUFF_LIST); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - listHolder.add(6, this.tom); - listHolder.add(7, this.dick); - listHolder.add(8, this.harry); - assertEquals(9, synchList.size()); - this.compare(listValueModel, synchList); - - listHolder.remove(8); - listHolder.remove(0); - listHolder.remove(4); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - } - - private void compare(ListValueModel<Junk> listValueModel, List<Junk> list) { - assertEquals(listValueModel.size(), list.size()); - for (int i = 0; i < listValueModel.size(); i++) { - assertEquals(listValueModel.get(i), list.get(i)); - } - } - - - public void testHasListeners() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyListChangeListeners(Junk.STUFF_LIST)); - assertFalse(this.jaz.hasAnyListChangeListeners(Junk.STUFF_LIST)); - - ListValueModel<Junk> listValueModel = new ItemListListValueModelAdapter<Junk>(listHolder, Junk.STUFF_LIST); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyListChangeListeners(Junk.STUFF_LIST)); - assertFalse(this.jaz.hasAnyListChangeListeners(Junk.STUFF_LIST)); - this.verifyHasNoListeners(listValueModel); - - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.foo.hasAnyListChangeListeners(Junk.STUFF_LIST)); - assertTrue(this.jaz.hasAnyListChangeListeners(Junk.STUFF_LIST)); - this.verifyHasListeners(listValueModel); - - listValueModel.removeListChangeListener(ListValueModel.LIST_VALUES, synchList); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyListChangeListeners(Junk.STUFF_LIST)); - assertFalse(this.jaz.hasAnyListChangeListeners(Junk.STUFF_LIST)); - this.verifyHasNoListeners(listValueModel); - } - - public void testGetSize() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemListListValueModelAdapter<Junk>(listHolder, Junk.STUFF_LIST); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - this.verifyHasListeners(listValueModel); - assertEquals(6, listValueModel.size()); - assertEquals(6, synchList.size()); - } - - public void testGet() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new SortedListValueModelWrapper<Junk>(new ItemListListValueModelAdapter<Junk>(listHolder, Junk.STUFF_LIST)); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - this.verifyHasListeners(listValueModel); - assertEquals(this.bar, listValueModel.get(0)); - assertEquals(this.bar, synchList.get(0)); - this.bar.removeStuff("bar"); - this.bar.addStuff("zzz"); - this.bar.addStuff("bar"); - assertEquals(this.bar, listValueModel.get(5)); - assertEquals(this.bar, synchList.get(5)); - this.bar.removeStuff("zzz"); - } - - private void verifyHasNoListeners(ListValueModel<Junk> listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private void verifyHasListeners(ListValueModel<Junk> listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private SimpleCollectionValueModel<Junk> buildCollectionHolder() { - return new SimpleCollectionValueModel<Junk>(this.buildCollection()); - } - - private Collection<Junk> buildCollection() { - Bag<Junk> bag = new HashBag<Junk>(); - this.populateCollection(bag); - return bag; - } - - private SimpleListValueModel<Junk> buildListHolder() { - return new SimpleListValueModel<Junk>(this.buildList()); - } - - private List<Junk> buildList() { - List<Junk> list = new ArrayList<Junk>(); - this.populateCollection(list); - return list; - } - - private void populateCollection(Collection<Junk> c) { - c.add(this.foo); - c.add(this.bar); - c.add(this.baz); - c.add(this.joo); - c.add(this.jar); - c.add(this.jaz); - } - - - // ********** Junk class ********** - - private class Junk extends AbstractModel implements Displayable, Comparable<Junk> { - private List<String> stuff; - public static final String STUFF_LIST = "stuff"; - - - public Junk(String stuffItem) { - this.stuff = new ArrayList<String>(); - this.stuff.add(stuffItem); - } - public void addStuff(String stuffItem) { - this.stuff.add(stuffItem); - fireItemAdded(STUFF_LIST, this.stuff.indexOf(stuffItem), stuffItem); - } - - public void removeStuff(String stuffItem) { - int index = this.stuff.indexOf(stuffItem); - this.stuff.remove(stuffItem); - fireItemRemoved(STUFF_LIST, index, stuffItem); - } - - public String displayString() { - return toString(); - } - - public Icon icon() { - return null; - } - - public int compareTo(Junk o) { - return this.displayString().compareTo(o.displayString()); - } - - @Override - public String toString() { - return "Junk(" + this.stuff + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemPropertyListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemPropertyListValueModelAdapterTests.java deleted file mode 100644 index a30ced90e7..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemPropertyListValueModelAdapterTests.java +++ /dev/null @@ -1,335 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -import javax.swing.Icon; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.swing.Displayable; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ItemPropertyListValueModelAdapterTests extends TestCase { - private Junk foo; - private Junk bar; - private Junk baz; - private Junk joo; - private Junk jar; - private Junk jaz; - - private Junk tom; - private Junk dick; - private Junk harry; - - public ItemPropertyListValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.foo = new Junk("this.foo"); - this.bar = new Junk("this.bar"); - this.baz = new Junk("this.baz"); - this.joo = new Junk("this.joo"); - this.jar = new Junk("this.jar"); - this.jaz = new Junk("this.jaz"); - - this.tom = new Junk("this.tom"); - this.dick = new Junk("this.dick"); - this.harry = new Junk("this.harry"); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testCollectionSynchronization() { - SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder(); - ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(collectionHolder, Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - collectionHolder.add(this.tom); - collectionHolder.add(this.dick); - collectionHolder.add(this.harry); - assertEquals(9, synchList.size()); - this.compare(listValueModel, synchList); - - collectionHolder.remove(this.foo); - collectionHolder.remove(this.jar); - collectionHolder.remove(this.harry); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - collectionHolder.setValues(this.buildCollection()); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - } - - public void testListSynchronization() { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(listHolder, Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - listHolder.add(6, this.tom); - listHolder.add(7, this.dick); - listHolder.add(8, this.harry); - assertEquals(9, synchList.size()); - this.compare(listValueModel, synchList); - - listHolder.remove(8); - listHolder.remove(0); - listHolder.remove(4); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - // test concurrent modification exception - listHolder.setListValues(this.buildList()); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - } - - private void compare(ListValueModel<Junk> listValueModel, List<Junk> list) { - assertEquals(listValueModel.size(), list.size()); - for (int i = 0; i < listValueModel.size(); i++) { - assertEquals(listValueModel.get(i), list.get(i)); - } - } - - public void testCollectionSort() { - this.verifyCollectionSort(null); - } - - public void testListSort() { - this.verifyListSort(null); - } - - public void testCustomCollectionSort() { - this.verifyCollectionSort(this.buildCustomComparator()); - } - - public void testCustomListSort() { - this.verifyListSort(this.buildCustomComparator()); - } - - private Comparator<Junk> buildCustomComparator() { - // sort with reverse order - return new Comparator<Junk>() { - public int compare(Junk o1, Junk o2) { - return o2.displayString().compareTo(o1.displayString()); - } - }; - } - - private void verifyCollectionSort(Comparator<Junk> comparator) { - SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder(); - ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(collectionHolder, comparator), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - collectionHolder.add(this.tom); - collectionHolder.add(this.dick); - collectionHolder.add(this.harry); - assertEquals(9, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - collectionHolder.remove(this.foo); - collectionHolder.remove(this.jar); - collectionHolder.remove(this.harry); - assertEquals(6, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - collectionHolder.setValues(this.buildCollection()); - assertEquals(6, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - } - - private void verifyListSort(Comparator<Junk> comparator) { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(new SortedListValueModelWrapper<Junk>(listHolder, comparator), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - listHolder.add(0, this.tom); - listHolder.add(0, this.dick); - listHolder.add(0, this.harry); - assertEquals(9, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - listHolder.remove(8); - listHolder.remove(4); - listHolder.remove(0); - listHolder.remove(5); - assertEquals(5, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - listHolder.setListValues(this.buildList()); - assertEquals(6, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - } - - private void compareSort(ListValueModel<Junk> listValueModel, List<Junk> list, Comparator<Junk> comparator) { - SortedSet<Junk> ss = new TreeSet<Junk>(comparator); - for (int i = 0; i < listValueModel.size(); i++) { - ss.add(listValueModel.get(i)); - } - assertEquals(ss.size(), list.size()); - for (Iterator<Junk> stream1 = ss.iterator(), stream2 = list.iterator(); stream1.hasNext(); ) { - assertEquals(stream1.next(), stream2.next()); - } - } - - public void testHasListeners() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY)); - assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY)); - assertFalse(this.jaz.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY)); - assertFalse(this.jaz.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY)); - - ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(new SortedListValueModelWrapper<Junk>(listHolder), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY)); - assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY)); - assertFalse(this.jaz.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY)); - assertFalse(this.jaz.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY)); - this.verifyHasNoListeners(listValueModel); - - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.foo.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY)); - assertTrue(this.foo.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY)); - assertTrue(this.jaz.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY)); - assertTrue(this.jaz.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY)); - this.verifyHasListeners(listValueModel); - - listValueModel.removeListChangeListener(ListValueModel.LIST_VALUES, synchList); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY)); - assertFalse(this.foo.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY)); - assertFalse(this.jaz.hasAnyPropertyChangeListeners(Displayable.DISPLAY_STRING_PROPERTY)); - assertFalse(this.jaz.hasAnyPropertyChangeListeners(Displayable.ICON_PROPERTY)); - this.verifyHasNoListeners(listValueModel); - } - - public void testGetSize() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemPropertyListValueModelAdapter<Junk>(new SortedListValueModelWrapper<Junk>(listHolder), Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - this.verifyHasListeners(listValueModel); - assertEquals(6, listValueModel.size()); - assertEquals(6, synchList.size()); - } - - public void testGet() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new SortedListValueModelWrapper<Junk>(new ItemPropertyListValueModelAdapter<Junk>(listHolder, Displayable.DISPLAY_STRING_PROPERTY, Displayable.ICON_PROPERTY)); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - this.verifyHasListeners(listValueModel); - assertEquals(this.bar, listValueModel.get(0)); - assertEquals(this.bar, synchList.get(0)); - this.bar.setName("zzz"); - assertEquals(this.bar, listValueModel.get(5)); - assertEquals(this.bar, synchList.get(5)); - this.bar.setName("this.bar"); - } - - private void verifyHasNoListeners(ListValueModel<Junk> listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private void verifyHasListeners(ListValueModel<Junk> listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private SimpleCollectionValueModel<Junk> buildCollectionHolder() { - return new SimpleCollectionValueModel<Junk>(this.buildCollection()); - } - - private Collection<Junk> buildCollection() { - Bag<Junk> bag = new HashBag<Junk>(); - this.populateCollection(bag); - return bag; - } - - private SimpleListValueModel<Junk> buildListHolder() { - return new SimpleListValueModel<Junk>(this.buildList()); - } - - private List<Junk> buildList() { - List<Junk> list = new ArrayList<Junk>(); - this.populateCollection(list); - return list; - } - - private void populateCollection(Collection<Junk> c) { - c.add(this.foo); - c.add(this.bar); - c.add(this.baz); - c.add(this.joo); - c.add(this.jar); - c.add(this.jaz); - } - - - // ********** Junk class ********** - - private class Junk extends AbstractModel implements Displayable, Comparable<Junk> { - private String name; - public Junk(String name) { - this.name = name; - } - public String displayString() { - return this.name; - } - public Icon icon() { - return null; - } - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(DISPLAY_STRING_PROPERTY, old, name); - } - public int compareTo(Junk o) { - return this.displayString().compareTo(o.displayString()); - } - @Override - public String toString() { - return "Junk(" + this.name + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemStateListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemStateListValueModelAdapterTests.java deleted file mode 100644 index e95c36b4ea..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ItemStateListValueModelAdapterTests.java +++ /dev/null @@ -1,306 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ItemStateListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ItemStateListValueModelAdapterTests extends TestCase { - private Junk foo; - private Junk bar; - private Junk baz; - private Junk joo; - private Junk jar; - private Junk jaz; - - private Junk tom; - private Junk dick; - private Junk harry; - - public ItemStateListValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.foo = new Junk("this.foo"); - this.bar = new Junk("this.bar"); - this.baz = new Junk("this.baz"); - this.joo = new Junk("this.joo"); - this.jar = new Junk("this.jar"); - this.jaz = new Junk("this.jaz"); - - this.tom = new Junk("this.tom"); - this.dick = new Junk("this.dick"); - this.harry = new Junk("this.harry"); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testCollectionSynchronization() { - SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder(); - ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(collectionHolder); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - collectionHolder.add(this.tom); - collectionHolder.add(this.dick); - collectionHolder.add(this.harry); - assertEquals(9, synchList.size()); - this.compare(listValueModel, synchList); - - collectionHolder.remove(this.foo); - collectionHolder.remove(this.jar); - collectionHolder.remove(this.harry); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - } - - public void testListSynchronization() { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(listHolder); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - - listHolder.add(6, this.tom); - listHolder.add(7, this.dick); - listHolder.add(8, this.harry); - assertEquals(9, synchList.size()); - this.compare(listValueModel, synchList); - - listHolder.remove(8); - listHolder.remove(0); - listHolder.remove(4); - assertEquals(6, synchList.size()); - this.compare(listValueModel, synchList); - } - - private void compare(ListValueModel<Junk> listValueModel, List<Junk> list) { - assertEquals(listValueModel.size(), list.size()); - for (int i = 0; i < listValueModel.size(); i++) { - assertEquals(listValueModel.get(i), list.get(i)); - } - } - - public void testCollectionSort() { - this.verifyCollectionSort(null); - } - - public void testListSort() { - this.verifyListSort(null); - } - - public void testCustomCollectionSort() { - this.verifyCollectionSort(this.buildCustomComparator()); - } - - public void testCustomListSort() { - this.verifyListSort(this.buildCustomComparator()); - } - - private Comparator<Junk> buildCustomComparator() { - // sort with reverse order - return new Comparator<Junk>() { - public int compare(Junk o1, Junk o2) { - return o2.compareTo(o1); - } - }; - } - - private void verifyCollectionSort(Comparator<Junk> comparator) { - SimpleCollectionValueModel<Junk> collectionHolder = this.buildCollectionHolder(); - ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(new SortedListValueModelAdapter<Junk>(collectionHolder, comparator)); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - collectionHolder.add(this.tom); - collectionHolder.add(this.dick); - collectionHolder.add(this.harry); - assertEquals(9, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - collectionHolder.remove(this.foo); - collectionHolder.remove(this.jar); - collectionHolder.remove(this.harry); - assertEquals(6, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - } - - private void verifyListSort(Comparator<Junk> comparator) { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(new SortedListValueModelWrapper<Junk>(listHolder, comparator)); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertEquals(6, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - listHolder.add(0, this.tom); - listHolder.add(0, this.dick); - listHolder.add(0, this.harry); - assertEquals(9, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - - listHolder.remove(8); - listHolder.remove(4); - listHolder.remove(0); - listHolder.remove(5); - assertEquals(5, synchList.size()); - this.compareSort(listValueModel, synchList, comparator); - } - - private void compareSort(ListValueModel<Junk> listValueModel, List<Junk> list, Comparator<Junk> comparator) { - SortedSet<Junk> ss = new TreeSet<Junk>(comparator); - for (int i = 0; i < listValueModel.size(); i++) { - ss.add(listValueModel.get(i)); - } - assertEquals(ss.size(), list.size()); - for (Iterator<Junk> stream1 = ss.iterator(), stream2 = list.iterator(); stream1.hasNext(); ) { - assertEquals(stream1.next(), stream2.next()); - } - } - - public void testHasListeners() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyStateChangeListeners()); - assertFalse(this.foo.hasAnyStateChangeListeners()); - assertFalse(this.jaz.hasAnyStateChangeListeners()); - assertFalse(this.jaz.hasAnyStateChangeListeners()); - - ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(new SortedListValueModelWrapper<Junk>(listHolder)); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyStateChangeListeners()); - assertFalse(this.foo.hasAnyStateChangeListeners()); - assertFalse(this.jaz.hasAnyStateChangeListeners()); - assertFalse(this.jaz.hasAnyStateChangeListeners()); - this.verifyHasNoListeners(listValueModel); - - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.foo.hasAnyStateChangeListeners()); - assertTrue(this.foo.hasAnyStateChangeListeners()); - assertTrue(this.jaz.hasAnyStateChangeListeners()); - assertTrue(this.jaz.hasAnyStateChangeListeners()); - this.verifyHasListeners(listValueModel); - - listValueModel.removeListChangeListener(ListValueModel.LIST_VALUES, synchList); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(this.foo.hasAnyStateChangeListeners()); - assertFalse(this.foo.hasAnyStateChangeListeners()); - assertFalse(this.jaz.hasAnyStateChangeListeners()); - assertFalse(this.jaz.hasAnyStateChangeListeners()); - this.verifyHasNoListeners(listValueModel); - } - - public void testGetSize() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new ItemStateListValueModelAdapter<Junk>(new SortedListValueModelWrapper<Junk>(listHolder)); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - this.verifyHasListeners(listValueModel); - assertEquals(6, listValueModel.size()); - assertEquals(6, synchList.size()); - } - - public void testGet() throws Exception { - SimpleListValueModel<Junk> listHolder = this.buildListHolder(); - ListValueModel<Junk> listValueModel = new SortedListValueModelWrapper<Junk>(new ItemStateListValueModelAdapter<Junk>(listHolder)); - CoordinatedList<Junk> synchList = new CoordinatedList<Junk>(listValueModel); - this.verifyHasListeners(listValueModel); - assertEquals(this.bar, listValueModel.get(0)); - assertEquals(this.bar, synchList.get(0)); - this.bar.setName("zzz"); - assertEquals(this.bar, listValueModel.get(5)); - assertEquals(this.bar, synchList.get(5)); - this.bar.setName("this.bar"); - } - - private void verifyHasNoListeners(ListValueModel<Junk> listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasNoListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private void verifyHasListeners(ListValueModel<Junk> listValueModel) throws Exception { - assertTrue(((AbstractModel) listValueModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private SimpleCollectionValueModel<Junk> buildCollectionHolder() { - return new SimpleCollectionValueModel<Junk>(this.buildCollection()); - } - - private Collection<Junk> buildCollection() { - Bag<Junk> bag = new HashBag<Junk>(); - this.populateCollection(bag); - return bag; - } - - private SimpleListValueModel<Junk> buildListHolder() { - return new SimpleListValueModel<Junk>(this.buildList()); - } - - private List<Junk> buildList() { - List<Junk> list = new ArrayList<Junk>(); - this.populateCollection(list); - return list; - } - - private void populateCollection(Collection<Junk> c) { - c.add(this.foo); - c.add(this.bar); - c.add(this.baz); - c.add(this.joo); - c.add(this.jar); - c.add(this.jaz); - } - - // ********** Junk class ********** - private class Junk extends AbstractModel implements Comparable<Junk> { - private String name; - public Junk(String name) { - this.name = name; - } - public void setName(String name) { - this.name = name; - this.fireStateChanged(); - } - public int compareTo(Junk j) { - return this.name.compareTo(j.name); - } - @Override - public String toString() { - return "Junk(" + this.name + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java deleted file mode 100644 index 2a152d97b8..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/JptUtilityModelValueTests.java +++ /dev/null @@ -1,77 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.Test; -import junit.framework.TestSuite; -import org.eclipse.jpt.utility.tests.internal.model.value.prefs.JptUtilityModelValuePrefsTests; -import org.eclipse.jpt.utility.tests.internal.model.value.swing.JptUtilityModelValueSwingTests; - -public class JptUtilityModelValueTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptUtilityModelValueTests.class.getPackage().getName()); - - suite.addTest(JptUtilityModelValuePrefsTests.suite()); - suite.addTest(JptUtilityModelValueSwingTests.suite()); - - suite.addTestSuite(BufferedWritablePropertyValueModelTests.class); - suite.addTestSuite(CachingTransformationPropertyValueModelTests.class); - suite.addTestSuite(CachingTransformationWritablePropertyValueModelTests.class); - suite.addTestSuite(CollectionAspectAdapterTests.class); - suite.addTestSuite(CollectionListValueModelAdapterTests.class); - suite.addTestSuite(CollectionPropertyValueModelAdapterTests.class); - suite.addTestSuite(CompositeCollectionValueModelTests.class); - suite.addTestSuite(CompositeListValueModelTests.class); - suite.addTestSuite(CompositePropertyValueModelTests.class); - suite.addTestSuite(ExtendedListValueModelWrapperTests.class); - suite.addTestSuite(FilteringCollectionValueModelTests.class); - suite.addTestSuite(FilteringPropertyValueModelTests.class); - suite.addTestSuite(ItemCollectionListValueModelAdapterTests.class); - suite.addTestSuite(ItemListListValueModelAdapterTests.class); - suite.addTestSuite(ItemPropertyListValueModelAdapterTests.class); - suite.addTestSuite(ItemStateListValueModelAdapterTests.class); - suite.addTestSuite(ListAspectAdapterTests.class); - suite.addTestSuite(ListCollectionValueModelAdapterTests.class); - suite.addTestSuite(ListCuratorTests.class); - suite.addTestSuite(NullCollectionValueModelTests.class); - suite.addTestSuite(NullListValueModelTests.class); - suite.addTestSuite(NullPropertyValueModelTests.class); - suite.addTestSuite(PropertyAspectAdapterTests.class); - suite.addTestSuite(PropertyCollectionValueModelAdapterTests.class); - suite.addTestSuite(PropertyListValueModelAdapterTests.class); - suite.addTestSuite(ReadOnlyWritablePropertyValueModelWrapperTests.class); - suite.addTestSuite(SetCollectionValueModelTests.class); - suite.addTestSuite(SimpleCollectionValueModelTests.class); - suite.addTestSuite(SimpleListValueModelTests.class); - suite.addTestSuite(SimplePropertyValueModelTests.class); - suite.addTestSuite(SortedListValueModelAdapterTests.class); - suite.addTestSuite(SortedListValueModelWrapperTests.class); - suite.addTestSuite(StaticCollectionValueModelTests.class); - suite.addTestSuite(StaticListValueModelTests.class); - suite.addTestSuite(StaticValueModelTests.class); - suite.addTestSuite(TransformationListValueModelAdapterTests.class); - suite.addTestSuite(TransformationListValueModelAdapterTests.TransformerTests.class); - suite.addTestSuite(TransformationPropertyValueModelTests.class); - suite.addTestSuite(TreeAspectAdapterTests.class); - suite.addTestSuite(ValueCollectionAdapterTests.class); - suite.addTestSuite(ValueListAdapterTests.class); - suite.addTestSuite(ValuePropertyAdapterTests.class); - suite.addTestSuite(ValueStateAdapterTests.class); - - return suite; - } - - private JptUtilityModelValueTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListAspectAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListAspectAdapterTests.java deleted file mode 100644 index 37c6718d6d..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListAspectAdapterTests.java +++ /dev/null @@ -1,476 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.List; -import java.util.ListIterator; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyListIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ListAspectAdapterTests extends TestCase { - private TestSubject subject1; - private WritablePropertyValueModel<TestSubject> subjectHolder1; - private LocalListAspectAdapter aa1; - private ListEvent event1; - private ListChangeListener listener1; - - private TestSubject subject2; - - public ListAspectAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject1 = new TestSubject(); - this.subject1.addNames(this.subject1Names()); - this.subject1.addDescriptions(this.subject1Descriptions()); - this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1); - this.aa1 = this.buildAspectAdapter(this.subjectHolder1); - this.listener1 = this.buildValueChangeListener1(); - this.aa1.addListChangeListener(ListValueModel.LIST_VALUES, this.listener1); - this.event1 = null; - - this.subject2 = new TestSubject(); - this.subject2.addNames(this.subject2Names()); - this.subject2.addDescriptions(this.subject2Descriptions()); - } - - private List<String> subject1Names() { - List<String> result = new ArrayList<String>(); - result.add("foo"); - result.add("bar"); - result.add("baz"); - result.add("bam"); - return result; - } - - private List<String> subject1Descriptions() { - List<String> result = new ArrayList<String>(); - result.add("this.subject1 description1"); - result.add("this.subject1 description2"); - return result; - } - - private List<String> subject2Names() { - List<String> result = new ArrayList<String>(); - result.add("joo"); - result.add("jar"); - result.add("jaz"); - result.add("jam"); - return result; - } - - private List<String> subject2Descriptions() { - List<String> result = new ArrayList<String>(); - result.add("this.subject2 description1"); - result.add("this.subject2 description2"); - return result; - } - - private LocalListAspectAdapter buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { - return new LocalListAspectAdapter(subjectHolder); - } - - private ListChangeListener buildValueChangeListener1() { - return new ListChangeListener() { - public void itemsAdded(ListAddEvent e) { - ListAspectAdapterTests.this.value1Changed(e); - } - public void itemsRemoved(ListRemoveEvent e) { - ListAspectAdapterTests.this.value1Changed(e); - } - public void itemsReplaced(ListReplaceEvent e) { - ListAspectAdapterTests.this.value1Changed(e); - } - public void itemsMoved(ListMoveEvent e) { - ListAspectAdapterTests.this.value1Changed(e); - } - public void listCleared(ListClearEvent e) { - ListAspectAdapterTests.this.value1Changed(e); - } - public void listChanged(ListChangeEvent e) { - ListAspectAdapterTests.this.value1Changed(e); - } - }; - } - - void value1Changed(ListEvent e) { - this.event1 = e; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSubjectHolder() { - assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator())); - assertNull(this.event1); - - this.subjectHolder1.setValue(this.subject2); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(this.subject2Names(), CollectionTools.list(this.aa1.listIterator())); - - this.event1 = null; - this.subjectHolder1.setValue(null); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertFalse(this.aa1.iterator().hasNext()); - - this.event1 = null; - this.subjectHolder1.setValue(this.subject1); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator())); - } - - public void testAdd() { - assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator())); - assertNull(this.event1); - - this.subject1.addName("jam"); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(this.subject1Names().size(), ((ListAddEvent) this.event1).getIndex()); - assertEquals("jam", ((ListAddEvent) this.event1).getItems().iterator().next()); - List<String> namesPlus = this.subject1Names(); - namesPlus.add("jam"); - assertEquals(namesPlus, CollectionTools.list(this.aa1.listIterator())); - - this.event1 = null; - this.aa1.add(2, "jaz"); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(2, ((ListAddEvent) this.event1).getIndex()); - assertEquals("jaz", ((ListAddEvent) this.event1).getItems().iterator().next()); - namesPlus.add(2, "jaz"); - assertEquals(namesPlus, CollectionTools.list(this.aa1.listIterator())); - } - - public void testDefaultAdd() { - assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator())); - assertNull(this.event1); - - List<String> items = new ArrayList<String>(); - items.add("joo"); - items.add("jar"); - items.add("jaz"); - items.add("jam"); - - this.event1 = null; - this.aa1.addAll(2, items); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(5, ((ListAddEvent) this.event1).getIndex()); // only the last "add" event will still be there - assertEquals("jam", ((ListAddEvent) this.event1).getItems().iterator().next()); - List<String> namesPlus = this.subject1Names(); - namesPlus.addAll(2, items); - assertEquals(namesPlus, CollectionTools.list(this.aa1.listIterator())); - } - - public void testRemove() { - assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator())); - assertNull(this.event1); - - String removedName = this.subject1.removeName(0); // should be "foo" - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(0, ((ListRemoveEvent) this.event1).getIndex()); - assertEquals(removedName, ((ListRemoveEvent) this.event1).getItems().iterator().next()); - List<String> namesMinus = this.subject1Names(); - namesMinus.remove(0); - assertEquals(namesMinus, CollectionTools.list(this.aa1.listIterator())); - - this.event1 = null; - Object removedItem = this.aa1.remove(0); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(0, ((ListRemoveEvent) this.event1).getIndex()); - assertEquals(removedItem, ((ListRemoveEvent) this.event1).getItems().iterator().next()); - namesMinus.remove(0); - assertEquals(namesMinus, CollectionTools.list(this.aa1.listIterator())); - } - - public void testDefaultLength() { - assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator())); - assertNull(this.event1); - - List<String> items = new ArrayList<String>(); - items.add("bar"); - items.add("baz"); - - this.event1 = null; - this.aa1.remove(1, 2); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(1, ((ListRemoveEvent) this.event1).getIndex()); // only the last "remove" event will still be there - assertEquals("baz", ((ListRemoveEvent) this.event1).getItems().iterator().next()); - List<String> namesPlus = this.subject1Names(); - namesPlus.remove(1); - namesPlus.remove(1); - assertEquals(namesPlus, CollectionTools.list(this.aa1.listIterator())); - } - - public void testReplace() { - assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator())); - assertNull(this.event1); - - String replacedName = this.subject1.setName(0, "jelly"); // should be "foo" - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(0, ((ListReplaceEvent) this.event1).getIndex()); - assertEquals("jelly", ((ListReplaceEvent) this.event1).getNewItems().iterator().next()); - assertEquals(replacedName, ((ListReplaceEvent) this.event1).getOldItems().iterator().next()); - List<String> namesChanged = this.subject1Names(); - namesChanged.set(0, "jelly"); - assertEquals(namesChanged, CollectionTools.list(this.aa1.listIterator())); - - this.event1 = null; - replacedName = this.subject1.setName(1, "roll"); // should be "bar" - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(1, ((ListReplaceEvent) this.event1).getIndex()); - assertEquals("roll", ((ListReplaceEvent) this.event1).getNewItems().iterator().next()); - assertEquals(replacedName, ((ListReplaceEvent) this.event1).getOldItems().iterator().next()); - namesChanged = this.subject1Names(); - namesChanged.set(0, "jelly"); - namesChanged.set(1, "roll"); - assertEquals(namesChanged, CollectionTools.list(this.aa1.listIterator())); - } - - public void testListChange() { - assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator())); - assertNull(this.event1); - - this.subject1.addTwoNames("jam", "jaz"); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - List<String> namesPlus2 = this.subject1Names(); - namesPlus2.add(0, "jaz"); - namesPlus2.add(0, "jam"); - assertEquals(namesPlus2, CollectionTools.list(this.aa1.listIterator())); - } - - public void testIterator() { - assertEquals(this.subject1Names(), CollectionTools.list(this.subject1.names())); - assertEquals(this.subject1Names(), CollectionTools.list(this.aa1.listIterator())); - } - - public void testGet() { - assertEquals(this.subject1Names().get(0), this.subject1.getName(0)); - assertEquals(this.subject1Names().get(0), this.aa1.get(0)); - } - - public void testSize() { - assertEquals(this.subject1Names().size(), CollectionTools.size(this.subject1.names())); - assertEquals(this.subject1Names().size(), CollectionTools.size(this.aa1.listIterator())); - } - - public void testHasListeners() { - assertTrue(this.aa1.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.subject1.hasAnyListChangeListeners(TestSubject.NAMES_LIST)); - this.aa1.removeListChangeListener(ListValueModel.LIST_VALUES, this.listener1); - assertFalse(this.subject1.hasAnyListChangeListeners(TestSubject.NAMES_LIST)); - assertFalse(this.aa1.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - ChangeListener listener2 = new ChangeAdapter(); - this.aa1.addChangeListener(listener2); - assertTrue(this.aa1.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.subject1.hasAnyListChangeListeners(TestSubject.NAMES_LIST)); - this.aa1.removeChangeListener(listener2); - assertFalse(this.subject1.hasAnyListChangeListeners(TestSubject.NAMES_LIST)); - assertFalse(this.aa1.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - - // ********** inner class ********** - - class TestSubject extends AbstractModel { - private List<String> names; - public static final String NAMES_LIST = "names"; - private List<String> descriptions; - public static final String DESCRIPTIONS_LIST = "descriptions"; - - public TestSubject() { - this.names = new ArrayList<String>(); - this.descriptions = new ArrayList<String>(); - } - public ListIterator<String> names() { - return new ReadOnlyListIterator<String>(this.names); - } - public String getName(int index) { - return this.names.get(index); - } - public void addName(int index, String name) { - this.names.add(index, name); - this.fireItemAdded(NAMES_LIST, index, name); - } - public void addName(String name) { - this.addName(this.names.size(), name); - } - public void addNames(ListIterator<String> newNames) { - while (newNames.hasNext()) { - this.addName(newNames.next()); - } - } - public void addNames(List<String> newNames) { - this.addNames(newNames.listIterator()); - } - public void addTwoNames(String name1, String name2) { - this.names.add(0, name2); - this.names.add(0, name1); - this.fireListChanged(NAMES_LIST, this.names); - } - public String removeName(int index) { - String removedName = this.names.remove(index); - this.fireItemRemoved(NAMES_LIST, index, removedName); - return removedName; - } - public String setName(int index, String name) { - String replacedName = this.names.set(index, name); - this.fireItemReplaced(NAMES_LIST, index, name, replacedName); - return replacedName; - } - public ListIterator<String> descriptions() { - return new ReadOnlyListIterator<String>(this.descriptions); - } - public String getDescription(int index) { - return this.descriptions.get(index); - } - public void addDescription(int index, String description) { - this.descriptions.add(index, description); - this.fireItemAdded(DESCRIPTIONS_LIST, index, description); - } - public void addDescription(String description) { - this.addDescription(this.descriptions.size(), description); - } - public void addDescriptions(ListIterator<String> newDescriptions) { - while (newDescriptions.hasNext()) { - this.addDescription(newDescriptions.next()); - } - } - public void addDescriptions(List<String> newDescriptions) { - this.addDescriptions(newDescriptions.listIterator()); - } - public String removeDescription(int index) { - String removedDescription = this.descriptions.remove(index); - this.fireItemRemoved(DESCRIPTIONS_LIST, index, removedDescription); - return removedDescription; - } - public String setDescription(int index, String description) { - String replacedDescription = this.descriptions.set(index, description); - this.fireItemReplaced(DESCRIPTIONS_LIST, index, description, replacedDescription); - return replacedDescription; - } - } - - - // this is not a typical aspect adapter - the value is determined by the aspect name - class LocalListAspectAdapter extends ListAspectAdapter<TestSubject, String> { - - LocalListAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { - super(subjectHolder, TestSubject.NAMES_LIST); - } - - @Override - protected ListIterator<String> listIterator_() { - if (this.listNames[0] == TestSubject.NAMES_LIST) { - return this.subject.names(); - } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) { - return this.subject.descriptions(); - } else { - throw new IllegalStateException("invalid aspect name: " + this.listNames[0]); - } - } - - public void add(int index, Object item) { - if (this.listNames[0] == TestSubject.NAMES_LIST) { - this.subject.addName(index, (String) item); - } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) { - this.subject.addDescription(index, (String) item); - } else { - throw new IllegalStateException("invalid aspect name: " + this.listNames[0]); - } - } - - public void addAll(int index, List<String> items) { - for (int i = 0; i < items.size(); i++) { - this.add(index + i, items.get(i)); - } - } - - public String remove(int index) { - if (this.listNames[0] == TestSubject.NAMES_LIST) { - return this.subject.removeName(index); - } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) { - return this.subject.removeDescription(index); - } else { - throw new IllegalStateException("invalid aspect name: " + this.listNames[0]); - } - } - - public List<String> remove(int index, int length) { - List<String> removedItems = new ArrayList<String>(length); - for (int i = 0; i < length; i++) { - removedItems.add(this.remove(index)); - } - return removedItems; - } - - public Object replace(int index, Object item) { - if (this.listNames[0] == TestSubject.NAMES_LIST) { - return this.subject.setName(index, (String) item); - } else if (this.listNames[0] == TestSubject.DESCRIPTIONS_LIST) { - return this.subject.setDescription(index, (String) item); - } else { - throw new IllegalStateException("invalid aspect name: " + this.listNames[0]); - } - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCollectionValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCollectionValueModelAdapterTests.java deleted file mode 100644 index 0c083da9ee..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCollectionValueModelAdapterTests.java +++ /dev/null @@ -1,282 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.swing.JList; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ListCollectionValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ListCollectionValueModelAdapterTests extends TestCase { - CollectionValueModel<String> adapter; - private SimpleListValueModel<String> wrappedListHolder; - private List<String> wrappedList; - - public ListCollectionValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.wrappedList = new ArrayList<String>(); - this.wrappedListHolder = new SimpleListValueModel<String>(this.wrappedList); - this.adapter = new ListCollectionValueModelAdapter<String>(this.wrappedListHolder); - } - - private Collection<String> wrappedCollection() { - return CollectionTools.collection(this.wrappedList.iterator()); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) { - // override failure - } - }); - this.wrappedListHolder.add(0, "foo"); - this.wrappedListHolder.add(1, "bar"); - this.wrappedListHolder.add(2, "baz"); - Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(3, adapterCollection.size()); - assertEquals(this.wrappedCollection(), adapterCollection); - } - - public void testStaleValues() { - CollectionChangeListener listener = new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) {/* OK */} - }; - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, listener); - this.wrappedListHolder.add(0, "foo"); - this.wrappedListHolder.add(1, "bar"); - this.wrappedListHolder.add(2, "baz"); - Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(3, adapterCollection.size()); - assertEquals(this.wrappedCollection(), adapterCollection); - - this.adapter.removeCollectionChangeListener(CollectionValueModel.VALUES, listener); - adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(0, adapterCollection.size()); - assertEquals(new HashBag<String>(), adapterCollection); - - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, listener); - adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(3, adapterCollection.size()); - assertEquals(this.wrappedCollection(), adapterCollection); - } - - public void testAdd() { - Bag<String> synchCollection = new CoordinatedBag<String>(this.adapter); - List<String> synchList = new CoordinatedList<String>(this.wrappedListHolder); - this.wrappedListHolder.add(0, "foo"); - assertTrue(this.wrappedList.contains("foo")); - this.wrappedListHolder.add(1, "bar"); - this.wrappedListHolder.add(2, "baz"); - this.wrappedListHolder.add(3, "joo"); - this.wrappedListHolder.add(4, "jar"); - this.wrappedListHolder.add(5, "jaz"); - assertEquals(6, this.wrappedList.size()); - - Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(this.wrappedCollection(), adapterCollection); - assertEquals(this.wrappedCollection(), CollectionTools.collection(synchList.iterator())); - assertEquals(this.wrappedCollection(), synchCollection); - } - - public void testRemove() { - Bag<String> synchCollection = new CoordinatedBag<String>(this.adapter); - List<String> synchList = new CoordinatedList<String>(this.wrappedListHolder); - this.wrappedListHolder.add(0, "foo"); - this.wrappedListHolder.add(1, "bar"); - this.wrappedListHolder.add(2, "baz"); - this.wrappedListHolder.add(3, "joo"); - this.wrappedListHolder.add(4, "jar"); - this.wrappedListHolder.add(5, "jaz"); - assertEquals("jaz", this.wrappedListHolder.remove(5)); - assertFalse(this.wrappedList.contains("jaz")); - assertEquals("foo", this.wrappedListHolder.remove(0)); - assertFalse(this.wrappedList.contains("foo")); - assertEquals(4, this.wrappedList.size()); - - Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(this.wrappedCollection(), adapterCollection); - assertEquals(this.wrappedCollection(), CollectionTools.collection(synchList.iterator())); - assertEquals(this.wrappedCollection(), synchCollection); - } - - public void testListSynch() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) { - // override failure - } - @Override - public void itemsRemoved(CollectionRemoveEvent e) { - // override failure - } - }); - this.wrappedListHolder.add(0, "foo"); - this.wrappedListHolder.add(1, "bar"); - this.wrappedListHolder.add(2, "baz"); - this.wrappedListHolder.add(3, "joo"); - this.wrappedListHolder.add(4, "jar"); - this.wrappedListHolder.add(5, "jaz"); - this.wrappedListHolder.remove(5); - assertFalse(this.wrappedList.contains("jaz")); - this.wrappedListHolder.remove(0); - assertFalse(this.wrappedList.contains("foo")); - assertEquals(4, this.wrappedList.size()); - - Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(this.wrappedCollection(), adapterCollection); - } - - public void testReplace() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) { - // override failure - } - @Override - public void itemsRemoved(CollectionRemoveEvent e) { - // override failure - } - }); - this.wrappedListHolder.add(0, "foo"); - this.wrappedListHolder.add(1, "bar"); - this.wrappedListHolder.add(2, "baz"); - Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(3, adapterCollection.size()); - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsRemoved(CollectionRemoveEvent e) { - assertEquals("foo", e.getItems().iterator().next()); - assertFalse(CollectionTools.contains(ListCollectionValueModelAdapterTests.this.adapter.iterator(), "joo")); - assertEquals(2, ListCollectionValueModelAdapterTests.this.adapter.size()); - } - @Override - public void itemsAdded(CollectionAddEvent e) { - assertEquals("joo", e.getItems().iterator().next()); - assertEquals(3, ListCollectionValueModelAdapterTests.this.adapter.size()); - } - }); - this.wrappedListHolder.set(0, "joo"); - adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(3, adapterCollection.size()); - assertEquals(this.wrappedCollection(), adapterCollection); - } - - public void testHasListeners() { - assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - CoordinatedBag<String> synchCollection = new CoordinatedBag<String>(this.adapter); - assertTrue(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - this.adapter.removeCollectionChangeListener(CollectionValueModel.VALUES, synchCollection); - assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - - ChangeListener cl = new ChangeAdapter(); - this.adapter.addChangeListener(cl); - assertTrue(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - this.adapter.removeChangeListener(cl); - assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - } - - public void testListChangedToEmpty() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) {/* OK */} - @Override - public void collectionCleared(CollectionClearEvent e) {/* OK */} - }); - this.wrappedListHolder.add(0, "foo"); - this.wrappedListHolder.add(1, "bar"); - this.wrappedListHolder.add(2, "baz"); - JList jList = new JList(new ListModelAdapter(this.adapter)); - this.wrappedListHolder.setListValues(new ArrayList<String>()); - assertEquals(0, jList.getModel().getSize()); - } - - public void testCollectionChangedFromEmpty() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) {/* OK */} - @Override - public void itemsRemoved(CollectionRemoveEvent e) {/* OK */} - }); - JList jList = new JList(new ListModelAdapter(this.adapter)); - - ArrayList<String> list = new ArrayList<String>(); - list.add("foo"); - list.add("bar"); - this.wrappedListHolder.setListValues(list); - assertEquals(2, jList.getModel().getSize()); - } - - public void testCollectionChangedFromEmptyToEmpty() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) {/* OK */} - @Override - public void itemsRemoved(CollectionRemoveEvent e) {/* OK */} - }); - JList jList = new JList(new ListModelAdapter(this.adapter)); - - ArrayList<String> list = new ArrayList<String>(); - this.wrappedListHolder.setListValues(list); - assertEquals(0, jList.getModel().getSize()); - } - - - // ********** inner class ********** - - class TestListener implements CollectionChangeListener { - public void itemsAdded(CollectionAddEvent e) { - fail("unexpected event"); - } - public void itemsRemoved(CollectionRemoveEvent e) { - fail("unexpected event"); - } - public void collectionCleared(CollectionClearEvent e) { - fail("unexpected event"); - } - public void collectionChanged(CollectionChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCuratorTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCuratorTests.java deleted file mode 100644 index 49ce46fdd6..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ListCuratorTests.java +++ /dev/null @@ -1,348 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyListIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ListCurator; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public final class ListCuratorTests - extends TestCase -{ - private TestSubject subject1; - private WritablePropertyValueModel<TestSubject> subjectHolder1; - - private ListCurator<TestSubject, String> curator; - private ListChangeListener listener1; - private ListEvent event1; - - private TestSubject subject2; - - public ListCuratorTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject1 = new TestSubject(this.subject1Names()); - this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1); - this.curator = this.buildListCurator(this.subjectHolder1); - this.listener1 = this.buildListChangeListener1(); - this.curator.addListChangeListener(ListValueModel.LIST_VALUES, this.listener1); - this.event1 = null; - - this.subject2 = new TestSubject(this.subject2Names()); - } - - private List<String> subject1Names() { - ArrayList<String> list = new ArrayList<String>(); - list.add("alpha"); - list.add("bravo"); - list.add("charlie"); - list.add("delta"); - return list; - } - - private List<String> subject2Names() { - ArrayList<String> list = new ArrayList<String>(); - list.add("echo"); - list.add("foxtrot"); - list.add("glove"); - list.add("hotel"); - return list; - } - - private ListCurator<TestSubject, String> buildListCurator(PropertyValueModel<TestSubject> subjectHolder) { - return new ListCurator<TestSubject, String>(subjectHolder) { - @Override - public Iterator<String> iteratorForRecord() { - return this.subject.strings(); - } - }; - } - - private ListChangeListener buildListChangeListener1() { - return new ListChangeListener() { - public void itemsAdded(ListAddEvent e) { - ListCuratorTests.this.value1Changed(e); - } - public void itemsRemoved(ListRemoveEvent e) { - ListCuratorTests.this.value1Changed(e); - } - public void itemsReplaced(ListReplaceEvent e) { - ListCuratorTests.this.value1Changed(e); - } - public void itemsMoved(ListMoveEvent e) { - ListCuratorTests.this.value1Changed(e); - } - public void listCleared(ListClearEvent e) { - ListCuratorTests.this.value1Changed(e); - } - public void listChanged(ListChangeEvent e) { - ListCuratorTests.this.value1Changed(e); - } - }; - } - - void value1Changed(ListEvent e) { - this.event1 = e; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSubjectHolder() { - assertEquals(this.subject1Names(), CollectionTools.list(this.curator.listIterator())); - assertNull(this.event1); - - this.subjectHolder1.setValue(this.subject2); - assertNotNull(this.event1); - assertEquals(this.curator, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(this.subject2Names(), CollectionTools.list(this.curator.listIterator())); - - this.event1 = null; - this.subjectHolder1.setValue(null); - assertNotNull(this.event1); - assertEquals(this.curator, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertFalse(this.curator.iterator().hasNext()); - - this.event1 = null; - this.subjectHolder1.setValue(this.subject1); - assertNotNull(this.event1); - assertEquals(this.curator, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(this.subject1Names(), CollectionTools.list(this.curator.listIterator())); - } - - public void testAdd() { - assertEquals(this.subject1Names(), CollectionTools.list(this.curator.listIterator())); - assertNull(this.event1); - - this.subject1.addString("echo"); - assertNotNull(this.event1); - assertEquals(this.curator, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(this.subject1Names().size(), ((ListAddEvent) this.event1).getIndex()); - assertEquals("echo", ((ListAddEvent) this.event1).getItems().iterator().next()); - List<String> stringsPlus = this.subject1Names(); - stringsPlus.add("echo"); - assertEquals(stringsPlus, CollectionTools.list(this.curator.listIterator())); - - this.event1 = null; - this.subject1.addString(0, "zulu"); - assertNotNull(this.event1); - assertEquals(this.curator, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(0, ((ListAddEvent) this.event1).getIndex()); - assertEquals("zulu", ((ListAddEvent) this.event1).getItems().iterator().next()); - stringsPlus.add(0, "zulu"); - assertEquals(stringsPlus, CollectionTools.list(this.curator.listIterator())); - } - - public void testRemove() { - assertEquals(this.subject1Names(), CollectionTools.list(this.curator.listIterator())); - assertNull(this.event1); - - String removedString = this.subject1.removeString(0); // should be "alpha" - assertNotNull(this.event1); - assertEquals(this.curator, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(0, ((ListRemoveEvent) this.event1).getIndex()); - assertEquals(removedString, ((ListRemoveEvent) this.event1).getItems().iterator().next()); - List<String> stringsMinus = this.subject1Names(); - stringsMinus.remove(0); - assertEquals(stringsMinus, CollectionTools.list(this.curator.listIterator())); - - removedString = this.subject1.removeString(2); // should be "delta" - assertNotNull(this.event1); - assertEquals(this.curator, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(2, ((ListRemoveEvent) this.event1).getIndex()); - assertEquals(removedString, ((ListRemoveEvent) this.event1).getItems().iterator().next()); - stringsMinus.remove(2); - assertEquals(stringsMinus, CollectionTools.list(this.curator.listIterator())); - } - - public void testCompleteListChange() { - assertEquals(this.subject1Names(), CollectionTools.list(this.curator.listIterator())); - assertNull(this.event1); - - this.subject1.setStrings(this.subject2Names()); - assertNotNull(this.event1); - assertEquals(this.curator, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - List<String> newStrings = this.subject2Names(); - assertEquals(newStrings, CollectionTools.list(this.curator.listIterator())); - } - - public void testPartialListChange() { - List<String> startingList = CollectionTools.list(this.curator.listIterator()); - assertEquals(this.subject1Names(), startingList); - assertNull(this.event1); - - String identicalString = startingList.get(1); // should be "bravo" - String nonidenticalString = startingList.get(0); // should be "alpha" - List<String> newStrings = CollectionTools.list(new String[] {new String("bravo"), new String("alpha"), "echo", "delta", "foxtrot"}); - this.subject1.setStrings(newStrings); - - List<String> finalList = CollectionTools.list(this.curator.listIterator()); - assertNotNull(this.event1); - assertEquals(this.curator, this.event1.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event1.getListName()); - assertEquals(newStrings, finalList); - assertTrue(identicalString == finalList.get(0)); - assertTrue(nonidenticalString != finalList.get(1)); - } - - public void testIterator() { - assertEquals(this.subject1Names(), CollectionTools.list(this.subject1.strings())); - assertEquals(this.subject1Names(), CollectionTools.list(this.curator.listIterator())); - } - - public void testGet() { - assertEquals(this.subject1Names().get(0), this.subject1.getString(0)); - assertEquals(this.subject1Names().get(0), this.curator.get(0)); - } - - public void testSize() { - assertEquals(this.subject1Names().size(), CollectionTools.size(this.subject1.strings())); - assertEquals(this.subject1Names().size(), CollectionTools.size(this.curator.listIterator())); - assertEquals(this.subject1Names().size(), this.curator.size()); - } - - public void testHasListeners() { - assertTrue(this.curator.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.subject1.hasAnyStateChangeListeners()); - this.curator.removeListChangeListener(ListValueModel.LIST_VALUES, this.listener1); - assertFalse(this.subject1.hasAnyStateChangeListeners()); - assertFalse(this.curator.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - ChangeListener listener2 = this.buildChangeListener(); - this.curator.addChangeListener(listener2); - assertTrue(this.curator.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(this.subject1.hasAnyStateChangeListeners()); - this.curator.removeChangeListener(listener2); - assertFalse(this.subject1.hasAnyStateChangeListeners()); - assertFalse(this.curator.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private ChangeListener buildChangeListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(ListAddEvent e) { - ListCuratorTests.this.value1Changed(e); - } - @Override - public void itemsRemoved(ListRemoveEvent e) { - ListCuratorTests.this.value1Changed(e); - } - @Override - public void itemsReplaced(ListReplaceEvent e) { - ListCuratorTests.this.value1Changed(e); - } - @Override - public void itemsMoved(ListMoveEvent e) { - ListCuratorTests.this.value1Changed(e); - } - @Override - public void listCleared(ListClearEvent e) { - ListCuratorTests.this.value1Changed(e); - } - @Override - public void listChanged(ListChangeEvent e) { - ListCuratorTests.this.value1Changed(e); - } - }; - } - - - // **************** Inner Class ******************************************* - - class TestSubject extends AbstractModel { - private List<String> strings; - - public TestSubject() { - this.strings = new ArrayList<String>(); - } - - public TestSubject(List<String> strings) { - this(); - this.setStrings(strings); - } - - public String getString(int index) { - return this.strings.get(index); - } - - public ListIterator<String> strings() { - return new ReadOnlyListIterator<String>(this.strings); - } - - public void addString(int index, String string) { - this.strings.add(index, string); - this.fireStateChanged(); - } - - public void addString(String string) { - this.addString(this.strings.size(), string); - } - - public String removeString(int index) { - String string = this.strings.get(index); - this.removeString(string); - return string; - } - - public void removeString(String string) { - this.strings.remove(string); - this.fireStateChanged(); - } - - public void setStrings(List<String> strings) { - this.strings = new ArrayList<String>(strings); - this.fireStateChanged(); - } - - public void setStrings(String[] strings) { - this.strings = CollectionTools.list(strings); - this.fireStateChanged(); - } - } -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullCollectionValueModelTests.java deleted file mode 100644 index 2bcc7387c8..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullCollectionValueModelTests.java +++ /dev/null @@ -1,44 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.model.value.NullCollectionValueModel; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class NullCollectionValueModelTests extends TestCase { - private CollectionValueModel<Object> collectionHolder; - - public NullCollectionValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.collectionHolder = new NullCollectionValueModel<Object>(); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSize() { - assertEquals(0, this.collectionHolder.size()); - } - - public void testIterator() { - assertFalse(this.collectionHolder.iterator().hasNext()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullListValueModelTests.java deleted file mode 100644 index e42bf48b12..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullListValueModelTests.java +++ /dev/null @@ -1,54 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.model.value.NullListValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class NullListValueModelTests extends TestCase { - private ListValueModel<Object> listHolder; - - public NullListValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.listHolder = new NullListValueModel<Object>(); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testGet() { - boolean exCaught = false; - try { - this.listHolder.get(0); - } catch (IndexOutOfBoundsException ex) { - exCaught = true; - } - assertTrue(exCaught); - } - - public void testSize() { - assertEquals(0, this.listHolder.size()); - } - - public void testIterator() { - assertFalse(this.listHolder.iterator().hasNext()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullPropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullPropertyValueModelTests.java deleted file mode 100644 index 754850691f..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/NullPropertyValueModelTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.model.value.NullPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class NullPropertyValueModelTests extends TestCase { - private PropertyValueModel<Object> valueHolder; - - public NullPropertyValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.valueHolder = new NullPropertyValueModel<Object>(); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testValue() { - assertNull(this.valueHolder.getValue()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyAspectAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyAspectAdapterTests.java deleted file mode 100644 index 06abc834ef..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyAspectAdapterTests.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class PropertyAspectAdapterTests extends TestCase { - private TestSubject subject1; - private WritablePropertyValueModel<TestSubject> subjectHolder1; - private PropertyAspectAdapter<TestSubject, String> aa1; - private PropertyChangeEvent event1; - private PropertyChangeListener listener1; - - private TestSubject subject2; - - private PropertyChangeEvent multipleValueEvent; - - private PropertyChangeEvent customValueEvent; - - - public PropertyAspectAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject1 = new TestSubject("foo", "test subject 1"); - this.subjectHolder1 = new SimplePropertyValueModel<TestSubject> (this.subject1); - this.aa1 = this.buildAspectAdapter(this.subjectHolder1); - this.listener1 = this.buildValueChangeListener1(); - this.aa1.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener1); - this.event1 = null; - - this.subject2 = new TestSubject("bar", "test subject 2"); - } - - private PropertyAspectAdapter<TestSubject, String> buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { - return new PropertyAspectAdapter<TestSubject, String>(subjectHolder, TestSubject.NAME_PROPERTY) { - // this is not a aspect adapter - the value is determined by the aspect name - @Override - protected String buildValue_() { - if (this.propertyNames[0] == TestSubject.NAME_PROPERTY) { - return this.subject.getName(); - } else if (this.propertyNames[0] == TestSubject.DESCRIPTION_PROPERTY) { - return this.subject.getDescription(); - } else { - throw new IllegalStateException("invalid aspect name: " + this.propertyNames[0]); - } - } - @Override - protected void setValue_(String value) { - if (this.propertyNames[0] == TestSubject.NAME_PROPERTY) { - this.subject.setName(value); - } else if (this.propertyNames[0] == TestSubject.DESCRIPTION_PROPERTY) { - this.subject.setDescription(value); - } else { - throw new IllegalStateException("invalid aspect name: " + this.propertyNames[0]); - } - } - }; - } - - private ChangeListener buildValueChangeListener1() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - PropertyAspectAdapterTests.this.value1Changed(e); - } - }; - } - - void value1Changed(PropertyChangeEvent e) { - this.event1 = e; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSubjectHolder() { - assertEquals("foo", this.aa1.getValue()); - assertNull(this.event1); - - this.subjectHolder1.setValue(this.subject2); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(PropertyValueModel.VALUE, this.event1.getPropertyName()); - assertEquals("foo", this.event1.getOldValue()); - assertEquals("bar", this.event1.getNewValue()); - assertEquals("bar", this.aa1.getValue()); - - this.event1 = null; - this.subjectHolder1.setValue(null); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(PropertyValueModel.VALUE, this.event1.getPropertyName()); - assertEquals("bar", this.event1.getOldValue()); - assertNull(this.event1.getNewValue()); - assertNull(this.aa1.getValue()); - - this.event1 = null; - this.subjectHolder1.setValue(this.subject1); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(PropertyValueModel.VALUE, this.event1.getPropertyName()); - assertEquals(null, this.event1.getOldValue()); - assertEquals("foo", this.event1.getNewValue()); - assertEquals("foo", this.aa1.getValue()); - } - - public void testPropertyChange() { - assertEquals("foo", this.aa1.getValue()); - assertNull(this.event1); - - this.subject1.setName("baz"); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(PropertyValueModel.VALUE, this.event1.getPropertyName()); - assertEquals("foo", this.event1.getOldValue()); - assertEquals("baz", this.event1.getNewValue()); - assertEquals("baz", this.aa1.getValue()); - - this.event1 = null; - this.subject1.setName(null); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(PropertyValueModel.VALUE, this.event1.getPropertyName()); - assertEquals("baz", this.event1.getOldValue()); - assertEquals(null, this.event1.getNewValue()); - assertEquals(null, this.aa1.getValue()); - - this.event1 = null; - this.subject1.setName("foo"); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(PropertyValueModel.VALUE, this.event1.getPropertyName()); - assertEquals(null, this.event1.getOldValue()); - assertEquals("foo", this.event1.getNewValue()); - assertEquals("foo", this.aa1.getValue()); - } - - public void testValue() { - assertEquals("foo", this.subject1.getName()); - assertEquals("foo", this.aa1.getValue()); - } - - public void testStaleValue() { - assertEquals("foo", this.subject1.getName()); - assertEquals("foo", this.aa1.getValue()); - - this.aa1.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener1); - assertEquals(null, this.aa1.getValue()); - - this.aa1.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener1); - assertEquals("foo", this.aa1.getValue()); - - this.aa1.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener1); - this.subjectHolder1.setValue(this.subject2); - assertEquals(null, this.aa1.getValue()); - - this.aa1.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener1); - assertEquals("bar", this.aa1.getValue()); - } - - public void testSetValue() { - this.aa1.setValue("baz"); - assertEquals("baz", this.aa1.getValue()); - assertEquals("baz", this.subject1.getName()); - } - - public void testHasListeners() { - assertTrue(this.aa1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(this.subject1.hasAnyPropertyChangeListeners(TestSubject.NAME_PROPERTY)); - this.aa1.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener1); - assertFalse(this.subject1.hasAnyPropertyChangeListeners(TestSubject.NAME_PROPERTY)); - assertFalse(this.aa1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - ChangeListener listener2 = this.buildValueChangeListener1(); - this.aa1.addChangeListener(listener2); - assertTrue(this.aa1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(this.subject1.hasAnyPropertyChangeListeners(TestSubject.NAME_PROPERTY)); - this.aa1.removeChangeListener(listener2); - assertFalse(this.subject1.hasAnyPropertyChangeListeners(TestSubject.NAME_PROPERTY)); - assertFalse(this.aa1.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - public void testMultipleAspectAdapter() { - TestSubject testSubject = new TestSubject("fred", "husband"); - WritablePropertyValueModel<TestSubject> testSubjectHolder = new SimplePropertyValueModel<TestSubject>(testSubject); - WritablePropertyValueModel<String> testAA = this.buildMultipleAspectAdapter(testSubjectHolder); - PropertyChangeListener testListener = this.buildMultipleValueChangeListener(); - testAA.addPropertyChangeListener(PropertyValueModel.VALUE, testListener); - assertEquals("fred:husband", testAA.getValue()); - - this.multipleValueEvent = null; - testSubject.setName("wilma"); - assertEquals("wilma:husband", testAA.getValue()); - assertEquals("fred:husband", this.multipleValueEvent.getOldValue()); - assertEquals("wilma:husband", this.multipleValueEvent.getNewValue()); - - this.multipleValueEvent = null; - testSubject.setDescription("wife"); - assertEquals("wilma:wife", testAA.getValue()); - assertEquals("wilma:husband", this.multipleValueEvent.getOldValue()); - assertEquals("wilma:wife", this.multipleValueEvent.getNewValue()); - } - - private WritablePropertyValueModel<String> buildMultipleAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { - return new PropertyAspectAdapter<TestSubject, String>(subjectHolder, TestSubject.NAME_PROPERTY, TestSubject.DESCRIPTION_PROPERTY) { - @Override - protected String buildValue_() { - return this.subject.getName() + ":" + this.subject.getDescription(); - } - }; - } - - private PropertyChangeListener buildMultipleValueChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - PropertyAspectAdapterTests.this.multipleValueChanged(e); - } - }; - } - - void multipleValueChanged(PropertyChangeEvent e) { - this.multipleValueEvent = e; - } - - /** - * test a bug where we would call #buildValue() in - * #engageNonNullSubject(), when we needed to call - * it in #engageSubject(), so the cached value would - * be rebuilt when the this.subject was set to null - */ - public void testCustomBuildValueWithNullSubject() { - TestSubject customSubject = new TestSubject("fred", "laborer"); - WritablePropertyValueModel<TestSubject> customSubjectHolder = new SimplePropertyValueModel<TestSubject>(customSubject); - WritablePropertyValueModel<String> customAA = this.buildCustomAspectAdapter(customSubjectHolder); - PropertyChangeListener customListener = this.buildCustomValueChangeListener(); - customAA.addPropertyChangeListener(PropertyValueModel.VALUE, customListener); - assertEquals("fred", customAA.getValue()); - - this.customValueEvent = null; - customSubject.setName("wilma"); - assertEquals("wilma", customAA.getValue()); - assertEquals("fred", this.customValueEvent.getOldValue()); - assertEquals("wilma", this.customValueEvent.getNewValue()); - - this.customValueEvent = null; - customSubjectHolder.setValue(null); - // this would fail - the value would be null... - assertEquals("<unnamed>", customAA.getValue()); - assertEquals("wilma", this.customValueEvent.getOldValue()); - assertEquals("<unnamed>", this.customValueEvent.getNewValue()); - } - - /** - * Test a bug: - * If two listeners were added to an aspect adapter, one with an - * aspect name and one without, the aspect adapter would add its - * 'subjectChangeListener' to its 'subjectHolder' twice. As a result, - * the following code will trigger an IllegalArgumentException - * if the bug is present; otherwise, it completes silently. - */ - public void testDuplicateListener() { - ChangeListener listener2 = new ChangeAdapter(); - this.aa1.addChangeListener(listener2); - } - - private WritablePropertyValueModel<String> buildCustomAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { - return new PropertyAspectAdapter<TestSubject, String>(subjectHolder, TestSubject.NAME_PROPERTY) { - @Override - protected String buildValue() { - return (this.subject == null) ? "<unnamed>" : this.subject.getName(); - } - }; - } - - private PropertyChangeListener buildCustomValueChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - PropertyAspectAdapterTests.this.customValueChanged(e); - } - }; - } - - void customValueChanged(PropertyChangeEvent e) { - this.customValueEvent = e; - } - - - // ********** test model ********** - - private static class TestSubject extends AbstractModel { - private String name; - public static final String NAME_PROPERTY = "name"; - private String description; - public static final String DESCRIPTION_PROPERTY = "description"; - - public TestSubject(String name, String description) { - this.name = name; - this.description = description; - } - public String getName() { - return this.name; - } - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - public String getDescription() { - return this.description; - } - public void setDescription(String description) { - Object old = this.description; - this.description = description; - this.firePropertyChanged(DESCRIPTION_PROPERTY, old, description); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyCollectionValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyCollectionValueModelAdapterTests.java deleted file mode 100644 index 9661ef4d4f..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyCollectionValueModelAdapterTests.java +++ /dev/null @@ -1,162 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Collection; - -import javax.swing.JList; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyCollectionValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class PropertyCollectionValueModelAdapterTests extends TestCase { - private CollectionValueModel<String> adapter; - private WritablePropertyValueModel<String> wrappedValueHolder; - - public PropertyCollectionValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.wrappedValueHolder = new SimplePropertyValueModel<String>(); - this.adapter = new PropertyCollectionValueModelAdapter<String>(this.wrappedValueHolder); - } - - private Collection<String> wrappedCollection() { - return CollectionTools.collection(new SingleElementIterator<String>(this.wrappedValueHolder.getValue())); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) {/* OK */} - }); - this.wrappedValueHolder.setValue("foo"); - Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(1, adapterCollection.size()); - assertEquals(this.wrappedCollection(), adapterCollection); - assertEquals("foo", adapterCollection.iterator().next()); - } - - public void testStaleValue() { - CollectionChangeListener listener = new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) {/* OK */} - }; - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, listener); - this.wrappedValueHolder.setValue("foo"); - Collection<String> adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(1, adapterCollection.size()); - assertEquals(this.wrappedCollection(), adapterCollection); - assertEquals("foo", adapterCollection.iterator().next()); - - this.adapter.removeCollectionChangeListener(CollectionValueModel.VALUES, listener); - adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(0, adapterCollection.size()); - assertEquals(new HashBag<String>(), adapterCollection); - - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, listener); - adapterCollection = CollectionTools.collection(this.adapter.iterator()); - assertEquals(1, adapterCollection.size()); - assertEquals(this.wrappedCollection(), adapterCollection); - assertEquals("foo", adapterCollection.iterator().next()); - } - - public void testHasListeners() { - assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - CoordinatedBag<String> synchCollection = new CoordinatedBag<String>(this.adapter); - assertTrue(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - this.adapter.removeCollectionChangeListener(CollectionValueModel.VALUES, synchCollection); - assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - - ChangeListener cl = new ChangeAdapter(); - this.adapter.addChangeListener(cl); - assertTrue(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - this.adapter.removeChangeListener(cl); - assertFalse(((AbstractModel) this.adapter).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - } - - public void testListChangedToEmpty() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) {/* OK */} - @Override - public void itemsRemoved(CollectionRemoveEvent e) {/* OK */} - }); - this.wrappedValueHolder.setValue("foo"); - JList jList = new JList(new ListModelAdapter(this.adapter)); - this.wrappedValueHolder.setValue(null); - assertEquals(0, jList.getModel().getSize()); - } - - public void testCollectionChangedFromEmpty() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener() { - @Override - public void itemsAdded(CollectionAddEvent e) {/* OK */} - }); - JList jList = new JList(new ListModelAdapter(this.adapter)); - - this.wrappedValueHolder.setValue("foo"); - assertEquals(1, jList.getModel().getSize()); - } - - public void testCollectionChangedFromEmptyToEmpty() { - this.adapter.addCollectionChangeListener(CollectionValueModel.VALUES, new TestListener()); - JList jList = new JList(new ListModelAdapter(this.adapter)); - - this.wrappedValueHolder.setValue(null); - assertEquals(0, jList.getModel().getSize()); - } - - - // ********** member class ********** - - static class TestListener implements CollectionChangeListener { - public void collectionChanged(CollectionChangeEvent event) { - fail("unexpected event"); - } - public void collectionCleared(CollectionClearEvent event) { - fail("unexpected event"); - } - public void itemsAdded(CollectionAddEvent event) { - fail("unexpected event"); - } - public void itemsRemoved(CollectionRemoveEvent event) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyListValueModelAdapterTests.java deleted file mode 100644 index d91b03d473..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/PropertyListValueModelAdapterTests.java +++ /dev/null @@ -1,211 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2008, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import javax.swing.JList; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.SingleElementIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class PropertyListValueModelAdapterTests extends TestCase { - private ListValueModel<String> adapter; - private WritablePropertyValueModel<String> wrappedValueHolder; - - public PropertyListValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.wrappedValueHolder = new SimplePropertyValueModel<String>(); - this.adapter = new PropertyListValueModelAdapter<String>(this.wrappedValueHolder); - } - - private Collection<String> wrappedList() { - return CollectionTools.list(new SingleElementIterator<String>(this.wrappedValueHolder.getValue())); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListener() { - @Override - public void itemsAdded(ListAddEvent event) {/* OK */} - }); - assertFalse(this.adapter.iterator().hasNext()); - this.wrappedValueHolder.setValue("foo"); - List<String> adapterList = CollectionTools.list(this.adapter.iterator()); - assertEquals(1, adapterList.size()); - assertEquals(this.wrappedList(), adapterList); - assertEquals("foo", adapterList.iterator().next()); - } - - public void testGetInt() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListener() { - @Override - public void itemsAdded(ListAddEvent event) {/* OK */} - }); - this.wrappedValueHolder.setValue("foo"); - assertEquals("foo", this.adapter.get(0)); - } - - public void testToArray1() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListener() { - @Override - public void itemsAdded(ListAddEvent event) {/* OK */} - }); - this.wrappedValueHolder.setValue("foo"); - Object[] array = this.adapter.toArray(); - assertEquals("foo", array[0]); - assertEquals(1, array.length); - } - - public void testToArray2() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListener()); - Object[] array = this.adapter.toArray(); - assertEquals(0, array.length); - } - - public void testStaleValue() { - ListChangeListener listener = new TestListener() { - @Override - public void itemsAdded(ListAddEvent event) {/* OK */} - }; - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, listener); - this.wrappedValueHolder.setValue("foo"); - List<String> adapterList = CollectionTools.list(this.adapter.iterator()); - assertEquals(1, adapterList.size()); - assertEquals(this.wrappedList(), adapterList); - assertEquals("foo", adapterList.iterator().next()); - - this.adapter.removeListChangeListener(ListValueModel.LIST_VALUES, listener); - adapterList = CollectionTools.list(this.adapter.iterator()); - assertEquals(0, adapterList.size()); - assertEquals(new ArrayList<String>(), adapterList); - - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, listener); - adapterList = CollectionTools.list(this.adapter.iterator()); - assertEquals(1, adapterList.size()); - assertEquals(this.wrappedList(), adapterList); - assertEquals("foo", adapterList.iterator().next()); - } - - public void testHasListeners() { - assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - CoordinatedList<String> synchList = new CoordinatedList<String>(this.adapter); - assertTrue(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.adapter.removeListChangeListener(ListValueModel.LIST_VALUES, synchList); - assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - ChangeListener cl = new ChangeAdapter(); - this.adapter.addChangeListener(cl); - assertTrue(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.adapter.removeChangeListener(cl); - assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - public void testListChangedToEmpty() { - this.wrappedValueHolder.setValue("foo"); - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListener() { - @Override - public void itemsRemoved(ListRemoveEvent event) {/* OK */} - }); - JList jList = new JList(new ListModelAdapter(this.adapter)); - this.wrappedValueHolder.setValue(null); - assertEquals(0, jList.getModel().getSize()); - } - - public void testListChangedFromEmpty() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListener() { - @Override - public void itemsAdded(ListAddEvent event) {/* OK */} - }); - JList jList = new JList(new ListModelAdapter(this.adapter)); - - this.wrappedValueHolder.setValue("foo"); - assertEquals(1, jList.getModel().getSize()); - } - - public void testListItemChanged() { - this.wrappedValueHolder.setValue("foo"); - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListener() { - @Override - public void itemsReplaced(ListReplaceEvent event) {/* OK */} - }); - JList jList = new JList(new ListModelAdapter(this.adapter)); - assertEquals(1, jList.getModel().getSize()); - assertEquals("foo", jList.getModel().getElementAt(0)); - - this.wrappedValueHolder.setValue("bar"); - assertEquals(1, jList.getModel().getSize()); - assertEquals("bar", jList.getModel().getElementAt(0)); - } - - public void testListChangedFromEmptyToEmpty() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListener()); - JList jList = new JList(new ListModelAdapter(this.adapter)); - - this.wrappedValueHolder.setValue(null); - assertEquals(0, jList.getModel().getSize()); - } - - - // ********** member class ********** - - static class TestListener implements ListChangeListener { - public void listChanged(ListChangeEvent event) { - fail("unexpected event"); - } - public void listCleared(ListClearEvent event) { - fail("unexpected event"); - } - public void itemsAdded(ListAddEvent event) { - fail("unexpected event"); - } - public void itemsRemoved(ListRemoveEvent event) { - fail("unexpected event"); - } - public void itemsMoved(ListMoveEvent event) { - fail("unexpected event"); - } - public void itemsReplaced(ListReplaceEvent event) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ReadOnlyWritablePropertyValueModelWrapperTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ReadOnlyWritablePropertyValueModelWrapperTests.java deleted file mode 100644 index c8678a7dfa..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ReadOnlyWritablePropertyValueModelWrapperTests.java +++ /dev/null @@ -1,157 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ReadOnlyWritablePropertyValueModelWrapper; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ReadOnlyWritablePropertyValueModelWrapperTests - extends TestCase -{ - private WritablePropertyValueModel<String> objectHolder; - - PropertyChangeEvent event; - - private WritablePropertyValueModel<String> wrapperObjectHolder; - - PropertyChangeEvent wrapperEvent; - - - public ReadOnlyWritablePropertyValueModelWrapperTests(String name) { - super(name); - } - - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.objectHolder = new SimplePropertyValueModel<String>("foo"); - this.wrapperObjectHolder = new ReadOnlyWritablePropertyValueModelWrapper<String>(this.objectHolder); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - - public void testValue() { - assertEquals("foo", this.objectHolder.getValue()); - assertEquals("foo", this.wrapperObjectHolder.getValue()); - - this.objectHolder.setValue("bar"); - assertEquals("bar", this.objectHolder.getValue()); - assertEquals("bar", this.wrapperObjectHolder.getValue()); - - this.objectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.wrapperObjectHolder.getValue()); - - this.objectHolder.setValue("foo"); - assertEquals("foo", this.objectHolder.getValue()); - assertEquals("foo", this.wrapperObjectHolder.getValue()); - } - - public void testSetValue() { - boolean exceptionOccurred = false; - try { - this.wrapperObjectHolder.setValue("bar"); - } - catch (UnsupportedOperationException uoe) { - exceptionOccurred = true; - } - - assertTrue(exceptionOccurred); - assertEquals("foo", this.objectHolder.getValue()); - assertEquals("foo", this.wrapperObjectHolder.getValue()); - } - - public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - ChangeListener listener = buildWrapperListener(); - this.wrapperObjectHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.wrapperObjectHolder.removeChangeListener(listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.wrapperObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.wrapperObjectHolder.removePropertyChangeListener(PropertyValueModel.VALUE, listener); - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildListener()); - this.wrapperObjectHolder.addChangeListener(this.buildWrapperListener()); - this.verifyPropertyChanges(); - } - - public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.wrapperObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildWrapperListener()); - this.verifyPropertyChanges(); - } - - private void verifyPropertyChanges() { - this.event = null; - this.wrapperEvent = null; - this.objectHolder.setValue("bar"); - verifyEvent(this.event, this.objectHolder, "foo", "bar"); - verifyEvent(this.wrapperEvent, this.wrapperObjectHolder, "foo", "bar"); - - this.event = null; - this.wrapperEvent = null; - this.objectHolder.setValue(null); - verifyEvent(this.event, this.objectHolder, "bar", null); - verifyEvent(this.wrapperEvent, this.wrapperObjectHolder, "bar", null); - - this.event = null; - this.wrapperEvent = null; - this.objectHolder.setValue("foo"); - verifyEvent(this.event, this.objectHolder, null, "foo"); - verifyEvent(this.wrapperEvent, this.wrapperObjectHolder, null, "foo"); - } - - private ChangeListener buildListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - ReadOnlyWritablePropertyValueModelWrapperTests.this.event = e; - } - }; - } - - private ChangeListener buildWrapperListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - ReadOnlyWritablePropertyValueModelWrapperTests.this.wrapperEvent = e; - } - }; - } - - private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) { - assertEquals(source, e.getSource()); - assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); - assertEquals(oldValue, e.getOldValue()); - assertEquals(newValue, e.getNewValue()); - } -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SetCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SetCollectionValueModelTests.java deleted file mode 100644 index ceb9c8a063..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SetCollectionValueModelTests.java +++ /dev/null @@ -1,328 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SetCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class SetCollectionValueModelTests extends TestCase { - private SimpleCollectionValueModel<String> collectionHolder; - CollectionAddEvent addEvent; - CollectionRemoveEvent removeEvent; - CollectionClearEvent collectionClearedEvent; - CollectionChangeEvent collectionChangedEvent; - - private CollectionValueModel<String> setHolder; - CollectionAddEvent setAddEvent; - CollectionRemoveEvent setRemoveEvent; - CollectionClearEvent setClearedEvent; - CollectionChangeEvent setChangedEvent; - - public SetCollectionValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.collectionHolder = new SimpleCollectionValueModel<String>(this.buildCollection()); - this.setHolder = new SetCollectionValueModel<String>(this.collectionHolder); - } - - private Collection<String> buildCollection() { - Collection<String> collection = new ArrayList<String>(); - collection.add("foo"); - collection.add("foo"); - return collection; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - // add a listener to "activate" the wrapper - this.setHolder.addChangeListener(this.buildSetChangeListener()); - - this.verify(this.collectionHolder, "foo", "foo"); - this.verify(this.setHolder, "foo"); - - this.collectionHolder.add("bar"); - this.collectionHolder.add("bar"); - this.verify(this.collectionHolder, "foo", "foo", "bar", "bar"); - this.verify(this.setHolder, "foo", "bar"); - - this.collectionHolder.remove("bar"); - this.verify(this.collectionHolder, "foo", "foo", "bar"); - this.verify(this.setHolder, "foo", "bar"); - - this.collectionHolder.remove("bar"); - this.verify(this.collectionHolder, "foo", "foo"); - this.verify(this.setHolder, "foo"); - - this.collectionHolder.remove("foo"); - this.verify(this.collectionHolder, "foo"); - this.verify(this.setHolder, "foo"); - - this.collectionHolder.remove("foo"); - assertFalse(this.collectionHolder.iterator().hasNext()); - assertFalse(this.setHolder.iterator().hasNext()); - } - - public void testSize() { - // add a listener to "activate" the wrapper - this.setHolder.addChangeListener(this.buildSetChangeListener()); - - assertEquals(2, this.collectionHolder.size()); - assertEquals(1, this.setHolder.size()); - - this.collectionHolder.add("bar"); - this.collectionHolder.add("bar"); - assertEquals(4, this.collectionHolder.size()); - assertEquals(2, this.setHolder.size()); - - this.collectionHolder.remove("bar"); - assertEquals(3, this.collectionHolder.size()); - assertEquals(2, this.setHolder.size()); - - this.collectionHolder.remove("bar"); - assertEquals(2, this.collectionHolder.size()); - assertEquals(1, this.setHolder.size()); - - this.collectionHolder.remove("foo"); - assertEquals(1, this.collectionHolder.size()); - assertEquals(1, this.setHolder.size()); - - this.collectionHolder.remove("foo"); - assertEquals(0, this.collectionHolder.size()); - assertEquals(0, this.setHolder.size()); - } - - public void testBulkChange() { - // add a listener to "activate" the wrapper - this.setHolder.addChangeListener(this.buildSetChangeListener()); - - Collection<String> newCollection = new ArrayList<String>(); - newCollection.add("fox"); - newCollection.add("fox"); - newCollection.add("bat"); - - this.collectionHolder.setValues(newCollection); - this.verify(this.collectionHolder, "fox", "fox", "bat"); - this.verify(this.setHolder, "fox", "bat"); - } - - public void testLazyListening() { - assertTrue(((AbstractModel) this.collectionHolder).hasNoCollectionChangeListeners(CollectionValueModel.VALUES)); - ChangeListener listener = this.buildSetChangeListener(); - this.setHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.collectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - this.setHolder.removeChangeListener(listener); - assertTrue(((AbstractModel) this.collectionHolder).hasNoCollectionChangeListeners(CollectionValueModel.VALUES)); - - this.setHolder.addCollectionChangeListener(CollectionValueModel.VALUES, listener); - assertTrue(((AbstractModel) this.collectionHolder).hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - this.setHolder.removeCollectionChangeListener(CollectionValueModel.VALUES, listener); - assertTrue(((AbstractModel) this.collectionHolder).hasNoCollectionChangeListeners(CollectionValueModel.VALUES)); - } - - public void testEvents1() { - this.collectionHolder.addChangeListener(this.buildChangeListener()); - this.setHolder.addChangeListener(this.buildSetChangeListener()); - this.verifyEvents(); - } - - public void testEvents2() { - this.collectionHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildCollectionChangeListener()); - this.setHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildSetCollectionChangeListener()); - this.verifyEvents(); - } - - private void clearEvents() { - this.addEvent = null; - this.removeEvent = null; - this.collectionClearedEvent = null; - this.collectionChangedEvent = null; - this.setAddEvent = null; - this.setRemoveEvent = null; - this.setClearedEvent = null; - this.setChangedEvent = null; - } - - private void verifyEvents() { - this.clearEvents(); - this.collectionHolder.add("bar"); - this.verifyEvent(this.addEvent, this.collectionHolder, "bar"); - this.verifyEvent(this.setAddEvent, this.setHolder, "bar"); - - this.clearEvents(); - this.collectionHolder.remove("foo"); - this.verifyEvent(this.removeEvent, this.collectionHolder, "foo"); - assertNull(this.setRemoveEvent); - - this.clearEvents(); - this.collectionHolder.add("bar"); - this.verifyEvent(this.addEvent, this.collectionHolder, "bar"); - assertNull(this.setAddEvent); - - this.clearEvents(); - this.collectionHolder.remove("foo"); - this.verifyEvent(this.removeEvent, this.collectionHolder, "foo"); - this.verifyEvent(this.setRemoveEvent, this.setHolder, "foo"); - - this.clearEvents(); - this.collectionHolder.add("foo"); - this.verifyEvent(this.addEvent, this.collectionHolder, "foo"); - this.verifyEvent(this.setAddEvent, this.setHolder, "foo"); - - this.clearEvents(); - this.collectionHolder.clear(); - this.verifyEvent(this.collectionClearedEvent, this.collectionHolder); - this.verifyEvent(this.setClearedEvent, this.setHolder); - - this.clearEvents(); - Collection<String> newCollection = new ArrayList<String>(); - newCollection.add("fox"); - newCollection.add("fox"); - newCollection.add("bat"); - newCollection.add("bat"); - newCollection.add("bat"); - this.collectionHolder.setValues(newCollection); - this.verifyEvent(this.collectionChangedEvent, this.collectionHolder, "fox", "fox", "bat", "bat", "bat"); - this.verifyEvent(this.setChangedEvent, this.setHolder, "fox", "bat"); - - } - - private CollectionChangeListener buildCollectionChangeListener() { - return new CollectionChangeListener() { - public void itemsAdded(CollectionAddEvent event) { - SetCollectionValueModelTests.this.addEvent = event; - } - public void itemsRemoved(CollectionRemoveEvent event) { - SetCollectionValueModelTests.this.removeEvent = event; - } - public void collectionCleared(CollectionClearEvent event) { - SetCollectionValueModelTests.this.collectionClearedEvent = event; - } - public void collectionChanged(CollectionChangeEvent event) { - SetCollectionValueModelTests.this.collectionChangedEvent = event; - } - }; - } - - private ChangeListener buildChangeListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(CollectionAddEvent event) { - SetCollectionValueModelTests.this.addEvent = event; - } - @Override - public void itemsRemoved(CollectionRemoveEvent event) { - SetCollectionValueModelTests.this.removeEvent = event; - } - @Override - public void collectionCleared(CollectionClearEvent event) { - SetCollectionValueModelTests.this.collectionClearedEvent = event; - } - @Override - public void collectionChanged(CollectionChangeEvent event) { - SetCollectionValueModelTests.this.collectionChangedEvent = event; - } - }; - } - - private CollectionChangeListener buildSetCollectionChangeListener() { - return new CollectionChangeListener() { - public void itemsAdded(CollectionAddEvent event) { - SetCollectionValueModelTests.this.setAddEvent = event; - } - public void itemsRemoved(CollectionRemoveEvent event) { - SetCollectionValueModelTests.this.setRemoveEvent = event; - } - public void collectionCleared(CollectionClearEvent event) { - SetCollectionValueModelTests.this.setClearedEvent = event; - } - public void collectionChanged(CollectionChangeEvent event) { - SetCollectionValueModelTests.this.setChangedEvent = event; - } - }; - } - - private ChangeListener buildSetChangeListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(CollectionAddEvent event) { - SetCollectionValueModelTests.this.setAddEvent = event; - } - @Override - public void itemsRemoved(CollectionRemoveEvent event) { - SetCollectionValueModelTests.this.setRemoveEvent = event; - } - @Override - public void collectionCleared(CollectionClearEvent event) { - SetCollectionValueModelTests.this.setClearedEvent = event; - } - @Override - public void collectionChanged(CollectionChangeEvent event) { - SetCollectionValueModelTests.this.setChangedEvent = event; - } - }; - } - - private void verify(CollectionValueModel<String> cvm, String... expectedItems) { - Bag<String> actual = CollectionTools.bag(cvm); - Bag<String> expected = CollectionTools.bag(expectedItems); - assertEquals(expected, actual); - } - - private void verifyEvent(CollectionAddEvent event, Object source, Object... expectedItems) { - assertEquals(source, event.getSource()); - assertEquals(CollectionValueModel.VALUES, event.getCollectionName()); - assertEquals(CollectionTools.bag(expectedItems), CollectionTools.bag(event.getItems())); - } - - private void verifyEvent(CollectionRemoveEvent event, Object source, Object... expectedItems) { - assertEquals(source, event.getSource()); - assertEquals(CollectionValueModel.VALUES, event.getCollectionName()); - assertEquals(CollectionTools.bag(expectedItems), CollectionTools.bag(event.getItems())); - } - - private void verifyEvent(CollectionClearEvent event, Object source) { - assertEquals(source, event.getSource()); - assertEquals(CollectionValueModel.VALUES, event.getCollectionName()); - } - - private void verifyEvent(CollectionChangeEvent event, Object source, Object... expectedItems) { - assertEquals(source, event.getSource()); - assertEquals(CollectionValueModel.VALUES, event.getCollectionName()); - assertEquals(CollectionTools.bag(expectedItems), CollectionTools.bag(event.getCollection())); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleCollectionValueModelTests.java deleted file mode 100644 index 48bac559d7..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleCollectionValueModelTests.java +++ /dev/null @@ -1,443 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Collection; -import java.util.HashSet; -import java.util.Set; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class SimpleCollectionValueModelTests extends TestCase { - private SimpleCollectionValueModel<String> bagHolder; - CollectionEvent bagEvent; - String bagEventType; - - private SimpleCollectionValueModel<String> setHolder; - CollectionEvent setEvent; - String setEventType; - - private static final String ADD = "add"; - private static final String REMOVE = "remove"; - private static final String CHANGE = "change"; - private static final String CLEAR = "clear"; - - - public SimpleCollectionValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.bagHolder = new SimpleCollectionValueModel<String>(this.buildBag()); - this.setHolder = new SimpleCollectionValueModel<String>(this.buildSet()); - } - - private Bag<String> buildBag() { - Bag<String> result = new HashBag<String>(); - this.addItemsTo(result); - return result; - } - - private Set<String> buildSet() { - Set<String> result = new HashSet<String>(); - this.addItemsTo(result); - return result; - } - - private void addItemsTo(Collection<String> c) { - c.add("foo"); - c.add("bar"); - c.add("baz"); - } - - private Bag<String> buildAddItems() { - Bag<String> result = new HashBag<String>(); - result.add("joo"); - result.add("jar"); - result.add("jaz"); - return result; - } - - private Bag<String> buildRemoveItems() { - Bag<String> result = new HashBag<String>(); - result.add("foo"); - result.add("baz"); - return result; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - assertEquals(this.buildBag(), CollectionTools.bag(this.bagHolder.iterator())); - assertEquals(this.buildSet(), CollectionTools.set(this.setHolder.iterator())); - } - - public void testSize() { - assertEquals(this.buildBag().size(), CollectionTools.size(this.bagHolder.iterator())); - assertEquals(this.buildSet().size(), CollectionTools.size(this.setHolder.iterator())); - } - - private boolean bagHolderContains(Object item) { - return CollectionTools.contains(this.bagHolder.iterator(), item); - } - - private boolean setHolderContains(Object item) { - return CollectionTools.contains(this.setHolder.iterator(), item); - } - - private boolean bagHolderContainsAll(Collection<String> items) { - return CollectionTools.containsAll(this.bagHolder.iterator(), items); - } - - private boolean setHolderContainsAll(Collection<String> items) { - return CollectionTools.containsAll(this.setHolder.iterator(), items); - } - - private boolean bagHolderContainsAny(Collection<String> items) { - Bag<String> bag = CollectionTools.bag(this.bagHolder.iterator()); - for (String string : items) { - if (bag.contains(string)) { - return true; - } - } - return false; - } - - private boolean setHolderContainsAny(Collection<String> items) { - Set<String> set = CollectionTools.set(this.setHolder.iterator()); - for (String string : items) { - if (set.contains(string)) { - return true; - } - } - return false; - } - - public void testAdd() { - assertFalse(this.bagHolderContains("joo")); - this.bagHolder.add("joo"); - assertTrue(this.bagHolderContains("joo")); - - assertFalse(this.bagHolderContains(null)); - this.bagHolder.add(null); - assertTrue(this.bagHolderContains(null)); - - assertFalse(this.setHolderContains("joo")); - this.setHolder.add("joo"); - assertTrue(this.setHolderContains("joo")); - - assertFalse(this.setHolderContains(null)); - this.setHolder.add(null); - assertTrue(this.setHolderContains(null)); - } - - public void testAddAll() { - assertFalse(this.bagHolderContainsAny(this.buildAddItems())); - this.bagHolder.addAll(this.buildAddItems()); - assertTrue(this.bagHolderContainsAll(this.buildAddItems())); - - assertFalse(this.setHolderContainsAny(this.buildAddItems())); - this.setHolder.addAll(this.buildAddItems()); - assertTrue(this.setHolderContainsAll(this.buildAddItems())); - } - - public void testRemove() { - assertTrue(this.bagHolderContains("bar")); - this.bagHolder.remove("bar"); - assertFalse(this.bagHolderContains("bar")); - - this.bagHolder.add(null); - assertTrue(this.bagHolderContains(null)); - this.bagHolder.remove(null); - assertFalse(this.bagHolderContains(null)); - - assertTrue(this.setHolderContains("bar")); - this.setHolder.remove("bar"); - assertFalse(this.setHolderContains("bar")); - - this.setHolder.add(null); - assertTrue(this.setHolderContains(null)); - this.setHolder.remove(null); - assertFalse(this.setHolderContains(null)); - } - - public void testRemoveAll() { - assertTrue(this.bagHolderContainsAll(this.buildRemoveItems())); - this.bagHolder.removeAll(this.buildRemoveItems()); - assertFalse(this.bagHolderContainsAny(this.buildRemoveItems())); - - assertTrue(this.setHolderContainsAll(this.buildRemoveItems())); - this.setHolder.removeAll(this.buildRemoveItems()); - assertFalse(this.setHolderContainsAny(this.buildRemoveItems())); - } - - public void testSetValues() { - assertTrue(this.bagHolderContains("bar")); - assertFalse(this.bagHolderContains("jar")); - this.bagHolder.setValues(this.buildAddItems()); - assertFalse(this.bagHolderContains("bar")); - assertTrue(this.bagHolderContains("jar")); - - this.bagHolder.add(null); - assertTrue(this.bagHolderContains(null)); - this.bagHolder.remove(null); - assertFalse(this.bagHolderContains(null)); - - this.bagHolder.setValues(new HashBag<String>()); - assertFalse(this.bagHolderContains("jar")); - - assertTrue(this.setHolderContains("bar")); - assertFalse(this.setHolderContains("jar")); - this.setHolder.setValues(this.buildAddItems()); - assertFalse(this.setHolderContains("bar")); - assertTrue(this.setHolderContains("jar")); - - this.setHolder.add(null); - assertTrue(this.setHolderContains(null)); - this.setHolder.remove(null); - assertFalse(this.setHolderContains(null)); - - this.setHolder.setValues(new HashBag<String>()); - assertFalse(this.setHolderContains("jar")); - } - - public void testCollectionChange1() { - this.bagHolder.addChangeListener(this.buildBagListener()); - this.verifyBagChange(); - - this.setHolder.addChangeListener(this.buildSetListener()); - this.verifySetChange(); - } - - public void testCollectionChange2() { - this.bagHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildBagListener()); - this.verifyBagChange(); - - this.setHolder.addCollectionChangeListener(CollectionValueModel.VALUES, this.buildSetListener()); - this.verifySetChange(); - } - - private void verifyBagChange() { - this.bagEvent = null; - this.bagEventType = null; - this.bagHolder.add("foo"); - this.verifyBagEvent(ADD, "foo"); - - this.bagEvent = null; - this.bagEventType = null; - this.bagHolder.add("foo"); - this.verifyBagEvent(ADD, "foo"); - - this.bagEvent = null; - this.bagEventType = null; - this.bagHolder.add("joo"); - this.verifyBagEvent(ADD, "joo"); - - this.bagEvent = null; - this.bagEventType = null; - this.bagHolder.add(null); - this.verifyBagEvent(ADD, null); - - this.bagEvent = null; - this.bagEventType = null; - this.bagHolder.add(null); - this.verifyBagEvent(ADD, null); - - this.bagEvent = null; - this.bagEventType = null; - this.bagHolder.remove("joo"); - this.verifyBagEvent(REMOVE, "joo"); - - this.bagEvent = null; - this.bagEventType = null; - this.bagHolder.remove(null); - this.verifyBagEvent(REMOVE, null); - - this.bagEvent = null; - this.bagEventType = null; - this.bagHolder.setValues(this.buildBag()); - this.verifyBagEvent(CHANGE); - - this.bagEvent = null; - this.bagEventType = null; - this.bagHolder.addAll(this.buildBag()); - this.verifyBagEvent(ADD); - assertEquals(this.buildBag(), CollectionTools.bag(((CollectionAddEvent) this.bagEvent).getItems())); - } - - private void verifySetChange() { - this.setEvent = null; - this.setEventType = null; - this.setHolder.add("foo"); - assertNull(this.setEvent); - assertNull(this.setEventType); - - this.setEvent = null; - this.setEventType = null; - this.setHolder.add("joo"); - this.verifySetEvent(ADD, "joo"); - - this.setEvent = null; - this.setEventType = null; - this.setHolder.add("joo"); - assertNull(this.setEvent); - assertNull(this.setEventType); - - this.setEvent = null; - this.setEventType = null; - this.setHolder.add(null); - this.verifySetEvent(ADD, null); - - this.setEvent = null; - this.setEventType = null; - this.setHolder.add(null); - assertNull(this.setEvent); - assertNull(this.setEventType); - - this.setEvent = null; - this.setEventType = null; - this.setHolder.remove("joo"); - this.verifySetEvent(REMOVE, "joo"); - - this.setEvent = null; - this.setEventType = null; - this.setHolder.remove("joo"); - assertNull(this.setEvent); - assertNull(this.setEventType); - - this.setEvent = null; - this.setEventType = null; - this.setHolder.remove(null); - this.verifySetEvent(REMOVE, null); - - this.setEvent = null; - this.setEventType = null; - this.setHolder.setValues(this.buildSet()); - this.verifySetEvent(CHANGE); - - this.setEvent = null; - this.setEventType = null; - this.setHolder.addAll(this.buildSet()); - assertNull(this.setEvent); - assertNull(this.setEventType); - } - - private ChangeListener buildBagListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(CollectionAddEvent e) { - SimpleCollectionValueModelTests.this.bagEventType = ADD; - SimpleCollectionValueModelTests.this.bagEvent = e; - } - @Override - public void itemsRemoved(CollectionRemoveEvent e) { - SimpleCollectionValueModelTests.this.bagEventType = REMOVE; - SimpleCollectionValueModelTests.this.bagEvent = e; - } - @Override - public void collectionCleared(CollectionClearEvent e) { - SimpleCollectionValueModelTests.this.bagEventType = CLEAR; - SimpleCollectionValueModelTests.this.bagEvent = e; - } - @Override - public void collectionChanged(CollectionChangeEvent e) { - SimpleCollectionValueModelTests.this.bagEventType = CHANGE; - SimpleCollectionValueModelTests.this.bagEvent = e; - } - }; - } - - private ChangeListener buildSetListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(CollectionAddEvent e) { - SimpleCollectionValueModelTests.this.setEventType = ADD; - SimpleCollectionValueModelTests.this.setEvent = e; - } - @Override - public void itemsRemoved(CollectionRemoveEvent e) { - SimpleCollectionValueModelTests.this.setEventType = REMOVE; - SimpleCollectionValueModelTests.this.setEvent = e; - } - @Override - public void collectionCleared(CollectionClearEvent e) { - SimpleCollectionValueModelTests.this.setEventType = CLEAR; - SimpleCollectionValueModelTests.this.setEvent = e; - } - @Override - public void collectionChanged(CollectionChangeEvent e) { - SimpleCollectionValueModelTests.this.setEventType = CHANGE; - SimpleCollectionValueModelTests.this.setEvent = e; - } - }; - } - - private void verifyBagEvent(String eventType) { - assertEquals(eventType, this.bagEventType); - assertEquals(this.bagHolder, this.bagEvent.getSource()); - assertEquals(CollectionValueModel.VALUES, this.bagEvent.getCollectionName()); - } - - private void verifyBagEvent(String eventType, Object item) { - this.verifyBagEvent(eventType); - assertEquals(item, this.getBagEventItems().iterator().next()); - } - - private Iterable<?> getBagEventItems() { - if (this.bagEvent instanceof CollectionAddEvent) { - return ((CollectionAddEvent) this.bagEvent).getItems(); - } else if (this.bagEvent instanceof CollectionRemoveEvent) { - return ((CollectionRemoveEvent) this.bagEvent).getItems(); - } - throw new IllegalStateException(); - } - - private void verifySetEvent(String eventType) { - assertEquals(eventType, this.setEventType); - assertEquals(this.setHolder, this.setEvent.getSource()); - assertEquals(CollectionValueModel.VALUES, this.setEvent.getCollectionName()); - } - - private void verifySetEvent(String eventType, Object item) { - this.verifySetEvent(eventType); - assertEquals(item, this.getSetEventItems().iterator().next()); - } - - private Iterable<?> getSetEventItems() { - if (this.setEvent instanceof CollectionAddEvent) { - return ((CollectionAddEvent) this.setEvent).getItems(); - } else if (this.setEvent instanceof CollectionRemoveEvent) { - return ((CollectionRemoveEvent) this.setEvent).getItems(); - } - throw new IllegalStateException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleListValueModelTests.java deleted file mode 100644 index f4122fd9fe..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimpleListValueModelTests.java +++ /dev/null @@ -1,378 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.List; -import java.util.Set; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class SimpleListValueModelTests extends TestCase { - private SimpleListValueModel<String> listHolder; - ListEvent event; - String eventType; - - private static final String ADD = "add"; - private static final String REMOVE = "remove"; - private static final String REPLACE = "replace"; - private static final String MOVE = "move"; - private static final String CLEAR = "clear"; - private static final String CHANGE = "change"; - - - public SimpleListValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.listHolder = new SimpleListValueModel<String>(this.buildList()); - } - - private List<String> buildList() { - List<String> result = new ArrayList<String>(); - result.add("foo"); - result.add("bar"); - result.add("baz"); - return result; - } - - private List<String> buildAddList() { - List<String> result = new ArrayList<String>(); - result.add("joo"); - result.add("jar"); - result.add("jaz"); - return result; - } - -// private List<String> buildRemoveList() { -// List<String> result = new ArrayList<String>(); -// result.add("foo"); -// result.add("bar"); -// return result; -// } -// - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - assertEquals(this.buildList(), CollectionTools.list(this.listHolder.iterator())); - } - - public void testListIterator() { - assertEquals(this.buildList(), CollectionTools.list(this.listHolder.listIterator())); - } - - public void testListIteratorInt() { - assertEquals(CollectionTools.list(this.buildList().listIterator(1)), CollectionTools.list(this.listHolder.listIterator(1))); - } - - public void testSize() { - assertEquals(this.buildList().size(), this.listHolder.size()); - } - - private boolean listContains(Object item) { - return CollectionTools.contains(this.listHolder.listIterator(), item); - } - - private boolean listContainsAll(Collection<String> items) { - return CollectionTools.containsAll(this.listHolder.listIterator(), items); - } - - private boolean listContainsAny(Collection<String> items) { - Set<String> set = CollectionTools.set(this.listHolder.iterator()); - for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) { - if (set.contains(stream.next())) { - return true; - } - } - return false; - } - - public void testAddObject() { - assertFalse(this.listContains("joo")); - this.listHolder.add("joo"); - assertTrue(this.listContains("joo")); - - assertFalse(this.listContains(null)); - this.listHolder.add(null); - assertTrue(this.listContains(null)); - } - - public void testAddIntObject() { - assertFalse(this.listContains("joo")); - this.listHolder.add(2, "joo"); - assertTrue(this.listContains("joo")); - - assertFalse(this.listContains(null)); - this.listHolder.add(0, null); - assertTrue(this.listContains(null)); - } - - public void testAddAllCollection() { - assertFalse(this.listContainsAny(this.buildAddList())); - this.listHolder.addAll(this.buildAddList()); - assertTrue(this.listContainsAll(this.buildAddList())); - } - - public void testAddAllIntCollection() { - assertFalse(this.listContainsAny(this.buildAddList())); - this.listHolder.addAll(2, this.buildAddList()); - assertTrue(this.listContainsAll(this.buildAddList())); - } - - public void testClear() { - assertFalse(this.listHolder.isEmpty()); - this.listHolder.clear(); - assertTrue(this.listHolder.isEmpty()); - } - - public void testContainsObject() { - assertTrue(this.listHolder.contains("foo")); - assertFalse(this.listHolder.contains("joo")); - } - - public void testContainsAllCollection() { - Collection<String> c = new ArrayList<String>(); - c.add("foo"); - c.add("bar"); - assertTrue(this.listHolder.containsAll(c)); - - c.add("joo"); - assertFalse(this.listHolder.containsAll(c)); - } - - public void testEquals() { - assertEquals(new SimpleListValueModel<String>(this.buildList()), this.listHolder); - assertFalse(this.listHolder.equals(new SimpleListValueModel<String>(this.buildAddList()))); - assertFalse(this.listHolder.equals(this.buildList())); - assertFalse(this.listHolder.equals(new SimpleListValueModel<String>())); - } - - public void testGetInt() { - assertEquals("foo", this.listHolder.get(0)); - assertEquals("bar", this.listHolder.get(1)); - assertEquals("baz", this.listHolder.get(2)); - } - - public void testHashCode() { - assertEquals(new SimpleListValueModel<String>(this.buildList()).hashCode(), this.listHolder.hashCode()); - } - - public void testIndexOfObject() { - assertEquals(0, this.listHolder.indexOf("foo")); - assertEquals(1, this.listHolder.indexOf("bar")); - assertEquals(2, this.listHolder.indexOf("baz")); - assertEquals(-1, this.listHolder.indexOf("joo")); - } - - public void testLastIndexOfObject() { - assertEquals(0, this.listHolder.lastIndexOf("foo")); - assertEquals(1, this.listHolder.lastIndexOf("bar")); - assertEquals(2, this.listHolder.lastIndexOf("baz")); - assertEquals(-1, this.listHolder.lastIndexOf("joo")); - - this.listHolder.add("foo"); - assertEquals(3, this.listHolder.lastIndexOf("foo")); - } - - public void testIsEmpty() { - assertFalse(this.listHolder.isEmpty()); - this.listHolder.clear(); - assertTrue(this.listHolder.isEmpty()); - } - - public void testRemove() { - assertTrue(this.listContains("bar")); - this.listHolder.remove(this.buildList().indexOf("bar")); - assertFalse(this.listContains("bar")); - - this.listHolder.add(1, null); - assertTrue(this.listContains(null)); - this.listHolder.remove(1); - assertFalse(this.listContains(null)); - } - - public void testSetValues() { - List<String> newList = new ArrayList<String>(); - newList.add("joo"); - newList.add("jar"); - newList.add("jaz"); - - assertTrue(this.listContains("bar")); - assertFalse(this.listContains("jar")); - this.listHolder.setListValues(newList); - assertFalse(this.listContains("bar")); - assertTrue(this.listContains("jar")); - - this.listHolder.add(1, null); - assertTrue(this.listContains(null)); - this.listHolder.remove(1); - assertFalse(this.listContains(null)); - - this.listHolder.setListValues(new ArrayList<String>()); - assertFalse(this.listContains("jar")); - } - - public void testListChange1() { - this.listHolder.addChangeListener(this.buildChangeListener()); - this.verifyListChange(); - } - - public void testListChange2() { - this.listHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - this.verifyListChange(); - } - - private void verifyListChange() { - this.event = null; - this.eventType = null; - this.listHolder.add(1, "joo"); - this.verifyEvent(ADD, 1, "joo"); - - this.event = null; - this.eventType = null; - this.listHolder.add(1, null); - this.verifyEvent(ADD, 1, null); - - this.event = null; - this.eventType = null; - this.listHolder.remove(1); - this.verifyEvent(REMOVE, 1, null); - - this.event = null; - this.eventType = null; - this.listHolder.remove(1); - this.verifyEvent(REMOVE, 1, "joo"); - - this.event = null; - this.eventType = null; - this.listHolder.setListValues(this.buildList()); - this.verifyEvent(CHANGE); - - this.event = null; - this.eventType = null; - this.listHolder.addAll(0, this.buildList()); - this.verifyEvent(ADD); - assertEquals(this.buildList(), CollectionTools.list(((ListAddEvent) this.event).getItems())); - - this.event = null; - this.eventType = null; - this.listHolder.set(0, "joo"); - this.verifyEvent(REPLACE); - assertFalse(CollectionTools.contains(((ListReplaceEvent) this.event).getNewItems(), "foo")); - assertTrue(CollectionTools.contains(((ListReplaceEvent) this.event).getNewItems(), "joo")); - } - - private ListChangeListener buildListener() { - return new ListChangeListener() { - public void itemsAdded(ListAddEvent e) { - SimpleListValueModelTests.this.eventType = ADD; - SimpleListValueModelTests.this.event = e; - } - public void itemsRemoved(ListRemoveEvent e) { - SimpleListValueModelTests.this.eventType = REMOVE; - SimpleListValueModelTests.this.event = e; - } - public void itemsReplaced(ListReplaceEvent e) { - SimpleListValueModelTests.this.eventType = REPLACE; - SimpleListValueModelTests.this.event = e; - } - public void itemsMoved(ListMoveEvent e) { - SimpleListValueModelTests.this.eventType = MOVE; - SimpleListValueModelTests.this.event = e; - } - public void listCleared(ListClearEvent e) { - SimpleListValueModelTests.this.eventType = CLEAR; - SimpleListValueModelTests.this.event = e; - } - public void listChanged(ListChangeEvent e) { - SimpleListValueModelTests.this.eventType = CHANGE; - SimpleListValueModelTests.this.event = e; - } - }; - } - - private ChangeListener buildChangeListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(ListAddEvent e) { - SimpleListValueModelTests.this.eventType = ADD; - SimpleListValueModelTests.this.event = e; - } - @Override - public void itemsRemoved(ListRemoveEvent e) { - SimpleListValueModelTests.this.eventType = REMOVE; - SimpleListValueModelTests.this.event = e; - } - @Override - public void itemsReplaced(ListReplaceEvent e) { - SimpleListValueModelTests.this.eventType = REPLACE; - SimpleListValueModelTests.this.event = e; - } - @Override - public void itemsMoved(ListMoveEvent e) { - SimpleListValueModelTests.this.eventType = MOVE; - SimpleListValueModelTests.this.event = e; - } - @Override - public void listCleared(ListClearEvent e) { - SimpleListValueModelTests.this.eventType = CLEAR; - SimpleListValueModelTests.this.event = e; - } - @Override - public void listChanged(ListChangeEvent e) { - SimpleListValueModelTests.this.eventType = CHANGE; - SimpleListValueModelTests.this.event = e; - } - }; - } - - private void verifyEvent(String e) { - assertEquals(e, this.eventType); - assertEquals(this.listHolder, this.event.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event.getListName()); - } - - private void verifyEvent(String e, int index, Object item) { - this.verifyEvent(e); - if (e == ADD) { - assertEquals(index, ((ListAddEvent) this.event).getIndex()); - assertEquals(item, ((ListAddEvent) this.event).getItems().iterator().next()); - } else if (e == REMOVE) { - assertEquals(index, ((ListRemoveEvent) this.event).getIndex()); - assertEquals(item, ((ListRemoveEvent) this.event).getItems().iterator().next()); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimplePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimplePropertyValueModelTests.java deleted file mode 100644 index e1a617fc71..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SimplePropertyValueModelTests.java +++ /dev/null @@ -1,97 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class SimplePropertyValueModelTests extends TestCase { - private WritablePropertyValueModel<String> objectHolder; - PropertyChangeEvent event; - - - public SimplePropertyValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.objectHolder = new SimplePropertyValueModel<String>("foo"); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testValue() { - assertEquals("foo", this.objectHolder.getValue()); - } - - public void testSetValue() { - this.objectHolder.setValue("bar"); - assertEquals("bar", this.objectHolder.getValue()); - this.objectHolder.setValue(null); - assertEquals(null, this.objectHolder.getValue()); - this.objectHolder.setValue("baz"); - assertEquals("baz", this.objectHolder.getValue()); - } - - public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildListener()); - this.verifyPropertyChange(); - } - - public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.verifyPropertyChange(); - } - - private void verifyPropertyChange() { - this.event = null; - this.objectHolder.setValue("bar"); - this.verifyEvent("foo", "bar"); - - this.event = null; - this.objectHolder.setValue(null); - this.verifyEvent("bar", null); - - this.event = null; - this.objectHolder.setValue("baz"); - this.verifyEvent(null, "baz"); - } - - private ChangeListener buildListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - SimplePropertyValueModelTests.this.event = e; - } - }; - } - - private void verifyEvent(Object oldValue, Object newValue) { - assertEquals(this.objectHolder, this.event.getSource()); - assertEquals(PropertyValueModel.VALUE, this.event.getPropertyName()); - assertEquals(oldValue, this.event.getOldValue()); - assertEquals(newValue, this.event.getNewValue()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelAdapterTests.java deleted file mode 100644 index a1e0d0188b..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelAdapterTests.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.TreeSet; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.ReverseComparator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class SortedListValueModelAdapterTests extends TestCase { - private SortedListValueModelAdapter<String> adapter; - private SimpleCollectionValueModel<String> wrappedCollectionHolder; - private Collection<String> wrappedCollection; - - - public SortedListValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.wrappedCollection = new HashBag<String>(); - this.wrappedCollectionHolder = new SimpleCollectionValueModel<String>(this.wrappedCollection); - this.adapter = new SortedListValueModelAdapter<String>(this.wrappedCollectionHolder); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - private void verifyList(Collection<String> expected, ListValueModel<String> actual) { - this.verifyList(expected, actual, null); - } - - private void verifyList(Collection<String> expected, ListValueModel<String> actual, Comparator<String> comparator) { - Collection<String> sortedSet = new TreeSet<String>(comparator); - sortedSet.addAll(expected); - List<String> expectedList = new ArrayList<String>(sortedSet); - List<String> actualList = CollectionTools.list(actual.iterator()); - assertEquals(expectedList, actualList); - } - - public void testAdd() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - @Override - public void itemsReplaced(ListReplaceEvent e) {/* OK */} - }); - this.wrappedCollectionHolder.add("foo"); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - assertEquals(3, this.adapter.size()); - this.verifyList(this.wrappedCollection, this.adapter); - } - - public void testAddItem() { - List<String> synchList = new CoordinatedList<String>(this.adapter); - Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder); - this.wrappedCollectionHolder.add("foo"); - assertTrue(this.wrappedCollection.contains("foo")); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - this.wrappedCollectionHolder.add("joo"); - this.wrappedCollectionHolder.add("jar"); - this.wrappedCollectionHolder.add("jaz"); - assertEquals(6, this.wrappedCollection.size()); - - this.verifyList(this.wrappedCollection, this.adapter); - assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator())); - assertEquals(this.wrappedCollection, synchCollection); - } - - public void testRemoveItem() { - List<String> synchList = new CoordinatedList<String>(this.adapter); - Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder); - this.wrappedCollectionHolder.add("foo"); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - this.wrappedCollectionHolder.add("joo"); - this.wrappedCollectionHolder.add("jar"); - this.wrappedCollectionHolder.add("jaz"); - this.wrappedCollectionHolder.remove("jaz"); - assertFalse(this.wrappedCollection.contains("jaz")); - this.wrappedCollectionHolder.remove("foo"); - assertFalse(this.wrappedCollection.contains("foo")); - assertEquals(4, this.wrappedCollection.size()); - - this.verifyList(this.wrappedCollection, this.adapter); - assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator())); - assertEquals(this.wrappedCollection, synchCollection); - } - - public void testListSynch() { - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - @Override - public void itemsRemoved(ListRemoveEvent e) {/* OK */} - @Override - public void itemsReplaced(ListReplaceEvent e) {/* OK */} - }); - this.wrappedCollectionHolder.add("foo"); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - this.wrappedCollectionHolder.add("joo"); - this.wrappedCollectionHolder.add("jar"); - this.wrappedCollectionHolder.add("jaz"); - this.wrappedCollectionHolder.remove("jaz"); - assertFalse(this.wrappedCollection.contains("jaz")); - this.wrappedCollectionHolder.remove("foo"); - assertFalse(this.wrappedCollection.contains("foo")); - assertEquals(4, this.wrappedCollection.size()); - - this.verifyList(this.wrappedCollection, this.adapter); - } - - public void testSetComparator() { - List<String> synchList = new CoordinatedList<String>(this.adapter); - Bag<String> synchCollection = new CoordinatedBag<String>(this.wrappedCollectionHolder); - this.wrappedCollectionHolder.add("foo"); - assertTrue(this.wrappedCollection.contains("foo")); - this.wrappedCollectionHolder.add("bar"); - this.wrappedCollectionHolder.add("baz"); - this.wrappedCollectionHolder.add("joo"); - this.wrappedCollectionHolder.add("jar"); - this.wrappedCollectionHolder.add("jaz"); - assertEquals(6, this.wrappedCollection.size()); - - this.verifyList(this.wrappedCollection, this.adapter); - assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator())); - assertEquals(this.wrappedCollection, synchCollection); - - this.adapter.setComparator(new ReverseComparator<String>()); - this.verifyList(this.wrappedCollection, this.adapter, new ReverseComparator<String>()); - assertEquals(this.wrappedCollection, CollectionTools.collection(synchList.iterator())); - assertEquals(this.wrappedCollection, synchCollection); - } - - public void testHasListeners() { - assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - CoordinatedList<String> synchList = new CoordinatedList<String>(this.adapter); - assertTrue(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.adapter.removeListChangeListener(ListValueModel.LIST_VALUES, synchList); - assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - ChangeListener cl = new ChangeAdapter(); - this.adapter.addChangeListener(cl); - assertTrue(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.adapter.removeChangeListener(cl); - assertFalse(((AbstractModel) this.adapter).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - public void testCollectionChange() { - this.wrappedCollectionHolder.add("fred"); - this.adapter.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void listChanged(ListChangeEvent e) {/* OK */} - }); - this.wrappedCollectionHolder.setValues(Arrays.asList(new String[] {"foo", "bar", "baz"})); - assertEquals(3, this.adapter.size()); - this.verifyList(this.wrappedCollection, this.adapter); - } - - class TestListChangeListener implements ListChangeListener { - public void itemsAdded(ListAddEvent e) { - fail("unexpected event"); - } - public void itemsRemoved(ListRemoveEvent e) { - fail("unexpected event"); - } - public void itemsReplaced(ListReplaceEvent e) { - fail("unexpected event"); - } - public void itemsMoved(ListMoveEvent e) { - fail("unexpected event"); - } - public void listCleared(ListClearEvent e) { - fail("unexpected event"); - } - public void listChanged(ListChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelWrapperTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelWrapperTests.java deleted file mode 100644 index 63815b9b45..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/SortedListValueModelWrapperTests.java +++ /dev/null @@ -1,237 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Comparator; -import java.util.List; -import java.util.TreeSet; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.ReverseComparator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class SortedListValueModelWrapperTests extends TestCase { - private List<String> list; - private SimpleListValueModel<String> listModel; - private SortedListValueModelWrapper<String> sortedListModel; - - - public SortedListValueModelWrapperTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.list = new ArrayList<String>(); - this.listModel = new SimpleListValueModel<String>(this.list); - this.sortedListModel = new SortedListValueModelWrapper<String>(this.listModel); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - private void verifyList(Collection<String> expected, ListValueModel<String> actual) { - this.verifyList(expected, actual, null); - } - - private void verifyList(Collection<String> expected, ListValueModel<String> actual, Comparator<String> comparator) { - Collection<String> sortedSet = new TreeSet<String>(comparator); - sortedSet.addAll(expected); - List<String> expectedList = new ArrayList<String>(sortedSet); - List<String> actualList = CollectionTools.list(actual); - assertEquals(expectedList, actualList); - } - - public void testAdd() { - this.sortedListModel.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - @Override - public void itemsReplaced(ListReplaceEvent e) {/* OK */} - }); - this.listModel.add("foo"); - this.listModel.add("bar"); - this.listModel.add("baz"); - assertEquals(3, this.sortedListModel.size()); - this.verifyList(this.list, this.sortedListModel); - } - - public void testAddItem() { - List<String> sortedSynchList = new CoordinatedList<String>(this.sortedListModel); - List<String> synchList = new CoordinatedList<String>(this.listModel); - this.listModel.add("foo"); - assertTrue(this.list.contains("foo")); - this.listModel.add("bar"); - this.listModel.add("baz"); - this.listModel.add("joo"); - this.listModel.add("jar"); - this.listModel.add("jaz"); - assertEquals(6, this.list.size()); - - this.verifyList(this.list, this.sortedListModel); - assertEquals(this.list, synchList); - assertEquals(CollectionTools.list(this.sortedListModel), sortedSynchList); - } - - public void testRemoveItem() { - List<String> sortedSynchList = new CoordinatedList<String>(this.sortedListModel); - List<String> synchList = new CoordinatedList<String>(this.listModel); - this.listModel.add("foo"); - this.listModel.add("bar"); - this.listModel.add("baz"); - this.listModel.add("joo"); - this.listModel.add("jar"); - this.listModel.add("jaz"); - this.listModel.remove("jaz"); - assertFalse(this.list.contains("jaz")); - this.listModel.remove("foo"); - assertFalse(this.list.contains("foo")); - assertEquals(4, this.list.size()); - - this.verifyList(this.list, this.sortedListModel); - assertEquals(this.list, synchList); - assertEquals(CollectionTools.list(this.sortedListModel), sortedSynchList); - } - - public void testReplaceItem() { - List<String> sortedSynchList = new CoordinatedList<String>(this.sortedListModel); - List<String> synchList = new CoordinatedList<String>(this.listModel); - this.listModel.add("foo"); - assertTrue(this.list.contains("foo")); - this.listModel.add("bar"); - this.listModel.add("baz"); - this.listModel.add("joo"); - this.listModel.add("jar"); - this.listModel.add("jaz"); - assertEquals(6, this.list.size()); - this.listModel.set(3, "ttt"); - this.listModel.set(4, "xxx"); - assertTrue(this.list.contains("xxx")); - - this.verifyList(this.list, this.sortedListModel); - assertEquals(this.list, synchList); - assertEquals(CollectionTools.list(this.sortedListModel), sortedSynchList); - } - - public void testListSynch() { - this.sortedListModel.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void itemsAdded(ListAddEvent e) {/* OK */} - @Override - public void itemsRemoved(ListRemoveEvent e) {/* OK */} - @Override - public void itemsReplaced(ListReplaceEvent e) {/* OK */} - }); - this.listModel.add("foo"); - this.listModel.add("bar"); - this.listModel.add("baz"); - this.listModel.add("joo"); - this.listModel.add("jar"); - this.listModel.add("jaz"); - this.listModel.remove("jaz"); - assertFalse(this.list.contains("jaz")); - this.listModel.remove("foo"); - assertFalse(this.list.contains("foo")); - assertEquals(4, this.list.size()); - - this.verifyList(this.list, this.sortedListModel); - } - - public void testSetComparator() { - List<String> sortedSynchList = new CoordinatedList<String>(this.sortedListModel); - List<String> synchList = new CoordinatedList<String>(this.listModel); - this.listModel.add("foo"); - assertTrue(this.list.contains("foo")); - this.listModel.add("bar"); - this.listModel.add("baz"); - this.listModel.add("joo"); - this.listModel.add("jar"); - this.listModel.add("jaz"); - assertEquals(6, this.list.size()); - - this.verifyList(this.list, this.sortedListModel); - assertEquals(this.list, synchList); - assertEquals(CollectionTools.list(this.sortedListModel), sortedSynchList); - - this.sortedListModel.setComparator(new ReverseComparator<String>()); - this.verifyList(this.list, this.sortedListModel, new ReverseComparator<String>()); - assertEquals(this.list, synchList); - } - - public void testHasListeners() { - assertFalse(((AbstractModel) this.sortedListModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - CoordinatedList<String> sortedSynchList = new CoordinatedList<String>(this.sortedListModel); - assertTrue(((AbstractModel) this.sortedListModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.sortedListModel.removeListChangeListener(ListValueModel.LIST_VALUES, sortedSynchList); - assertFalse(((AbstractModel) this.sortedListModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - ChangeListener cl = new ChangeAdapter(); - this.sortedListModel.addChangeListener(cl); - assertTrue(((AbstractModel) this.sortedListModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.sortedListModel.removeChangeListener(cl); - assertFalse(((AbstractModel) this.sortedListModel).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - public void testListChange() { - this.listModel.add("fred"); - this.sortedListModel.addListChangeListener(ListValueModel.LIST_VALUES, new TestListChangeListener() { - @Override - public void listChanged(ListChangeEvent e) {/* OK */} - }); - this.listModel.setListValues(Arrays.asList(new String[] {"foo", "bar", "baz"})); - assertEquals(3, this.sortedListModel.size()); - this.verifyList(this.list, this.sortedListModel); - } - - class TestListChangeListener implements ListChangeListener { - public void itemsAdded(ListAddEvent e) { - fail("unexpected event"); - } - public void itemsRemoved(ListRemoveEvent e) { - fail("unexpected event"); - } - public void itemsReplaced(ListReplaceEvent e) { - fail("unexpected event"); - } - public void itemsMoved(ListMoveEvent e) { - fail("unexpected event"); - } - public void listCleared(ListClearEvent e) { - fail("unexpected event"); - } - public void listChanged(ListChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java deleted file mode 100644 index dca32f9315..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticCollectionValueModelTests.java +++ /dev/null @@ -1,61 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Collection; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.model.value.StaticCollectionValueModel; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class StaticCollectionValueModelTests extends TestCase { - - private static final Collection<String> COLLECTION = buildCollection(); - private static Collection<String> buildCollection() { - Collection<String> result = new HashBag<String>(); - result.add("foo"); - result.add("bar"); - return result; - } - - private CollectionValueModel<String> collectionHolder; - - - public StaticCollectionValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.collectionHolder = this.buildCollectionHolder(); - } - - private CollectionValueModel<String> buildCollectionHolder() { - return new StaticCollectionValueModel<String>(COLLECTION); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - assertEquals(buildCollection(), CollectionTools.bag(this.collectionHolder.iterator())); - } - - public void testSize() { - assertEquals(buildCollection().size(), this.collectionHolder.size()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java deleted file mode 100644 index 0d7cbc6110..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticListValueModelTests.java +++ /dev/null @@ -1,64 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.List; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.value.StaticListValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class StaticListValueModelTests extends TestCase { - - private static final List<String> LIST = buildList(); - private static List<String> buildList() { - List<String> result = new ArrayList<String>(); - result.add("foo"); - result.add("bar"); - return result; - } - - private ListValueModel<String> listHolder; - - - public StaticListValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.listHolder = new StaticListValueModel<String>(LIST); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testGet() { - List<String> expected = buildList(); - for (int i = 0; i < this.listHolder.size(); i++) { - assertEquals(expected.get(i), this.listHolder.get(i)); - } - } - - public void testIterator() { - assertEquals(buildList(), CollectionTools.list(this.listHolder.listIterator())); - } - - public void testSize() { - assertEquals(buildList().size(), this.listHolder.size()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java deleted file mode 100644 index 380cf17c58..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/StaticValueModelTests.java +++ /dev/null @@ -1,46 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class StaticValueModelTests extends TestCase { - private PropertyValueModel<String> objectHolder; - private static final PropertyValueModel<String> OBJECT_HOLDER = new StaticPropertyValueModel<String>("foo"); - - - public StaticValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.objectHolder = OBJECT_HOLDER; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testValue() { - assertEquals("foo", this.objectHolder.getValue()); - } - - public void testToString() { - assertTrue(this.objectHolder.toString().indexOf("foo") >= 0); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationListValueModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationListValueModelAdapterTests.java deleted file mode 100644 index 83ce590d81..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationListValueModelAdapterTests.java +++ /dev/null @@ -1,339 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.Transformer; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationListValueModelAdapter; -import org.eclipse.jpt.utility.model.event.ListAddEvent; -import org.eclipse.jpt.utility.model.event.ListChangeEvent; -import org.eclipse.jpt.utility.model.event.ListClearEvent; -import org.eclipse.jpt.utility.model.event.ListEvent; -import org.eclipse.jpt.utility.model.event.ListMoveEvent; -import org.eclipse.jpt.utility.model.event.ListRemoveEvent; -import org.eclipse.jpt.utility.model.event.ListReplaceEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class TransformationListValueModelAdapterTests extends TestCase { - private SimpleListValueModel<String> listHolder; - private ListValueModel<String> transformedListHolder; - ListEvent event; - String eventType; - - private static final String ADD = "add"; - private static final String REMOVE = "remove"; - private static final String REPLACE = "replace"; - private static final String MOVE = "move"; - private static final String CLEAR = "clear"; - private static final String CHANGE = "change"; - - - public TransformationListValueModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.listHolder = new SimpleListValueModel<String>(this.buildList()); - this.transformedListHolder = this.buildTransformedListHolder(this.listHolder); - } - - private List<String> buildList() { - List<String> result = new ArrayList<String>(); - result.add("foo"); - result.add("bar"); - result.add("baz"); - return result; - } - - private List<String> buildTransformedList() { - return this.transform(this.buildList()); - } - - private List<String> transform(List<String> list) { - List<String> result = new ArrayList<String>(list.size()); - for (String string : list) { - if (string == null) { - result.add(null); - } else { - result.add(string.toUpperCase()); - } - } - return result; - } - - private List<String> buildAddList() { - List<String> result = new ArrayList<String>(); - result.add("joo"); - result.add("jar"); - result.add("jaz"); - return result; - } - - private List<String> buildTransformedAddList() { - return this.transform(this.buildAddList()); - } - -// private List<String> buildRemoveList() { -// List<String> result = new ArrayList<String>(); -// result.add("foo"); -// result.add("bar"); -// return result; -// } -// -// private List<String> buildTransformedRemoveList() { -// return this.transform(this.buildRemoveList()); -// } -// - ListValueModel<String> buildTransformedListHolder(ListValueModel<String> lvm) { - return new TransformationListValueModelAdapter<String, String>(lvm) { - @Override - protected String transformItem(String s) { - return (s == null) ? null : s.toUpperCase(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testIterator() { - this.transformedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - assertEquals(this.buildTransformedList(), CollectionTools.list(this.transformedListHolder.iterator())); - } - - public void testStaleValues() { - ListChangeListener listener = this.buildListener(); - this.transformedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, listener); - assertEquals(this.buildTransformedList(), CollectionTools.list(this.transformedListHolder.iterator())); - - this.transformedListHolder.removeListChangeListener(ListValueModel.LIST_VALUES, listener); - assertEquals(Collections.EMPTY_LIST, CollectionTools.list(this.transformedListHolder.iterator())); - } - - public void testSize() { - this.transformedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - assertEquals(this.buildTransformedList().size(), CollectionTools.size(this.transformedListHolder.iterator())); - } - - private boolean transformedListContains(Object item) { - return CollectionTools.contains(this.transformedListHolder.iterator(), item); - } - - private boolean transformedListContainsAll(Collection<String> items) { - return CollectionTools.containsAll(this.transformedListHolder.iterator(), items); - } - - private boolean transformedListContainsAny(Collection<String> items) { - List<String> transformedList = CollectionTools.list(this.transformedListHolder.iterator()); - for (Iterator<String> stream = items.iterator(); stream.hasNext(); ) { - if (transformedList.contains(stream.next())) { - return true; - } - } - return false; - } - - public void testAdd() { - this.transformedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - - assertFalse(this.transformedListContains("JOO")); - this.listHolder.add(2, "joo"); - assertTrue(this.transformedListContains("JOO")); - - assertFalse(this.transformedListContains(null)); - this.listHolder.add(0, null); - assertTrue(this.transformedListContains(null)); - } - - public void testAddAll() { - this.transformedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - - assertFalse(this.transformedListContainsAny(this.buildTransformedAddList())); - this.listHolder.addAll(2, this.buildAddList()); - assertTrue(this.transformedListContainsAll(this.buildTransformedAddList())); - } - - public void testRemove() { - this.transformedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - - assertTrue(this.transformedListContains("BAR")); - this.listHolder.remove(this.buildList().indexOf("bar")); - assertFalse(this.transformedListContains("BAR")); - - this.listHolder.add(1, null); - assertTrue(this.transformedListContains(null)); - this.listHolder.remove(1); - assertFalse(this.transformedListContains(null)); - } - - public void testListChangeGeneric() { - this.transformedListHolder.addChangeListener(this.buildListener()); - this.verifyListChange(); - } - - public void testListChangeNamed() { - this.transformedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, this.buildListener()); - this.verifyListChange(); - } - - private void verifyListChange() { - this.event = null; - this.eventType = null; - this.listHolder.add(1, "joo"); - this.verifyEvent(ADD, 1, "JOO"); - - this.event = null; - this.eventType = null; - this.listHolder.add(1, null); - this.verifyEvent(ADD, 1, null); - - this.event = null; - this.eventType = null; - this.listHolder.remove(1); - this.verifyEvent(REMOVE, 1, null); - - this.event = null; - this.eventType = null; - this.listHolder.remove(1); - this.verifyEvent(REMOVE, 1, "JOO"); - - this.event = null; - this.eventType = null; - this.listHolder.addAll(0, this.buildList()); - this.verifyEvent(ADD); - assertEquals(this.buildTransformedList(), CollectionTools.list(((ListAddEvent) this.event).getItems())); - - this.event = null; - this.eventType = null; - this.listHolder.set(0, "joo"); - this.verifyEvent(REPLACE); - assertFalse(CollectionTools.contains(((ListReplaceEvent) this.event).getNewItems(), "FOO")); - assertTrue(CollectionTools.contains(((ListReplaceEvent) this.event).getNewItems(), "JOO")); - } - - private ChangeListener buildListener() { - return new ChangeAdapter() { - @Override - public void itemsAdded(ListAddEvent e) { - TransformationListValueModelAdapterTests.this.eventType = ADD; - TransformationListValueModelAdapterTests.this.event = e; - } - @Override - public void itemsRemoved(ListRemoveEvent e) { - TransformationListValueModelAdapterTests.this.eventType = REMOVE; - TransformationListValueModelAdapterTests.this.event = e; - } - @Override - public void itemsReplaced(ListReplaceEvent e) { - TransformationListValueModelAdapterTests.this.eventType = REPLACE; - TransformationListValueModelAdapterTests.this.event = e; - } - @Override - public void itemsMoved(ListMoveEvent e) { - TransformationListValueModelAdapterTests.this.eventType = MOVE; - TransformationListValueModelAdapterTests.this.event = e; - } - @Override - public void listCleared(ListClearEvent e) { - TransformationListValueModelAdapterTests.this.eventType = CLEAR; - TransformationListValueModelAdapterTests.this.event = e; - } - @Override - public void listChanged(ListChangeEvent e) { - TransformationListValueModelAdapterTests.this.eventType = CHANGE; - TransformationListValueModelAdapterTests.this.event = e; - } - }; - } - - private void verifyEvent(String type) { - assertEquals(type, this.eventType); - assertEquals(this.transformedListHolder, this.event.getSource()); - assertEquals(ListValueModel.LIST_VALUES, this.event.getListName()); - } - - private void verifyEvent(String type, int index, Object item) { - this.verifyEvent(type); - if (type == ADD) { - assertEquals(index, ((ListAddEvent) this.event).getIndex()); - assertEquals(item, ((ListAddEvent) this.event).getItems().iterator().next()); - } else if (type == REMOVE) { - assertEquals(index, ((ListRemoveEvent) this.event).getIndex()); - assertEquals(item, ((ListRemoveEvent) this.event).getItems().iterator().next()); - } - } - - public void testHasListeners() { - /* - * adding listeners to the transformed list will cause listeners - * to be added to the wrapped list; - * likewise, removing listeners from the transformed list will - * cause listeners to be removed from the wrapped list - */ - assertFalse(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - ChangeListener listener = this.buildListener(); - - this.transformedListHolder.addListChangeListener(ListValueModel.LIST_VALUES, listener); - assertTrue(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - this.transformedListHolder.removeListChangeListener(ListValueModel.LIST_VALUES, listener); - assertFalse(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - this.transformedListHolder.addChangeListener(listener); - assertTrue(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - this.transformedListHolder.removeChangeListener(listener); - assertFalse(((AbstractModel) this.listHolder).hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - } - - - /** - * execute the same set of tests again, but by passing a Transformer to the adapter - * (as opposed to overriding #transformItem(Object)) - */ - public static class TransformerTests extends TransformationListValueModelAdapterTests { - public TransformerTests(String name) { - super(name); - } - @Override - ListValueModel<String> buildTransformedListHolder(ListValueModel<String> lvm) { - return new TransformationListValueModelAdapter<String, String>(lvm, this.buildTransformer()); - } - private Transformer<String, String> buildTransformer() { - return new Transformer<String, String>() { - public String transform(String s) { - return (s == null) ? null : s.toUpperCase(); - } - }; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java deleted file mode 100644 index 0aaa6e4ee5..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TransformationPropertyValueModelTests.java +++ /dev/null @@ -1,189 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.BidiTransformer; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationWritablePropertyValueModel; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class TransformationPropertyValueModelTests extends TestCase { - private WritablePropertyValueModel<String> objectHolder; - PropertyChangeEvent event; - - private WritablePropertyValueModel<String> transformationObjectHolder; - PropertyChangeEvent transformationEvent; - - public TransformationPropertyValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.objectHolder = new SimplePropertyValueModel<String>("foo"); - this.transformationObjectHolder = new TransformationWritablePropertyValueModel<String, String>(this.objectHolder, this.buildTransformer()); - } - - private BidiTransformer<String, String> buildTransformer() { - return new BidiTransformer<String, String>() { - public String transform(String s) { - return (s == null) ? null : s.toUpperCase(); - } - public String reverseTransform(String s) { - return (s == null) ? null : s.toLowerCase(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testValue() { - assertEquals("foo", this.objectHolder.getValue()); - assertEquals("FOO", this.transformationObjectHolder.getValue()); - - this.objectHolder.setValue("bar"); - assertEquals("bar", this.objectHolder.getValue()); - assertEquals("BAR", this.transformationObjectHolder.getValue()); - - this.objectHolder.setValue("baz"); - assertEquals("baz", this.objectHolder.getValue()); - assertEquals("BAZ", this.transformationObjectHolder.getValue()); - - this.objectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); - - this.objectHolder.setValue("foo"); - assertEquals("foo", this.objectHolder.getValue()); - assertEquals("FOO", this.transformationObjectHolder.getValue()); - } - - public void testSetValue() { - this.transformationObjectHolder.setValue("BAR"); - assertEquals("bar", this.objectHolder.getValue()); - assertEquals("BAR", this.transformationObjectHolder.getValue()); - - this.transformationObjectHolder.setValue("Foo"); - assertEquals("foo", this.objectHolder.getValue()); - assertEquals("FOO", this.transformationObjectHolder.getValue()); - - this.transformationObjectHolder.setValue(null); - assertNull(this.objectHolder.getValue()); - assertNull(this.transformationObjectHolder.getValue()); - - this.transformationObjectHolder.setValue("baz"); - assertEquals("baz", this.objectHolder.getValue()); - assertEquals("BAZ", this.transformationObjectHolder.getValue()); - } - - public void testLazyListening() { - assertTrue(((AbstractModel) this.objectHolder).hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - ChangeListener listener = this.buildTransformationListener(); - 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)); - } - - public void testPropertyChange1() { - this.objectHolder.addChangeListener(this.buildListener()); - this.transformationObjectHolder.addChangeListener(this.buildTransformationListener()); - this.verifyPropertyChanges(); - } - - public void testPropertyChange2() { - this.objectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildListener()); - this.transformationObjectHolder.addPropertyChangeListener(PropertyValueModel.VALUE, this.buildTransformationListener()); - this.verifyPropertyChanges(); - } - - private void verifyPropertyChanges() { - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("bar"); - this.verifyEvent(this.event, this.objectHolder, "foo", "bar"); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "FOO", "BAR"); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("baz"); - this.verifyEvent(this.event, this.objectHolder, "bar", "baz"); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "BAR", "BAZ"); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("Foo"); - this.verifyEvent(this.event, this.objectHolder, "baz", "Foo"); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "BAZ", "FOO"); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("FOO"); - this.verifyEvent(this.event, this.objectHolder, "Foo", "FOO"); - assertNull(this.transformationEvent); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue(null); - this.verifyEvent(this.event, this.objectHolder, "FOO", null); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, "FOO", null); - - this.event = null; - this.transformationEvent = null; - this.objectHolder.setValue("bar"); - this.verifyEvent(this.event, this.objectHolder, null, "bar"); - this.verifyEvent(this.transformationEvent, this.transformationObjectHolder, null, "BAR"); - } - - private ChangeListener buildListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - TransformationPropertyValueModelTests.this.event = e; - } - }; - } - - private ChangeListener buildTransformationListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - TransformationPropertyValueModelTests.this.transformationEvent = e; - } - }; - } - - private void verifyEvent(PropertyChangeEvent e, Object source, Object oldValue, Object newValue) { - assertEquals(source, e.getSource()); - assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); - assertEquals(oldValue, e.getOldValue()); - assertEquals(newValue, e.getNewValue()); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java deleted file mode 100644 index 4f851b4e9c..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/TreeAspectAdapterTests.java +++ /dev/null @@ -1,362 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.Collection; -import java.util.Iterator; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.iterators.ChainIterator; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.iterators.TreeIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TreeAspectAdapter; -import org.eclipse.jpt.utility.model.event.TreeAddEvent; -import org.eclipse.jpt.utility.model.event.TreeChangeEvent; -import org.eclipse.jpt.utility.model.event.TreeClearEvent; -import org.eclipse.jpt.utility.model.event.TreeEvent; -import org.eclipse.jpt.utility.model.event.TreeRemoveEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.TreeChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.TreeValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class TreeAspectAdapterTests extends TestCase { - private TestSubject subject1; - private WritablePropertyValueModel<TestSubject> subjectHolder1; - private TreeAspectAdapter<TestSubject, List<TestNode>> aa1; - private TreeEvent event1; - private TreeChangeListener listener1; - - private TestSubject subject2; - - - public TreeAspectAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.subject1 = new TestSubject(); - TestNode root, node; - - root = this.subject1.getRootNameNode(); - node = this.subject1.addName(root, "name 1.1"); - this.subject1.addName(node, "name 1.1.1"); - this.subject1.addName(node, "name 1.1.2"); - node = this.subject1.addName(root, "name 1.2"); - this.subject1.addName(node, "name 1.2.1"); - node = this.subject1.addName(root, "name 1.3"); - - root = this.subject1.getRootDescriptionNode(); - node = this.subject1.addDescription(root, "description 1.1"); - this.subject1.addDescription(node, "description 1.1.1"); - this.subject1.addDescription(node, "description 1.1.2"); - node = this.subject1.addDescription(root, "description 1.2"); - this.subject1.addDescription(node, "description 1.2.1"); - node = this.subject1.addDescription(root, "description 1.3"); - - this.subjectHolder1 = new SimplePropertyValueModel<TestSubject>(this.subject1); - this.aa1 = this.buildAspectAdapter(this.subjectHolder1); - this.listener1 = this.buildValueChangeListener1(); - this.aa1.addTreeChangeListener(TreeValueModel.NODES, this.listener1); - this.event1 = null; - - this.subject2 = new TestSubject(); - - root = this.subject2.getRootNameNode(); - node = this.subject2.addName(root, "name 2.1"); - this.subject2.addName(node, "name 2.1.1"); - this.subject2.addName(node, "name 2.1.2"); - node = this.subject2.addName(root, "name 2.2"); - this.subject2.addName(node, "name 2.2.1"); - node = this.subject2.addName(root, "name 2.3"); - - root = this.subject2.getRootDescriptionNode(); - node = this.subject2.addDescription(root, "description 2.1"); - this.subject2.addDescription(node, "description 2.1.1"); - this.subject2.addDescription(node, "description 2.1.2"); - node = this.subject2.addDescription(root, "description 2.2"); - this.subject2.addDescription(node, "description 2.2.1"); - node = this.subject2.addDescription(root, "description 2.3"); - } - - private TreeAspectAdapter<TestSubject, List<TestNode>> buildAspectAdapter(PropertyValueModel<TestSubject> subjectHolder) { - return new TreeAspectAdapter<TestSubject, List<TestNode>>(subjectHolder, TestSubject.NAMES_TREE) { - // this is not a typical aspect adapter - the value is determined by the aspect name - @Override - protected Iterator<List<TestNode>> nodes_() { - if (this.treeNames[0] == TestSubject.NAMES_TREE) { - return this.subject.namePaths(); - } - if (this.treeNames[0] == TestSubject.DESCRIPTIONS_TREE) { - return this.subject.descriptionPaths(); - } - throw new IllegalStateException("invalid aspect name: " + this.treeNames[0]); - } - }; - } - - private ChangeListener buildValueChangeListener1() { - return new ChangeAdapter() { - @Override - public void nodeAdded(TreeAddEvent e) { - TreeAspectAdapterTests.this.value1Changed(e); - } - @Override - public void nodeRemoved(TreeRemoveEvent e) { - TreeAspectAdapterTests.this.value1Changed(e); - } - @Override - public void treeCleared(TreeClearEvent e) { - TreeAspectAdapterTests.this.value1Changed(e); - } - @Override - public void treeChanged(TreeChangeEvent e) { - TreeAspectAdapterTests.this.value1Changed(e); - } - }; - } - - void value1Changed(TreeEvent e) { - this.event1 = e; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSubjectHolder() { - assertNull(this.event1); - - this.subjectHolder1.setValue(this.subject2); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(TreeValueModel.NODES, this.event1.getTreeName()); - - this.event1 = null; - this.subjectHolder1.setValue(null); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(TreeValueModel.NODES, this.event1.getTreeName()); - - this.event1 = null; - this.subjectHolder1.setValue(this.subject1); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(TreeValueModel.NODES, this.event1.getTreeName()); - } - - public void testTreeStructureChange() { - assertNull(this.event1); - - this.subject1.addTwoNames(this.subject1.getRootNameNode(), "jam", "jaz"); - assertNotNull(this.event1); - assertEquals(this.aa1, this.event1.getSource()); - assertEquals(TreeValueModel.NODES, this.event1.getTreeName()); - assertTrue(this.subject1.containsNameNode("jam")); - assertTrue(this.subject1.containsNameNode("jaz")); - } - - public void testNodes() { - assertEquals(this.convertToNames(this.subject1.namePaths()), this.convertToNames(this.aa1.nodes())); - } - - private Collection<String> convertToNames(Iterator<List<TestNode>> namePaths) { - Collection<String> result = new HashBag<String>(); - while (namePaths.hasNext()) { - List<TestNode> path = namePaths.next(); - StringBuffer sb = new StringBuffer(); - sb.append('['); - for (int i = 0; i < path.size(); i++) { - sb.append(path.get(i).getText()); - if (i < path.size() - 1) { - sb.append(':'); - } - } - sb.append(']'); - result.add(sb.toString()); - } - return result; - } - - public void testHasListeners() { - assertTrue(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES)); - assertTrue(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE)); - this.aa1.removeTreeChangeListener(TreeValueModel.NODES, this.listener1); - assertFalse(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE)); - assertFalse(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES)); - - ChangeListener listener2 = this.buildValueChangeListener1(); - this.aa1.addChangeListener(listener2); - assertTrue(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES)); - assertTrue(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE)); - this.aa1.removeChangeListener(listener2); - assertFalse(this.subject1.hasAnyTreeChangeListeners(TestSubject.NAMES_TREE)); - assertFalse(this.aa1.hasAnyTreeChangeListeners(TreeValueModel.NODES)); - } - - // ********** inner classes ********** - - class TestSubject extends AbstractModel { - private TestNode rootNameNode; - public static final String NAMES_TREE = "names"; - private TestNode rootDescriptionNode; - public static final String DESCRIPTIONS_TREE = "descriptions"; - - public TestSubject() { - this.rootNameNode = new TestNode("root name"); - this.rootDescriptionNode = new TestNode("root description"); - } - public TestNode getRootNameNode() { - return this.rootNameNode; - } - public Iterator<TestNode> nameNodes() { - return new TreeIterator<TestNode>(this.rootNameNode) { - @Override - public Iterator<TestNode> children(TestNode next) { - return next.children(); - } - }; - } - public Iterator<List<TestNode>> namePaths() { - return new TransformationIterator<TestNode, List<TestNode>>(this.nameNodes()) { - @Override - protected List<TestNode> transform(TestNode next) { - return next.getPath(); - } - }; - } - public TestNode addName(TestNode parent, String name) { - TestNode child = new TestNode(name); - parent.addChild(child); - this.fireNodeAdded(NAMES_TREE, child.getPath()); - return child; - } - public void addTwoNames(TestNode parent, String name1, String name2) { - parent.addChild(new TestNode(name1)); - parent.addChild(new TestNode(name2)); - this.fireTreeChanged(NAMES_TREE, parent.getPath()); - } - public void removeNameNode(TestNode nameNode) { - nameNode.getParent().removeChild(nameNode); - this.fireNodeRemoved(NAMES_TREE, nameNode.getPath()); - } - public boolean containsNameNode(String name) { - return this.nameNode(name) != null; - } - public TestNode nameNode(String name) { - for (Iterator<TestNode> stream = this.nameNodes(); stream.hasNext(); ) { - TestNode node = stream.next(); - if (node.getText().equals(name)) { - return node; - } - } - return null; - } - public TestNode getRootDescriptionNode() { - return this.rootDescriptionNode; - } - public Iterator<TestNode> descriptionNodes() { - return new TreeIterator<TestNode>(this.rootDescriptionNode) { - @Override - public Iterator<TestNode> children(TestNode next) { - return next.children(); - } - }; - } - public Iterator<List<TestNode>> descriptionPaths() { - return new TransformationIterator<TestNode, List<TestNode>>(this.descriptionNodes()) { - @Override - protected List<TestNode> transform(TestNode next) { - return next.getPath(); - } - }; - } - public TestNode addDescription(TestNode parent, String description) { - TestNode child = new TestNode(description); - parent.addChild(child); - this.fireNodeAdded(DESCRIPTIONS_TREE, child.getPath()); - return child; - } - public void removeDescriptionNode(TestNode descriptionNode) { - descriptionNode.getParent().removeChild(descriptionNode); - this.fireNodeRemoved(DESCRIPTIONS_TREE, descriptionNode.getPath()); - } - public boolean containsDescriptionNode(String name) { - for (Iterator<TestNode> stream = this.descriptionNodes(); stream.hasNext(); ) { - TestNode node = stream.next(); - if (node.getText().equals(name)) { - return true; - } - } - return false; - } - } - - class TestNode { - private final String text; - private TestNode parent; - private final Collection<TestNode> children; - - public TestNode(String text) { - this.text = text; - this.children = new HashBag<TestNode>(); - } - public String getText() { - return this.text; - } - public TestNode getParent() { - return this.parent; - } - private void setParent(TestNode parent) { - this.parent = parent; - } - public Iterator<TestNode> children() { - return new ReadOnlyIterator<TestNode>(this.children); - } - public void addChild(TestNode child) { - this.children.add(child); - child.setParent(this); - } - public void removeChild(TestNode child) { - this.children.remove(child); - } - public List<TestNode> getPath() { - return CollectionTools.reverseList(this.buildAntiPath()); - } - private Iterator<TestNode> buildAntiPath() { - return new ChainIterator<TestNode>(this) { - @Override - protected TestNode nextLink(TestNode currentLink) { - return currentLink.getParent(); - } - }; - } - @Override - public String toString() { - return "TestNode(" + this.text + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueCollectionAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueCollectionAdapterTests.java deleted file mode 100644 index f9e5e72674..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueCollectionAdapterTests.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.Collection; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.ValueCollectionAdapter; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.event.StateChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ValueCollectionAdapterTests extends TestCase { - private Junk junk; - private SimplePropertyValueModel<Junk> junkHolder; - private ValueCollectionAdapter<Junk> junkHolder2; - - - public ValueCollectionAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.junk = new Junk("foo"); - this.junkHolder = new SimplePropertyValueModel<Junk>(this.junk); - this.junkHolder2 = new ValueCollectionAdapter<Junk>(this.junkHolder, Junk.STUFF_COLLECTION); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testWrappedPVM() { - Junk junk2 = new Junk("bar"); - LocalListener l = new LocalListener(this.junkHolder2, this.junk, junk2); - this.junkHolder2.addChangeListener(l); - this.junkHolder.setValue(junk2); - assertTrue(l.eventReceived()); - } - - public void testHasPropertyChangeListeners() throws Exception { - assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addChangeListener(l); - assertTrue(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.junkHolder2.removeChangeListener(l); - assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - public void testHasStateChangeListeners() throws Exception { - assertFalse(this.junk.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION)); - assertFalse(this.junkHolder2.hasAnyStateChangeListeners()); - - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addStateChangeListener(l); - assertTrue(this.junk.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION)); - assertTrue(this.junkHolder2.hasAnyStateChangeListeners()); - - this.junkHolder2.removeStateChangeListener(l); - assertFalse(this.junk.hasAnyCollectionChangeListeners(Junk.STUFF_COLLECTION)); - assertFalse(this.junkHolder2.hasAnyStateChangeListeners()); - } - - public void testCollectionAdd() { - LocalListener l = new LocalListener(this.junkHolder2); - this.junkHolder2.addStateChangeListener(l); - this.junk.addStuff("bar"); - assertTrue(l.eventReceived()); - } - - public void testCollectionRemove() { - LocalListener l = new LocalListener(this.junkHolder2); - this.junkHolder2.addStateChangeListener(l); - this.junk.removeStuff("foo"); - assertTrue(l.eventReceived()); - } - - - class LocalListener extends ChangeAdapter { - private boolean eventReceived = false; - private final Object source; - private final Object oldValue; - private final Object newValue; - LocalListener(Object source) { - this(source, null, null); - } - LocalListener(Object source, Object oldValue, Object newValue) { - super(); - this.source = source; - this.oldValue = oldValue; - this.newValue = newValue; - } - @Override - public void propertyChanged(PropertyChangeEvent e) { - this.eventReceived = true; - assertEquals(this.source, e.getSource()); - assertEquals(this.oldValue, e.getOldValue()); - assertEquals(this.newValue, e.getNewValue()); - assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); - } - @Override - public void stateChanged(StateChangeEvent e) { - this.eventReceived = true; - assertEquals(this.source, e.getSource()); - } - boolean eventReceived() { - return this.eventReceived; - } - } - - - private class Junk extends AbstractModel { - private Collection<String> stuff; - public static final String STUFF_COLLECTION = "stuff"; - - public Junk(String stuffItem) { - this.stuff = new ArrayList<String>(); - this.stuff.add(stuffItem); - } - - public void addStuff(String stuffItem) { - this.addItemToCollection(stuffItem, this.stuff, STUFF_COLLECTION); - } - - public void removeStuff(String stuffItem) { - this.removeItemFromCollection(stuffItem, this.stuff, STUFF_COLLECTION); - } - - @Override - public String toString() { - return "Junk(" + this.stuff + ")"; - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueListAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueListAdapterTests.java deleted file mode 100644 index 89d3c25a42..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueListAdapterTests.java +++ /dev/null @@ -1,169 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import java.util.ArrayList; -import java.util.List; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.ValueListAdapter; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.event.StateChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ValueListAdapterTests extends TestCase { - private Junk junk; - private SimplePropertyValueModel<Junk> junkHolder; - private ValueListAdapter<Junk> junkHolder2; - - - public ValueListAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.junk = new Junk("foo"); - this.junkHolder = new SimplePropertyValueModel<Junk>(this.junk); - this.junkHolder2 = new ValueListAdapter<Junk>(this.junkHolder, Junk.STUFF_LIST); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testWrappedPVM() { - Junk junk2 = new Junk("bar"); - LocalListener l = new LocalListener(this.junkHolder2, this.junk, junk2); - this.junkHolder2.addChangeListener(l); - this.junkHolder.setValue(junk2); - assertTrue(l.eventReceived()); - } - - public void testHasPropertyChangeListeners() throws Exception { - assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addChangeListener(l); - assertTrue(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.junkHolder2.removeChangeListener(l); - assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - public void testHasStateChangeListeners() throws Exception { - assertFalse(this.junk.hasAnyListChangeListeners(Junk.STUFF_LIST)); - assertFalse(this.junkHolder2.hasAnyStateChangeListeners()); - - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addStateChangeListener(l); - assertTrue(this.junk.hasAnyListChangeListeners(Junk.STUFF_LIST)); - assertTrue(this.junkHolder2.hasAnyStateChangeListeners()); - - this.junkHolder2.removeStateChangeListener(l); - assertFalse(this.junk.hasAnyListChangeListeners(Junk.STUFF_LIST)); - assertFalse(this.junkHolder2.hasAnyStateChangeListeners()); - } - - public void testListAdd() { - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addStateChangeListener(l); - this.junk.addStuff("bar"); - assertTrue(l.eventReceived()); - } - - public void testListRemove() { - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addStateChangeListener(l); - this.junk.removeStuff("foo"); - assertTrue(l.eventReceived()); - } - - public void testListReplace() { - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addStateChangeListener(l); - this.junk.replaceStuff("foo", "bar"); - assertTrue(l.eventReceived()); - } - - - class LocalListener extends ChangeAdapter { - private boolean eventReceived = false; - private final Object source; - private final Object oldValue; - private final Object newValue; - LocalListener(Object source) { - this(source, null, null); - } - LocalListener(Object source, Object oldValue, Object newValue) { - super(); - this.source = source; - this.oldValue = oldValue; - this.newValue = newValue; - } - @Override - public void propertyChanged(PropertyChangeEvent e) { - this.eventReceived = true; - assertEquals(this.source, e.getSource()); - assertEquals(this.oldValue, e.getOldValue()); - assertEquals(this.newValue, e.getNewValue()); - assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); - } - @Override - public void stateChanged(StateChangeEvent e) { - this.eventReceived = true; - assertEquals(this.source, e.getSource()); - } - boolean eventReceived() { - return this.eventReceived; - } - } - - private class Junk extends AbstractModel { - private List<String> stuff; - public static final String STUFF_LIST = "stuff"; - - public Junk(String stuffItem) { - this.stuff = new ArrayList<String>(); - this.stuff.add(stuffItem); - } - - public void addStuff(String stuffItem) { - this.addItemToList(stuffItem, this.stuff, STUFF_LIST); - } - - public void removeStuff(String stuffItem) { - this.removeItemFromList(stuffItem, this.stuff, STUFF_LIST); - } - - public void replaceStuff(String oldStuffItem, String newStuffItem) { - this.replaceItemInList(oldStuffItem, newStuffItem, this.stuff, STUFF_LIST); - } - - @Override - public String toString() { - return "Junk(" + this.stuff + ")"; - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValuePropertyAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValuePropertyAdapterTests.java deleted file mode 100644 index e3912484c5..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValuePropertyAdapterTests.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.ValuePropertyAdapter; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.event.StateChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ValuePropertyAdapterTests extends TestCase { - private Junk junk; - private SimplePropertyValueModel<Junk> junkHolder; - private ValuePropertyAdapter<Junk> junkHolder2; - - - public ValuePropertyAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.junk = new Junk("foo"); - this.junkHolder = new SimplePropertyValueModel<Junk>(this.junk); - this.junkHolder2 = new ValuePropertyAdapter<Junk>(this.junkHolder, Junk.NAME_PROPERTY); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testWrappedPVM() { - Junk junk2 = new Junk("bar"); - LocalListener l = new LocalListener(this.junkHolder2, this.junk, junk2); - this.junkHolder2.addChangeListener(l); - this.junkHolder.setValue(junk2); - assertTrue(l.eventReceived()); - } - - public void testHasPropertyChangeListeners() throws Exception { - assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addChangeListener(l); - assertTrue(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.junkHolder2.removeChangeListener(l); - assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - public void testHasStateChangeListeners() throws Exception { - assertFalse(this.junk.hasAnyPropertyChangeListeners(Junk.NAME_PROPERTY)); - assertFalse(this.junkHolder2.hasAnyStateChangeListeners()); - - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addStateChangeListener(l); - assertTrue(this.junk.hasAnyPropertyChangeListeners(Junk.NAME_PROPERTY)); - assertTrue(this.junkHolder2.hasAnyStateChangeListeners()); - - this.junkHolder2.removeStateChangeListener(l); - assertFalse(this.junk.hasAnyPropertyChangeListeners(Junk.NAME_PROPERTY)); - assertFalse(this.junkHolder2.hasAnyStateChangeListeners()); - } - - public void testChangeProperty() { - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addStateChangeListener(l); - this.junk.setName("bar"); - assertTrue(l.eventReceived()); - } - - - class LocalListener extends ChangeAdapter { - private boolean eventReceived = false; - private final Object source; - private final Object oldValue; - private final Object newValue; - LocalListener(Object source) { - this(source, null, null); - } - LocalListener(Object source, Object oldValue, Object newValue) { - super(); - this.source = source; - this.oldValue = oldValue; - this.newValue = newValue; - } - @Override - public void propertyChanged(PropertyChangeEvent e) { - this.eventReceived = true; - assertEquals(this.source, e.getSource()); - assertEquals(this.oldValue, e.getOldValue()); - assertEquals(this.newValue, e.getNewValue()); - assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); - } - @Override - public void stateChanged(StateChangeEvent e) { - this.eventReceived = true; - assertEquals(this.source, e.getSource()); - } - boolean eventReceived() { - return this.eventReceived; - } - } - - class Junk extends AbstractModel { - private String name; - public static final String NAME_PROPERTY = "name"; - - public Junk(String name) { - this.name = name; - } - - public void setName(String name) { - String old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - @Override - public String toString() { - return "Junk(" + this.name + ")"; - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueStateAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueStateAdapterTests.java deleted file mode 100644 index e0002e388a..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/ValueStateAdapterTests.java +++ /dev/null @@ -1,145 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.ValueStateAdapter; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.event.StateChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ValueStateAdapterTests extends TestCase { - private Junk junk; - private SimplePropertyValueModel<Junk> junkHolder; - private ValueStateAdapter<Junk> junkHolder2; - - - public ValueStateAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.junk = new Junk("foo"); - this.junkHolder = new SimplePropertyValueModel<Junk>(this.junk); - this.junkHolder2 = new ValueStateAdapter<Junk>(this.junkHolder); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testWrappedPVM() { - Junk junk2 = new Junk("bar"); - LocalListener l = new LocalListener(this.junkHolder2, this.junk, junk2); - this.junkHolder2.addChangeListener(l); - this.junkHolder.setValue(junk2); - assertTrue(l.eventReceived()); - } - - public void testHasPropertyChangeListeners() throws Exception { - assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addChangeListener(l); - assertTrue(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - this.junkHolder2.removeChangeListener(l); - assertFalse(this.junkHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertFalse(this.junkHolder2.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - public void testHasStateChangeListeners() throws Exception { - assertFalse(this.junk.hasAnyStateChangeListeners()); - assertFalse(this.junkHolder2.hasAnyStateChangeListeners()); - - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addStateChangeListener(l); - assertTrue(this.junk.hasAnyStateChangeListeners()); - assertTrue(this.junkHolder2.hasAnyStateChangeListeners()); - - this.junkHolder2.removeStateChangeListener(l); - assertFalse(this.junk.hasAnyStateChangeListeners()); - assertFalse(this.junkHolder2.hasAnyStateChangeListeners()); - } - - public void testChangeState() { - LocalListener l = new LocalListener(this.junkHolder2, null, this.junk); - this.junkHolder2.addChangeListener(l); - this.junkHolder2.addStateChangeListener(l); - this.junk.setName("bar"); - assertTrue(l.eventReceived()); - } - - - class LocalListener extends ChangeAdapter { - private boolean eventReceived = false; - private final Object source; - private final Object oldValue; - private final Object newValue; - LocalListener(Object source) { - this(source, null, null); - } - LocalListener(Object source, Object oldValue, Object newValue) { - super(); - this.source = source; - this.oldValue = oldValue; - this.newValue = newValue; - } - @Override - public void propertyChanged(PropertyChangeEvent e) { - this.eventReceived = true; - assertEquals(this.source, e.getSource()); - assertEquals(this.oldValue, e.getOldValue()); - assertEquals(this.newValue, e.getNewValue()); - assertEquals(PropertyValueModel.VALUE, e.getPropertyName()); - } - @Override - public void stateChanged(StateChangeEvent e) { - this.eventReceived = true; - assertEquals(this.source, e.getSource()); - } - boolean eventReceived() { - return this.eventReceived; - } - } - - class Junk extends AbstractModel { - private String name; - public static final String NAME_PROPERTY = "name"; - - public Junk(String name) { - this.name = name; - } - - public void setName(String name) { - this.name = name; - this.fireStateChanged(); - } - - @Override - public String toString() { - return "Junk(" + this.name + ")"; - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/JptUtilityModelValuePrefsTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/JptUtilityModelValuePrefsTests.java deleted file mode 100644 index 043da07fbf..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/JptUtilityModelValuePrefsTests.java +++ /dev/null @@ -1,31 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.prefs; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptUtilityModelValuePrefsTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptUtilityModelValuePrefsTests.class.getPackage().getName()); - - suite.addTestSuite(PreferencesCollectionValueModelTests.class); - suite.addTestSuite(PreferencePropertyValueModelTests.class); - - return suite; - } - - private JptUtilityModelValuePrefsTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java deleted file mode 100644 index 49aab95fc0..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencePropertyValueModelTests.java +++ /dev/null @@ -1,398 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.prefs; - -import java.util.prefs.NodeChangeEvent; -import java.util.prefs.NodeChangeListener; -import java.util.prefs.PreferenceChangeEvent; -import java.util.prefs.PreferenceChangeListener; -import java.util.prefs.Preferences; - -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.prefs.PreferencePropertyValueModel; -import org.eclipse.jpt.utility.model.Model; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -@SuppressWarnings("nls") -public class PreferencePropertyValueModelTests extends PreferencesTestCase { - private WritablePropertyValueModel<Preferences> nodeHolder; - PreferencePropertyValueModel<String> preferenceAdapter; - PropertyChangeEvent event; - PropertyChangeListener listener; - boolean listenerRemoved = false; - PreferenceChangeEvent preferenceEvent; - private static final String KEY_NAME = "foo"; - private static final String STRING_VALUE = "original string value"; - - public PreferencePropertyValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.testNode.put(KEY_NAME, STRING_VALUE); - - this.nodeHolder = new SimplePropertyValueModel<Preferences>(this.testNode); - this.preferenceAdapter = new PreferencePropertyValueModel<String>(this.nodeHolder, KEY_NAME); - this.listener = this.buildValueChangeListener(); - this.preferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener); - this.event = null; - } - - @Override - protected void tearDown() throws Exception { - super.tearDown(); - } - - private PropertyChangeListener buildValueChangeListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - if (PreferencePropertyValueModelTests.this.event != null) { - throw new IllegalStateException("unexpected this.event: " + e); - } - PreferencePropertyValueModelTests.this.event = e; - } - }; - } - - public void testSubjectHolder() throws Exception { - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - assertNull(this.event); - - String ANOTHER_STRING_VALUE = "some other value"; - Preferences anotherNode = this.classNode.node("another test node"); - anotherNode.put(KEY_NAME, ANOTHER_STRING_VALUE); - - this.nodeHolder.setValue(anotherNode); - this.verifyEvent(STRING_VALUE, ANOTHER_STRING_VALUE); - assertEquals(ANOTHER_STRING_VALUE, this.preferenceAdapter.getValue()); - - this.event = null; - this.nodeHolder.setValue(null); - this.verifyEvent(ANOTHER_STRING_VALUE, null); - assertNull(this.preferenceAdapter.getValue()); - - this.event = null; - this.nodeHolder.setValue(this.testNode); - this.verifyEvent(null, STRING_VALUE); - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - } - - public void testPreferenceChange() throws Exception { - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - assertNull(this.event); - - this.testNode.put(KEY_NAME, STRING_VALUE + STRING_VALUE); - this.waitForEventQueueToClear(); - this.verifyEvent(STRING_VALUE, STRING_VALUE + STRING_VALUE); - assertEquals(STRING_VALUE + STRING_VALUE, this.preferenceAdapter.getValue()); - - this.event = null; - this.testNode.remove(KEY_NAME); - this.waitForEventQueueToClear(); - this.verifyEvent(STRING_VALUE + STRING_VALUE, null); - assertNull(this.preferenceAdapter.getValue()); - - this.event = null; - this.testNode.put(KEY_NAME, STRING_VALUE); - this.waitForEventQueueToClear(); - this.verifyEvent(null, STRING_VALUE); - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - } - - public void testValue() throws Exception { - assertEquals(STRING_VALUE, this.testNode.get(KEY_NAME, "<missing preference>")); - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - } - - public void testSetValue() throws Exception { - String ANOTHER_STRING_VALUE = "some other value"; - this.preferenceAdapter.setValue(ANOTHER_STRING_VALUE); - assertEquals(ANOTHER_STRING_VALUE, this.preferenceAdapter.getValue()); - assertEquals(ANOTHER_STRING_VALUE, this.testNode.get(KEY_NAME, "<missing preference>")); - } - - public void testHasListeners() throws Exception { - assertTrue(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(this.nodeHasAnyPrefListeners(this.testNode)); - this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener); - assertFalse(this.nodeHasAnyPrefListeners(this.testNode)); - assertFalse(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - ChangeListener listener2 = this.buildChangeListener(); - this.preferenceAdapter.addChangeListener(listener2); - assertTrue(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - assertTrue(this.nodeHasAnyPrefListeners(this.testNode)); - this.preferenceAdapter.removeChangeListener(listener2); - assertFalse(this.nodeHasAnyPrefListeners(this.testNode)); - assertFalse(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - private ChangeListener buildChangeListener() { - return new ChangeAdapter() { - @Override - public void propertyChanged(PropertyChangeEvent e) { - if (PreferencePropertyValueModelTests.this.event != null) { - throw new IllegalStateException("unexpected this.event: " + e); - } - PreferencePropertyValueModelTests.this.event = e; - } - }; - } - - public void testRemoveAndReAddPreference() throws Exception { - assertEquals(STRING_VALUE, this.testNode.get(KEY_NAME, null)); - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - assertNull(this.event); - - // remove the preference entirely... - this.testNode.remove(KEY_NAME); - this.waitForEventQueueToClear(); - assertNull(this.testNode.get(KEY_NAME, null)); - this.verifyEvent(STRING_VALUE, null); - assertNull(this.preferenceAdapter.getValue()); - - // ...then re-add it with the same key - this.event = null; - this.testNode.put(KEY_NAME, STRING_VALUE); - this.waitForEventQueueToClear(); - assertEquals(STRING_VALUE, this.testNode.get(KEY_NAME, null)); - this.verifyEvent(null, STRING_VALUE); - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - } - - public void testDefaultValue() throws Exception { - // rebuild the adapter with a default value - String DEFAULT_VALUE = "default value"; - this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener); - this.preferenceAdapter = new PreferencePropertyValueModel<String>(this.nodeHolder, KEY_NAME, DEFAULT_VALUE); - this.preferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener); - - assertEquals(STRING_VALUE, this.testNode.get(KEY_NAME, null)); - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - assertNull(this.event); - - // remove the preference entirely... - this.testNode.remove(KEY_NAME); - this.waitForEventQueueToClear(); - assertNull(this.testNode.get(KEY_NAME, null)); - this.verifyEvent(STRING_VALUE, DEFAULT_VALUE); - assertEquals(DEFAULT_VALUE, this.preferenceAdapter.getValue()); - - // ...then re-add it with the same key - this.event = null; - this.testNode.put(KEY_NAME, STRING_VALUE); - this.waitForEventQueueToClear(); - assertEquals(STRING_VALUE, this.testNode.get(KEY_NAME, null)); - this.verifyEvent(DEFAULT_VALUE, STRING_VALUE); - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - } - - public void testUnsynchronizedValue() throws Exception { - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - assertNull(this.event); - - // remove the this.listener so the adapter no longer listens to the preference - this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener); - - this.testNode.put(KEY_NAME, STRING_VALUE + STRING_VALUE); - this.waitForEventQueueToClear(); - // no this.event should have been fired... - assertNull(this.event); - // ...and the adapter's value should be null - assertNull(this.preferenceAdapter.getValue()); - - this.testNode.remove(KEY_NAME); - this.waitForEventQueueToClear(); - assertNull(this.event); - assertNull(this.preferenceAdapter.getValue()); - - this.testNode.put(KEY_NAME, STRING_VALUE); - this.waitForEventQueueToClear(); - assertNull(this.event); - assertNull(this.preferenceAdapter.getValue()); - - // add the this.listener so the adapter synchs - this.preferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener); - assertEquals(STRING_VALUE, this.preferenceAdapter.getValue()); - } - - public void testIntegerPreference() throws Exception { - // stop listening to the node and convert it to an integer - this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener); - - PreferencePropertyValueModel<Integer> integerPreferenceAdapter = new PreferencePropertyValueModel<Integer>(this.nodeHolder, KEY_NAME); - this.testNode.putInt(KEY_NAME, 123); - integerPreferenceAdapter = PreferencePropertyValueModel.forInteger(this.testNode, KEY_NAME, 0); - integerPreferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener); - assertEquals(new Integer(123), integerPreferenceAdapter.getValue()); - assertNull(this.event); - - this.testNode.putInt(KEY_NAME, 246); - this.waitForEventQueueToClear(); - this.verifyEvent(integerPreferenceAdapter, new Integer(123), new Integer(246)); - assertEquals(new Integer(246), integerPreferenceAdapter.getValue()); - - this.event = null; - this.testNode.remove(KEY_NAME); - this.waitForEventQueueToClear(); - this.verifyEvent(integerPreferenceAdapter, new Integer(246), new Integer(0)); - assertEquals(new Integer(0), integerPreferenceAdapter.getValue()); - - this.event = null; - this.testNode.putInt(KEY_NAME, 123); - this.waitForEventQueueToClear(); - this.verifyEvent(integerPreferenceAdapter, new Integer(0), new Integer(123)); - assertEquals(new Integer(123), integerPreferenceAdapter.getValue()); - } - - /** - * test a situation where - * - we are listening to the node when it gets removed from the preferences "repository" - * - we get notification that it has been removed - * - we try to remove our this.listener - * - the node will throw an IllegalStateException - the adapter should handle it OK... - */ - public void testRemoveNode() throws Exception { - assertTrue(this.preferenceAdapter.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - Preferences parent = this.testNode.parent(); - parent.addNodeChangeListener(this.buildParentNodeChangeListener()); - this.testNode.removeNode(); - this.testNode.flush(); // this seems to be required for the this.event to trigger... - this.waitForEventQueueToClear(); - - assertTrue(this.listenerRemoved); - assertTrue(this.preferenceAdapter.hasNoPropertyChangeListeners(PropertyValueModel.VALUE)); - } - - private NodeChangeListener buildParentNodeChangeListener() { - return new NodeChangeListener() { - public void childAdded(NodeChangeEvent e) { - throw new IllegalStateException("unexpected this.event: " + e); - } - public void childRemoved(NodeChangeEvent e) { - if (e.getChild() == PreferencePropertyValueModelTests.this.testNode) { - PreferencePropertyValueModelTests.this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, PreferencePropertyValueModelTests.this.listener); - // this line of code will not execute if the line above triggers an exception - PreferencePropertyValueModelTests.this.listenerRemoved = true; - } - } - }; - } - - public void testSetSameValue() { - assertNull(this.event); - assertNull(this.preferenceEvent); - this.testNode.addPreferenceChangeListener(this.buildPreferenceChangeListener()); - - String ANOTHER_STRING_VALUE = "some other value"; - this.preferenceAdapter.setValue(ANOTHER_STRING_VALUE); - - this.verifyEvent(STRING_VALUE, ANOTHER_STRING_VALUE); - this.waitForEventQueueToClear(); - this.verifyPreferenceEvent(ANOTHER_STRING_VALUE); - - // now set to *same* value - nothing should happen... - this.event = null; - this.preferenceEvent = null; - this.preferenceAdapter.setValue(ANOTHER_STRING_VALUE); - - assertNull(this.event); - assertNull(this.preferenceEvent); - } - - public void testSetSameValueForcePassThrough() throws Exception { - assertNull(this.event); - assertNull(this.preferenceEvent); - - this.preferenceAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.listener); - this.preferenceAdapter = new AlwaysUpdatePreferencePropertyValueModel<String>(this.nodeHolder, KEY_NAME); - this.preferenceAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.listener); - - this.testNode.addPreferenceChangeListener(this.buildPreferenceChangeListener()); - - String ANOTHER_STRING_VALUE = "some other value"; - this.preferenceAdapter.setValue(ANOTHER_STRING_VALUE); - - this.verifyEvent(STRING_VALUE, ANOTHER_STRING_VALUE); - this.waitForEventQueueToClear(); - this.verifyPreferenceEvent(ANOTHER_STRING_VALUE); - - // now set to *same* value - only one this.event should fire - this.event = null; - this.preferenceEvent = null; - this.preferenceAdapter.setValue(ANOTHER_STRING_VALUE); - - assertNull(this.event); - this.waitForEventQueueToClear(); - this.verifyPreferenceEvent(ANOTHER_STRING_VALUE); - assertNull(this.event); - } - - private PreferenceChangeListener buildPreferenceChangeListener() { - return new PreferenceChangeListener() { - public void preferenceChange(PreferenceChangeEvent evt) { - PreferencePropertyValueModelTests.this.preferenceEvent = evt; - } - }; - } - - private void verifyEvent(Model source, Object oldValue, Object newValue) { - assertNotNull(this.event); - assertEquals(source, this.event.getSource()); - assertEquals(PropertyValueModel.VALUE, this.event.getPropertyName()); - assertEquals(oldValue, this.event.getOldValue()); - assertEquals(newValue, this.event.getNewValue()); - } - - private void verifyEvent(Object oldValue, Object newValue) { - this.verifyEvent(this.preferenceAdapter, oldValue, newValue); - } - - private void verifyPreferenceEvent(Object newValue) { - assertNotNull(this.preferenceEvent); - assertEquals(this.testNode, this.preferenceEvent.getSource()); - assertEquals(KEY_NAME, this.preferenceEvent.getKey()); - assertEquals(newValue, this.preferenceEvent.getNewValue()); - assertEquals(newValue, this.testNode.get(KEY_NAME, "<missing preference>")); - } - - private boolean nodeHasAnyPrefListeners(Preferences node) throws Exception { - PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ClassTools.fieldValue(node, "prefListeners"); - return prefListeners.length > 0; - } - - - /** - * Use this adapter to test out always passing through the new value - * to the preference. - */ - private class AlwaysUpdatePreferencePropertyValueModel<P> extends PreferencePropertyValueModel<P> { - - AlwaysUpdatePreferencePropertyValueModel(PropertyValueModel<Preferences> preferencesHolder, String key) { - super(preferencesHolder, key); - } - - @Override - protected boolean shouldSetPreference(Object oldValue, Object newValue) { - return true; - } - - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java deleted file mode 100644 index c57af46fb6..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesCollectionValueModelTests.java +++ /dev/null @@ -1,312 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.prefs; - -import java.util.HashMap; -import java.util.Map; -import java.util.prefs.NodeChangeEvent; -import java.util.prefs.NodeChangeListener; -import java.util.prefs.PreferenceChangeListener; -import java.util.prefs.Preferences; - -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.prefs.PreferencePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.prefs.PreferencesCollectionValueModel; -import org.eclipse.jpt.utility.model.event.CollectionAddEvent; -import org.eclipse.jpt.utility.model.event.CollectionChangeEvent; -import org.eclipse.jpt.utility.model.event.CollectionClearEvent; -import org.eclipse.jpt.utility.model.event.CollectionEvent; -import org.eclipse.jpt.utility.model.event.CollectionRemoveEvent; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ChangeAdapter; -import org.eclipse.jpt.utility.model.listener.ChangeListener; -import org.eclipse.jpt.utility.model.listener.CollectionChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -@SuppressWarnings("nls") -public class PreferencesCollectionValueModelTests extends PreferencesTestCase { - private Map<String, String> expectedValues; - private WritablePropertyValueModel<Preferences> nodeHolder; - PreferencesCollectionValueModel<String> preferencesAdapter; - CollectionEvent event; - CollectionChangeListener listener; - private PropertyChangeListener itemListener; - boolean listenerRemoved = false; - private static final String KEY_NAME_1 = "foo 1"; - private static final String KEY_NAME_2 = "foo 2"; - private static final String KEY_NAME_3 = "foo 3"; - private static final String STRING_VALUE_1 = "original string value 1"; - private static final String STRING_VALUE_2 = "original string value 2"; - private static final String STRING_VALUE_3 = "original string value 3"; - - public PreferencesCollectionValueModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.expectedValues = new HashMap<String, String>(); - this.testNode.put(KEY_NAME_1, STRING_VALUE_1); this.expectedValues.put(KEY_NAME_1, STRING_VALUE_1); - this.testNode.put(KEY_NAME_2, STRING_VALUE_2); this.expectedValues.put(KEY_NAME_2, STRING_VALUE_2); - this.testNode.put(KEY_NAME_3, STRING_VALUE_3); this.expectedValues.put(KEY_NAME_3, STRING_VALUE_3); - - this.nodeHolder = new SimplePropertyValueModel<Preferences>(this.testNode); - this.preferencesAdapter = new PreferencesCollectionValueModel<String>(this.nodeHolder); - this.listener = this.buildCollectionChangeListener(); - this.itemListener = this.buildItemListener(); - this.preferencesAdapter.addCollectionChangeListener(CollectionValueModel.VALUES, this.listener); - this.event = null; - } - - private CollectionChangeListener buildCollectionChangeListener() { - return new CollectionChangeListener() { - public void collectionChanged(CollectionChangeEvent e) { - this.logEvent(e); - } - public void collectionCleared(CollectionClearEvent e) { - this.logEvent(e); - } - public void itemsAdded(CollectionAddEvent e) { - this.logEvent(e); - } - public void itemsRemoved(CollectionRemoveEvent e) { - this.logEvent(e); - } - private void logEvent(CollectionEvent e) { - if (PreferencesCollectionValueModelTests.this.event != null) { - throw new IllegalStateException("unexpected this.event: " + e); - } - PreferencesCollectionValueModelTests.this.event = e; - } - }; - } - - private PropertyChangeListener buildItemListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - throw new IllegalStateException("unexpected this.event: " + e); - } - }; - } - - public void testSubjectHolder() throws Exception { - this.verifyAdapter(this.preferencesAdapter); - assertNull(this.event); - - String ANOTHER_KEY_NAME_1 = "another key 1"; - String ANOTHER_KEY_NAME_2 = "another key 2"; - String ANOTHER_KEY_NAME_3 = "another key 3"; - String ANOTHER_STRING_VALUE_1 = "another string value 1"; - String ANOTHER_STRING_VALUE_2 = "another string value 2"; - String ANOTHER_STRING_VALUE_3 = "another string value 3"; - Preferences anotherNode = this.classNode.node("another test node"); - this.expectedValues.clear(); - anotherNode.put(ANOTHER_KEY_NAME_1, ANOTHER_STRING_VALUE_1); this.expectedValues.put(ANOTHER_KEY_NAME_1, ANOTHER_STRING_VALUE_1); - anotherNode.put(ANOTHER_KEY_NAME_2, ANOTHER_STRING_VALUE_2); this.expectedValues.put(ANOTHER_KEY_NAME_2, ANOTHER_STRING_VALUE_2); - anotherNode.put(ANOTHER_KEY_NAME_3, ANOTHER_STRING_VALUE_3); this.expectedValues.put(ANOTHER_KEY_NAME_3, ANOTHER_STRING_VALUE_3); - - this.nodeHolder.setValue(anotherNode); - // collectionChanged does not pass any items in the this.event - this.verifyEvent(); - this.verifyAdapter(this.preferencesAdapter); - - this.event = null; - this.expectedValues.clear(); - this.nodeHolder.setValue(null); - this.verifyEvent(); - assertFalse(this.preferencesAdapter.iterator().hasNext()); - - this.event = null; - this.nodeHolder.setValue(this.testNode); - this.verifyEvent(); - this.expectedValues.clear(); - this.expectedValues.put(KEY_NAME_1, STRING_VALUE_1); - this.expectedValues.put(KEY_NAME_2, STRING_VALUE_2); - this.expectedValues.put(KEY_NAME_3, STRING_VALUE_3); - this.verifyAdapter(this.preferencesAdapter); - } - - public void testAddPreference() throws Exception { - this.verifyAdapter(this.preferencesAdapter); - assertNull(this.event); - - String ANOTHER_KEY_NAME = "another key"; - String ANOTHER_STRING_VALUE = "another string value"; - this.testNode.put(ANOTHER_KEY_NAME, ANOTHER_STRING_VALUE); - this.waitForEventQueueToClear(); - Map<String, String> expectedItems = new HashMap<String, String>(); - expectedItems.put(ANOTHER_KEY_NAME, ANOTHER_STRING_VALUE); - this.verifyEvent(expectedItems); - this.expectedValues.put(ANOTHER_KEY_NAME, ANOTHER_STRING_VALUE); - this.verifyAdapter(this.preferencesAdapter); - } - - public void testRemovePreference() throws Exception { - this.verifyAdapter(this.preferencesAdapter); - assertNull(this.event); - - this.testNode.remove(KEY_NAME_2); - this.waitForEventQueueToClear(); - - assertNotNull(this.event); - assertEquals(this.preferencesAdapter, this.event.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event.getCollectionName()); - assertEquals(1, ((CollectionRemoveEvent) this.event).getItemsSize()); - @SuppressWarnings("unchecked") - String key = ((PreferencePropertyValueModel<String>) ((CollectionRemoveEvent) this.event).getItems().iterator().next()).getKey(); - assertEquals(KEY_NAME_2, key); - - this.expectedValues.remove(KEY_NAME_2); - this.verifyAdapter(this.preferencesAdapter); - } - - public void testChangePreference() throws Exception { - this.verifyAdapter(this.preferencesAdapter); - assertNull(this.event); - - String DIFFERENT = "something completely different"; - this.testNode.put(KEY_NAME_2, DIFFERENT); - this.waitForEventQueueToClear(); - - assertNull(this.event); - - this.expectedValues.put(KEY_NAME_2, DIFFERENT); - this.verifyAdapter(this.preferencesAdapter); - } - - public void testValues() throws Exception { - this.verifyNode(this.testNode); - this.verifyAdapter(this.preferencesAdapter); - } - - /** - * test a situation where - * - we are listening to the node when it gets removed from the preferences "repository" - * - we get notification that it has been removed - * - we try to remove our this.listener - * - the node will throw an IllegalStateException - the adapter should handle it OK... - */ - public void testRemoveNode() throws Exception { - assertTrue(this.preferencesAdapter.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - - Preferences parent = this.testNode.parent(); - parent.addNodeChangeListener(this.buildParentNodeChangeListener()); - this.testNode.removeNode(); - this.testNode.flush(); // this seems to be required for the this.event to trigger... - this.waitForEventQueueToClear(); - - assertTrue(this.listenerRemoved); - assertFalse(this.preferencesAdapter.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - } - - private NodeChangeListener buildParentNodeChangeListener() { - return new NodeChangeListener() { - public void childAdded(NodeChangeEvent e) { - throw new IllegalStateException("unexpected this.event: " + e); - } - public void childRemoved(NodeChangeEvent e) { - if (e.getChild() == PreferencesCollectionValueModelTests.this.testNode) { - PreferencesCollectionValueModelTests.this.preferencesAdapter.removeCollectionChangeListener(CollectionValueModel.VALUES, PreferencesCollectionValueModelTests.this.listener); - // this line of code will not execute if the line above triggers an exception - PreferencesCollectionValueModelTests.this.listenerRemoved = true; - } - } - }; - } - - public void testHasListeners() throws Exception { - assertTrue(this.preferencesAdapter.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - assertTrue(this.nodeHasAnyPrefListeners(this.testNode)); - this.preferencesAdapter.removeCollectionChangeListener(CollectionValueModel.VALUES, this.listener); - assertFalse(this.nodeHasAnyPrefListeners(this.testNode)); - assertFalse(this.preferencesAdapter.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - - ChangeListener listener2 = this.buildChangeListener(); - this.preferencesAdapter.addChangeListener(listener2); - assertTrue(this.preferencesAdapter.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - assertTrue(this.nodeHasAnyPrefListeners(this.testNode)); - this.preferencesAdapter.removeChangeListener(listener2); - assertFalse(this.nodeHasAnyPrefListeners(this.testNode)); - assertFalse(this.preferencesAdapter.hasAnyCollectionChangeListeners(CollectionValueModel.VALUES)); - } - - private ChangeListener buildChangeListener() { - return new ChangeAdapter() { - @Override - public void collectionChanged(CollectionChangeEvent e) { - this.logEvent(e); - } - @Override - public void collectionCleared(CollectionClearEvent e) { - this.logEvent(e); - } - @Override - public void itemsAdded(CollectionAddEvent e) { - this.logEvent(e); - } - @Override - public void itemsRemoved(CollectionRemoveEvent e) { - this.logEvent(e); - } - private void logEvent(CollectionEvent e) { - if (PreferencesCollectionValueModelTests.this.event != null) { - throw new IllegalStateException("unexpected this.event: " + e); - } - PreferencesCollectionValueModelTests.this.event = e; - } - }; - } - - private void verifyEvent(Map<String, String> items) { - this.verifyEvent(); - assertEquals(items.size(), ((CollectionAddEvent) this.event).getItemsSize()); - @SuppressWarnings("unchecked") - Iterable<PreferencePropertyValueModel<String>> eventItems = (Iterable<PreferencePropertyValueModel<String>>) ((CollectionAddEvent) this.event).getItems(); - this.verifyItems(items, eventItems); - } - - private void verifyEvent() { - assertNotNull(this.event); - assertEquals(this.preferencesAdapter, this.event.getSource()); - assertEquals(CollectionValueModel.VALUES, this.event.getCollectionName()); - } - - private void verifyNode(Preferences node) throws Exception { - String[] keys = node.keys(); - assertEquals(this.expectedValues.size(), keys.length); - for (int i = 0; i < keys.length; i++) { - assertEquals(this.expectedValues.get(keys[i]), node.get(keys[i], "<missing preference>")); - } - } - - private void verifyAdapter(PreferencesCollectionValueModel<String> cvm) { - assertEquals(this.expectedValues.size(), cvm.size()); - this.verifyItems(this.expectedValues, cvm); - } - - private void verifyItems(Map<String, String> expected, Iterable<PreferencePropertyValueModel<String>> actual) { - for (PreferencePropertyValueModel<String> model : actual) { - model.addPropertyChangeListener(PropertyValueModel.VALUE, this.itemListener); - assertEquals(expected.get(model.getKey()), model.getValue()); - model.removePropertyChangeListener(PropertyValueModel.VALUE, this.itemListener); - } - } - - private boolean nodeHasAnyPrefListeners(Preferences node) throws Exception { - PreferenceChangeListener[] prefListeners = (PreferenceChangeListener[]) ClassTools.fieldValue(node, "prefListeners"); - return prefListeners.length > 0; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java deleted file mode 100644 index ce4c304a6e..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/prefs/PreferencesTestCase.java +++ /dev/null @@ -1,85 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.prefs; - -import java.util.EventObject; -import java.util.List; -import java.util.prefs.AbstractPreferences; -import java.util.prefs.Preferences; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -/** - * set up and tear down a test node for any subclass that - * needs to test preferences-related stuff - */ -public abstract class PreferencesTestCase extends TestCase { - protected Preferences classNode; - public Preferences testNode; - protected static final String TEST_NODE_NAME = "test node"; - - public PreferencesTestCase(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - Preferences packageNode = Preferences.userNodeForPackage(this.getClass()); - this.classNode = packageNode.node(ClassTools.shortClassNameForObject(this)); - // clean out any leftover crap... - if ((this.classNode.keys().length > 0) || (this.classNode.childrenNames().length > 0)) { - this.classNode.removeNode(); - // ...and re-create the node - this.classNode = packageNode.node(ClassTools.shortClassNameForObject(this)); - } - this.testNode = this.classNode.node(TEST_NODE_NAME); - } - - @Override - protected void tearDown() throws Exception { - // wait for all the events to be delivered before tearing down - this.waitForEventQueueToClear(); - Preferences node = this.classNode.parent(); - this.classNode.removeNode(); - while (this.nodeIsVestigial(node)) { - Preferences parent = node.parent(); - node.removeNode(); - node = parent; - } - TestTools.clear(this); - super.tearDown(); - } - - private boolean nodeIsVestigial(Preferences node) throws Exception { - return (node != null) - && (node.keys().length == 0) - && (node.childrenNames().length == 0) - && (node != Preferences.userRoot()); - } - - protected void waitForEventQueueToClear() { - try { - while ( ! this.preferencesEventQueue().isEmpty()) { - Thread.sleep(100); - } - Thread.sleep(100); - } catch (InterruptedException ex) { - throw new RuntimeException(ex); - } - } - - @SuppressWarnings("unchecked") - private List<EventObject> preferencesEventQueue() { - return (List<EventObject>) ClassTools.staticFieldValue(AbstractPreferences.class, "eventQueue"); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java deleted file mode 100644 index 4302458d3d..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterTests.java +++ /dev/null @@ -1,134 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import javax.swing.ButtonModel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.event.EventListenerList; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.CheckBoxModelAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class CheckBoxModelAdapterTests extends TestCase { - private WritablePropertyValueModel<Boolean> booleanHolder; - private ButtonModel buttonModelAdapter; - boolean eventFired; - - public CheckBoxModelAdapterTests(String name) { - super(name); - } - - @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_(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSetSelected() throws Exception { - this.eventFired = false; - this.buttonModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - CheckBoxModelAdapterTests.this.eventFired = true; - } - }); - this.buttonModelAdapter.setSelected(false); - assertTrue(this.eventFired); - assertEquals(Boolean.FALSE, this.booleanHolder.getValue()); - } - - public void testSetValue() throws Exception { - this.eventFired = false; - this.buttonModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - CheckBoxModelAdapterTests.this.eventFired = true; - } - }); - assertTrue(this.buttonModelAdapter.isSelected()); - this.booleanHolder.setValue(Boolean.FALSE); - assertTrue(this.eventFired); - assertFalse(this.buttonModelAdapter.isSelected()); - } - - public void testDefaultValue() throws Exception { - this.eventFired = false; - this.buttonModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - CheckBoxModelAdapterTests.this.eventFired = true; - } - }); - assertTrue(this.buttonModelAdapter.isSelected()); - this.booleanHolder.setValue(null); - assertTrue(this.eventFired); - assertFalse(this.buttonModelAdapter.isSelected()); - - this.eventFired = false; - this.booleanHolder.setValue(Boolean.FALSE); - assertFalse(this.eventFired); - assertFalse(this.buttonModelAdapter.isSelected()); - } - - public void testHasListeners() throws Exception { - SimplePropertyValueModel<Boolean> localBooleanHolder = (SimplePropertyValueModel<Boolean>) this.booleanHolder; - assertFalse(localBooleanHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.buttonModelAdapter); - - ChangeListener listener = new TestChangeListener(); - this.buttonModelAdapter.addChangeListener(listener); - assertTrue(localBooleanHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasListeners(this.buttonModelAdapter); - - this.buttonModelAdapter.removeChangeListener(listener); - assertFalse(localBooleanHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.buttonModelAdapter); - } - - private void verifyHasNoListeners(Object model) throws Exception { - EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList"); - assertEquals(0, listenerList.getListenerList().length); - } - - private void verifyHasListeners(Object model) throws Exception { - EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList"); - assertFalse(listenerList.getListenerList().length == 0); - } - - - // ********** member class ********** - private class TestChangeListener implements ChangeListener { - TestChangeListener() { - super(); - } - public void stateChanged(ChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java deleted file mode 100644 index c3bc373dc7..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/CheckBoxModelAdapterUITest.java +++ /dev/null @@ -1,313 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ButtonModel; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.WindowConstants; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.CheckBoxModelAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * Play around with a set of check boxes. - */ -public class CheckBoxModelAdapterUITest { - - private TestModel testModel; - private WritablePropertyValueModel<TestModel> testModelHolder; - private WritablePropertyValueModel<Boolean> flag1Holder; - private WritablePropertyValueModel<Boolean> flag2Holder; - private WritablePropertyValueModel<Boolean> notFlag2Holder; - private ButtonModel flag1ButtonModel; - private ButtonModel flag2ButtonModel; - private ButtonModel notFlag2ButtonModel; - - public static void main(String[] args) throws Exception { - new CheckBoxModelAdapterUITest().exec(args); - } - - private CheckBoxModelAdapterUITest() { - super(); - } - - private void exec(String[] args) throws Exception { - this.testModel = new TestModel(true, true); - this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel); - this.flag1Holder = this.buildFlag1Holder(this.testModelHolder); - this.flag1ButtonModel = this.buildCheckBoxModelAdapter(this.flag1Holder); - this.flag2Holder = this.buildFlag2Holder(this.testModelHolder); - this.flag2ButtonModel = this.buildCheckBoxModelAdapter(this.flag2Holder); - this.notFlag2Holder = this.buildNotFlag2Holder(this.testModelHolder); - this.notFlag2ButtonModel = this.buildCheckBoxModelAdapter(this.notFlag2Holder); - this.openWindow(); - } - - private WritablePropertyValueModel<Boolean> buildFlag1Holder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, Boolean>(vm, TestModel.FLAG1_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isFlag1()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setFlag1(value.booleanValue()); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildFlag2Holder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, Boolean>(vm, TestModel.FLAG2_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isFlag2()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setFlag2(value.booleanValue()); - } - }; - } - - private WritablePropertyValueModel<Boolean> buildNotFlag2Holder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, Boolean>(vm, TestModel.NOT_FLAG2_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isNotFlag2()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setNotFlag2(value.booleanValue()); - } - }; - } - - private ButtonModel buildCheckBoxModelAdapter(WritablePropertyValueModel<Boolean> booleanHolder) { - return new CheckBoxModelAdapter(booleanHolder); - } - - private void openWindow() { - JFrame window = new JFrame(this.getClass().getName()); - window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - window.addWindowListener(this.buildWindowListener()); - window.getContentPane().add(this.buildMainPanel(), "Center"); - window.setSize(400, 100); - window.setVisible(true); - } - - private WindowListener buildWindowListener() { - return new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - System.exit(0); - } - }; - } - - private Component buildMainPanel() { - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(this.buildCheckBoxPanel(), BorderLayout.NORTH); - mainPanel.add(this.buildControlPanel(), BorderLayout.SOUTH); - return mainPanel; - } - - private Component buildCheckBoxPanel() { - JPanel taskListPanel = new JPanel(new GridLayout(1, 0)); - taskListPanel.add(this.buildFlag1CheckBox()); - taskListPanel.add(this.buildFlag2CheckBox()); - taskListPanel.add(this.buildNotFlag2CheckBox()); - taskListPanel.add(this.buildUnattachedCheckBox()); - return taskListPanel; - } - - private JCheckBox buildFlag1CheckBox() { - JCheckBox checkBox = new JCheckBox(); - checkBox.setText("flag 1"); - checkBox.setModel(this.flag1ButtonModel); - return checkBox; - } - - private JCheckBox buildFlag2CheckBox() { - JCheckBox checkBox = new JCheckBox(); - checkBox.setText("flag 2"); - checkBox.setModel(this.flag2ButtonModel); - return checkBox; - } - - private JCheckBox buildNotFlag2CheckBox() { - JCheckBox checkBox = new JCheckBox(); - checkBox.setText("not flag 2"); - checkBox.setModel(this.notFlag2ButtonModel); - return checkBox; - } - - private JCheckBox buildUnattachedCheckBox() { - JCheckBox checkBox = new JCheckBox("unattached"); - checkBox.getModel().addItemListener(this.buildUnattachedItemListener()); - return checkBox; - } - - private ItemListener buildUnattachedItemListener() { - return new ItemListener() { - public void itemStateChanged(ItemEvent e) { - System.out.println("unattached state changed: " + e); - } - }; - } - - private Component buildControlPanel() { - JPanel controlPanel = new JPanel(new GridLayout(1, 0)); - controlPanel.add(this.buildFlipFlag1Button()); - controlPanel.add(this.buildClearModelButton()); - controlPanel.add(this.buildRestoreModelButton()); - controlPanel.add(this.buildPrintModelButton()); - return controlPanel; - } - - private JButton buildFlipFlag1Button() { - return new JButton(this.buildFlipFlag1Action()); - } - - private Action buildFlipFlag1Action() { - Action action = new AbstractAction("flip flag 1") { - public void actionPerformed(ActionEvent event) { - CheckBoxModelAdapterUITest.this.flipFlag1(); - } - }; - action.setEnabled(true); - return action; - } - - void flipFlag1() { - this.testModel.setFlag1( ! this.testModel.isFlag1()); - } - - private JButton buildClearModelButton() { - return new JButton(this.buildClearModelAction()); - } - - private Action buildClearModelAction() { - Action action = new AbstractAction("clear model") { - public void actionPerformed(ActionEvent event) { - CheckBoxModelAdapterUITest.this.clearModel(); - } - }; - action.setEnabled(true); - return action; - } - - void clearModel() { - this.testModelHolder.setValue(null); - } - - private JButton buildRestoreModelButton() { - return new JButton(this.buildRestoreModelAction()); - } - - private Action buildRestoreModelAction() { - Action action = new AbstractAction("restore model") { - public void actionPerformed(ActionEvent event) { - CheckBoxModelAdapterUITest.this.restoreModel(); - } - }; - action.setEnabled(true); - return action; - } - - void restoreModel() { - this.testModelHolder.setValue(this.testModel); - } - - private JButton buildPrintModelButton() { - return new JButton(this.buildPrintModelAction()); - } - - private Action buildPrintModelAction() { - Action action = new AbstractAction("print model") { - public void actionPerformed(ActionEvent event) { - CheckBoxModelAdapterUITest.this.printModel(); - } - }; - action.setEnabled(true); - return action; - } - - void printModel() { - System.out.println("flag 1: " + this.testModel.isFlag1()); - System.out.println("flag 2: " + this.testModel.isFlag2()); - System.out.println("not flag 2: " + this.testModel.isNotFlag2()); - System.out.println("***"); - } - - - private class TestModel extends AbstractModel { - private boolean flag1; - public static final String FLAG1_PROPERTY = "flag1"; - private boolean flag2; - public static final String FLAG2_PROPERTY = "flag2"; - private boolean notFlag2; - public static final String NOT_FLAG2_PROPERTY = "notFlag2"; - - public TestModel(boolean flag1, boolean flag2) { - this.flag1 = flag1; - this.flag2 = flag2; - this.notFlag2 = ! flag2; - } - public boolean isFlag1() { - return this.flag1; - } - public void setFlag1(boolean flag1) { - boolean old = this.flag1; - this.flag1 = flag1; - this.firePropertyChanged(FLAG1_PROPERTY, old, flag1); - } - public boolean isFlag2() { - return this.flag2; - } - public void setFlag2(boolean flag2) { - boolean old = this.flag2; - this.flag2 = flag2; - this.firePropertyChanged(FLAG2_PROPERTY, old, flag2); - - old = this.notFlag2; - this.notFlag2 = ! flag2; - this.firePropertyChanged(NOT_FLAG2_PROPERTY, old, this.notFlag2); - } - public boolean isNotFlag2() { - return this.notFlag2; - } - public void setNotFlag2(boolean notFlag2) { - this.setFlag2( ! notFlag2); - } - @Override - public String toString() { - return "TestModel(" + this.isFlag1() + " - " + this.isFlag2() + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java deleted file mode 100644 index e79111a232..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterTests.java +++ /dev/null @@ -1,110 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import javax.swing.ComboBoxModel; -import javax.swing.ListModel; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ComboBoxModelAdapter; -import org.eclipse.jpt.utility.internal.swing.Displayable; -import org.eclipse.jpt.utility.internal.swing.SimpleDisplayable; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.model.value.CoordinatedList; - -public class ComboBoxModelAdapterTests extends TestCase { - - public ComboBoxModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - // nothing yet... - } - - @Override - protected void tearDown() throws Exception { - // nothing yet... - super.tearDown(); - } - - public void testHasListeners() throws Exception { - SimpleListValueModel<Displayable> listHolder = this.buildListHolder(); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - SimplePropertyValueModel<Object> selectionHolder = new SimplePropertyValueModel<Object>(listHolder.iterator().next()); - assertFalse(selectionHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - - ComboBoxModel comboBoxModel = new ComboBoxModelAdapter(listHolder, selectionHolder); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(selectionHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(comboBoxModel); - - CoordinatedList<Displayable> synchList = new CoordinatedList<Displayable>(comboBoxModel); - PropertyChangeListener selectionListener = this.buildSelectionListener(); - selectionHolder.addPropertyChangeListener(PropertyValueModel.VALUE, selectionListener); - assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(selectionHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasListeners(comboBoxModel); - - comboBoxModel.removeListDataListener(synchList); - selectionHolder.removePropertyChangeListener(PropertyValueModel.VALUE, selectionListener); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertFalse(selectionHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(comboBoxModel); - } - - private PropertyChangeListener buildSelectionListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent evt) { - // do nothing... - } - }; - } - - private void verifyHasNoListeners(ListModel listModel) throws Exception { - boolean hasNoListeners = ((Boolean) ClassTools.executeMethod(listModel, "hasNoListDataListeners")).booleanValue(); - assertTrue(hasNoListeners); - } - - private void verifyHasListeners(ListModel listModel) throws Exception { - boolean hasListeners = ((Boolean) ClassTools.executeMethod(listModel, "hasListDataListeners")).booleanValue(); - assertTrue(hasListeners); - } - - private SimpleListValueModel<Displayable> buildListHolder() { - return new SimpleListValueModel<Displayable>(this.buildList()); - } - - private List<Displayable> buildList() { - List<Displayable> list = new ArrayList<Displayable>(); - this.populateCollection(list); - return list; - } - - private void populateCollection(Collection<Displayable> c) { - c.add(new SimpleDisplayable("foo")); - c.add(new SimpleDisplayable("bar")); - c.add(new SimpleDisplayable("baz")); - c.add(new SimpleDisplayable("joo")); - c.add(new SimpleDisplayable("jar")); - c.add(new SimpleDisplayable("jaz")); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java deleted file mode 100644 index bb6e8f0ce7..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest.java +++ /dev/null @@ -1,391 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.util.ArrayList; -import java.util.List; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ComboBoxModel; -import javax.swing.JButton; -import javax.swing.JComboBox; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.ListCellRenderer; -import javax.swing.UIManager; -import javax.swing.WindowConstants; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ComboBoxModelAdapter; -import org.eclipse.jpt.utility.internal.swing.FilteringListBrowser; -import org.eclipse.jpt.utility.internal.swing.ListChooser; -import org.eclipse.jpt.utility.internal.swing.SimpleListCellRenderer; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - - -/** - * Play around with a set of combo-boxes. - * - * DefaultLongListBrowserDialogUITest subclasses this class; so be - * careful when making changes. - */ -public class ComboBoxModelAdapterUITest { - - protected JFrame window; - private TestModel testModel; - private WritablePropertyValueModel<TestModel> testModelHolder; - private WritablePropertyValueModel<Object> colorHolder; - private SimpleListValueModel<String> colorListHolder; - protected ComboBoxModel colorComboBoxModel; - private int nextColorNumber = 0; - - public static void main(String[] args) throws Exception { - new ComboBoxModelAdapterUITest().exec(args); - } - - protected ComboBoxModelAdapterUITest() { - super(); - } - - protected void exec(String[] args) throws Exception { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); -// UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName()); // Metal LAF -// UIManager.setLookAndFeel(com.sun.java.swing.plaf.windows.WindowsLookAndFeel.class.getName()); -// UIManager.setLookAndFeel(com.sun.java.swing.plaf.motif.MotifLookAndFeel.class.getName()); -// UIManager.setLookAndFeel(oracle.bali.ewt.olaf.OracleLookAndFeel.class.getName()); - this.testModel = this.buildTestModel(); - this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel); - this.colorHolder = this.buildColorHolder(this.testModelHolder); - this.colorListHolder = this.buildColorListHolder(); - this.colorComboBoxModel = this.buildComboBoxModelAdapter(this.colorListHolder, this.colorHolder); - this.openWindow(); - } - - private WritablePropertyValueModel<Object> buildColorHolder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, Object>(vm, TestModel.COLOR_PROPERTY) { - @Override - protected String buildValue_() { - return this.subject.getColor(); - } - @Override - protected void setValue_(Object value) { - this.subject.setColor((String) value); - } - }; - } - - protected TestModel buildTestModel() { - return new TestModel(); - } - - private SimpleListValueModel<String> buildColorListHolder() { - return new SimpleListValueModel<String>(TestModel.validColors()); -// return new AbstractReadOnlyListValueModel() { -// public Object value() { -// return new ArrayListIterator(TestModel.VALID_COLORS); -// } -// public int size() { -// return TestModel.VALID_COLORS.length; -// } -// }; - } - - protected ListValueModel<String> uiColorListHolder() { - return this.colorListHolder; - } - - private ComboBoxModel buildComboBoxModelAdapter(ListValueModel<String> listHolder, WritablePropertyValueModel<Object> selectionHolder) { - return new ComboBoxModelAdapter(listHolder, selectionHolder); - } - - private void openWindow() { - this.window = new JFrame(ClassTools.shortNameFor(this.getClass())); - this.window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - this.window.addWindowListener(this.buildWindowListener()); - this.window.getContentPane().add(this.buildMainPanel(), "Center"); - this.window.setLocation(300, 300); - this.window.setSize(400, 150); - this.window.setVisible(true); - } - - private WindowListener buildWindowListener() { - return new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - System.exit(0); - } - }; - } - - private Component buildMainPanel() { - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(this.buildComboBoxPanel(), BorderLayout.NORTH); - mainPanel.add(this.buildControlPanel(), BorderLayout.SOUTH); - return mainPanel; - } - - protected JPanel buildComboBoxPanel() { - JPanel panel = new JPanel(new GridLayout(1, 0)); - panel.add(this.buildComboBox()); - panel.add(this.buildComboBox()); - panel.add(this.buildListChooser1()); - panel.add(this.buildListChooser2()); - return panel; - } - - private JComboBox buildComboBox() { - JComboBox comboBox = new JComboBox(this.colorComboBoxModel); - comboBox.setRenderer(this.buildComboBoxRenderer()); - return comboBox; - } - - protected ListCellRenderer buildComboBoxRenderer() { - return new SimpleListCellRenderer() { - @Override - protected String buildText(Object value) { - return super.buildText(value); - } - }; - } - - private ListChooser buildListChooser1() { - return new LocalListChooser1(this.colorComboBoxModel); - } - - private ListChooser buildListChooser2() { - return new LocalListChooser2(this.colorComboBoxModel); - } - - private Component buildControlPanel() { - JPanel controlPanel = new JPanel(new GridLayout(2, 0)); - controlPanel.add(this.buildResetColorButton()); - controlPanel.add(this.buildClearModelButton()); - controlPanel.add(this.buildRestoreModelButton()); - controlPanel.add(this.buildPrintModelButton()); - controlPanel.add(this.buildAddTenButton()); - controlPanel.add(this.buildRemoveTenButton()); - return controlPanel; - } - - // ********** reset color button ********** - private JButton buildResetColorButton() { - return new JButton(this.buildResetColorAction()); - } - - private Action buildResetColorAction() { - Action action = new AbstractAction("reset color") { - public void actionPerformed(ActionEvent event) { - ComboBoxModelAdapterUITest.this.resetColor(); - } - }; - action.setEnabled(true); - return action; - } - - void resetColor() { - this.testModel.setColor(TestModel.DEFAULT_COLOR); - } - - // ********** clear model button ********** - private JButton buildClearModelButton() { - return new JButton(this.buildClearModelAction()); - } - - private Action buildClearModelAction() { - Action action = new AbstractAction("clear model") { - public void actionPerformed(ActionEvent event) { - ComboBoxModelAdapterUITest.this.clearModel(); - } - }; - action.setEnabled(true); - return action; - } - - void clearModel() { - this.testModelHolder.setValue(null); - } - - // ********** restore model button ********** - private JButton buildRestoreModelButton() { - return new JButton(this.buildRestoreModelAction()); - } - - private Action buildRestoreModelAction() { - Action action = new AbstractAction("restore model") { - public void actionPerformed(ActionEvent event) { - ComboBoxModelAdapterUITest.this.restoreModel(); - } - }; - action.setEnabled(true); - return action; - } - - void restoreModel() { - this.testModelHolder.setValue(this.testModel); - } - - // ********** print model button ********** - private JButton buildPrintModelButton() { - return new JButton(this.buildPrintModelAction()); - } - - private Action buildPrintModelAction() { - Action action = new AbstractAction("print model") { - public void actionPerformed(ActionEvent event) { - ComboBoxModelAdapterUITest.this.printModel(); - } - }; - action.setEnabled(true); - return action; - } - - void printModel() { - System.out.println(this.testModel); - } - - // ********** add 20 button ********** - private JButton buildAddTenButton() { - return new JButton(this.buildAddTenAction()); - } - - private Action buildAddTenAction() { - Action action = new AbstractAction("add 20") { - public void actionPerformed(ActionEvent event) { - ComboBoxModelAdapterUITest.this.addTen(); - } - }; - action.setEnabled(true); - return action; - } - - void addTen() { - for (int i = this.nextColorNumber; i < this.nextColorNumber + 20; i++) { - this.colorListHolder.add(this.colorListHolder.size(), "color" + i); - } - this.nextColorNumber += 20; - } - - // ********** remove 20 button ********** - private JButton buildRemoveTenButton() { - return new JButton(this.buildRemoveTenAction()); - } - - private Action buildRemoveTenAction() { - Action action = new AbstractAction("remove 20") { - public void actionPerformed(ActionEvent event) { - ComboBoxModelAdapterUITest.this.removeTen(); - } - }; - action.setEnabled(true); - return action; - } - - void removeTen() { - for (int i = 0; i < 20; i++) { - if (this.colorListHolder.size() > 0) { - this.colorListHolder.remove(this.colorListHolder.size() - 1); - } - } - } - - - protected static class TestModel extends AbstractModel { - private String color; - public static final String COLOR_PROPERTY = "color"; - public static final String RED = "red"; - public static final String ORANGE = "orange"; - public static final String YELLOW = "yellow"; - public static final String GREEN = "green"; - public static final String BLUE = "blue"; - public static final String INDIGO = "indigo"; - public static final String VIOLET = "violet"; - public static final String DEFAULT_COLOR = RED; - public static List<String> validColors; - public static final String[] DEFAULT_VALID_COLORS = { - RED, - ORANGE, - YELLOW, - GREEN, - BLUE, - INDIGO, - VIOLET - }; - - public static List<String> validColors() { - if (validColors == null) { - validColors = buildDefaultValidColors(); - } - return validColors; - } - public static List<String> buildDefaultValidColors() { - List<String> result = new ArrayList<String>(); - CollectionTools.addAll(result, DEFAULT_VALID_COLORS); - return result; - } - - public TestModel() { - this(DEFAULT_COLOR); - } - public TestModel(String color) { - this.color = color; - } - public String getColor() { - return this.color; - } - public void setColor(String color) { - this.checkColor(color); - Object old = this.color; - this.color = color; - this.firePropertyChanged(COLOR_PROPERTY, old, color); - } - public void checkColor(String c) { - if ( ! validColors().contains(c)) { - throw new IllegalArgumentException(c); - } - } - @Override - public String toString() { - return "TestModel(" + this.color + ")"; - } - } - - - private class LocalListChooser1 extends ListChooser { - public LocalListChooser1(ComboBoxModel model) { - super(model); - } - } - - - private class LocalListChooser2 extends ListChooser { - public LocalListChooser2(ComboBoxModel model) { - super(model); - } - @Override - protected ListBrowser buildBrowser() { - return new FilteringListBrowser<String>(); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java deleted file mode 100644 index e9c5fc4a09..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ComboBoxModelAdapterUITest2.java +++ /dev/null @@ -1,74 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import javax.swing.ListCellRenderer; -import org.eclipse.jpt.utility.internal.model.value.ExtendedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.swing.SimpleListCellRenderer; -import org.eclipse.jpt.utility.model.value.ListValueModel; - -/** - * - */ -public class ComboBoxModelAdapterUITest2 extends ComboBoxModelAdapterUITest { - - public static void main(String[] args) throws Exception { - new ComboBoxModelAdapterUITest2().exec(args); - } - - public ComboBoxModelAdapterUITest2() { - super(); - } - - /** - * use a different model that allows the color to be set to null - */ - @Override - protected TestModel buildTestModel() { - return new TestModel2(); - } - - /** - * add a null to the front of the list - */ - @Override - protected ListValueModel<String> uiColorListHolder() { - // the default is to prepend the wrapped list with a null item - return new ExtendedListValueModelWrapper<String>(super.uiColorListHolder()); - } - - /** - * convert null to some text - */ - @Override - protected ListCellRenderer buildComboBoxRenderer() { - return new SimpleListCellRenderer() { - @Override - protected String buildText(Object value) { - return (value == null) ? "<none selected>" : super.buildText(value); - } - }; - } - - - protected static class TestModel2 extends TestModel { - /** - * null is OK here - */ - @Override - public void checkColor(String color) { - if (color == null) { - return; - } - super.checkColor(color); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java deleted file mode 100644 index cb255e7b12..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DateSpinnerModelAdapterTests.java +++ /dev/null @@ -1,159 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.util.Date; -import javax.swing.SpinnerModel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.DateSpinnerModelAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class DateSpinnerModelAdapterTests extends TestCase { - private WritablePropertyValueModel<Object> valueHolder; - private SpinnerModel spinnerModelAdapter; - boolean eventFired; - - public DateSpinnerModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.valueHolder = new SimplePropertyValueModel<Object>(new Date()); - this.spinnerModelAdapter = new DateSpinnerModelAdapter(this.valueHolder) { - @Override - protected PropertyChangeListener buildDateChangeListener() { - return this.buildDateChangeListener_(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSetValueSpinnerModel() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - DateSpinnerModelAdapterTests.this.eventFired = true; - } - }); - Date newDate = new Date(); - newDate.setTime(777777); - this.spinnerModelAdapter.setValue(newDate); - assertTrue(this.eventFired); - assertEquals(777777, ((Date) this.valueHolder.getValue()).getTime()); - } - - public void testSetValueValueHolder() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - DateSpinnerModelAdapterTests.this.eventFired = true; - } - }); - Date newDate = new Date(); - newDate.setTime(777777); - this.valueHolder.setValue(newDate); - assertTrue(this.eventFired); - assertEquals(777777, ((Date) this.spinnerModelAdapter.getValue()).getTime()); - } - - public void testDefaultValue() throws Exception { - Date newDate = new Date(); - newDate.setTime(777777); - this.valueHolder.setValue(newDate); - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - DateSpinnerModelAdapterTests.this.eventFired = true; - } - }); - assertEquals(777777, ((Date) this.spinnerModelAdapter.getValue()).getTime()); - this.valueHolder.setValue(null); - assertTrue(this.eventFired); - assertFalse(((Date) this.spinnerModelAdapter.getValue()).getTime() == 777777); - } - - public void testHasListeners() throws Exception { - SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueHolder; - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.spinnerModelAdapter); - - ChangeListener listener = new TestChangeListener(); - this.spinnerModelAdapter.addChangeListener(listener); - assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasListeners(this.spinnerModelAdapter); - - this.spinnerModelAdapter.removeChangeListener(listener); - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.spinnerModelAdapter); - } - - private void verifyHasNoListeners(SpinnerModel adapter) throws Exception { - assertEquals(0, ((DateSpinnerModelAdapter) adapter).getChangeListeners().length); - } - - private void verifyHasListeners(Object adapter) throws Exception { - assertFalse(((DateSpinnerModelAdapter) adapter).getChangeListeners().length == 0); - } - - public void testNullInitialValue() { - Date today = new Date(); - this.valueHolder = new SimplePropertyValueModel<Object>(); - this.spinnerModelAdapter = new DateSpinnerModelAdapter(this.valueHolder, today) { - @Override - protected PropertyChangeListener buildDateChangeListener() { - return this.buildDateChangeListener_(); - } - }; - - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - DateSpinnerModelAdapterTests.this.eventFired = true; - } - }); - assertEquals(today, this.spinnerModelAdapter.getValue()); - - Date newDate = new Date(); - newDate.setTime(777777); - this.valueHolder.setValue(newDate); - - assertTrue(this.eventFired); - assertEquals(777777, ((Date) this.spinnerModelAdapter.getValue()).getTime()); - } - - - // ********** inner class ********** - private class TestChangeListener implements ChangeListener { - TestChangeListener() { - super(); - } - public void stateChanged(ChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java deleted file mode 100644 index d647360a88..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterTests.java +++ /dev/null @@ -1,158 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import javax.swing.event.DocumentEvent; -import javax.swing.event.DocumentListener; -import javax.swing.event.DocumentEvent.EventType; -import javax.swing.text.Document; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.DocumentAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class DocumentAdapterTests extends TestCase { - private WritablePropertyValueModel<String> stringHolder; - Document documentAdapter; - boolean eventFired; - - public DocumentAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.stringHolder = new SimplePropertyValueModel<String>("0123456789"); - this.documentAdapter = new DocumentAdapter(this.stringHolder) { - @Override - protected PropertyChangeListener buildStringListener() { - return this.buildStringListener_(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testRemove() throws Exception { - this.eventFired = false; - this.documentAdapter.addDocumentListener(new TestDocumentListener() { - @Override - public void removeUpdate(DocumentEvent e) { - DocumentAdapterTests.this.eventFired = true; - assertEquals(EventType.REMOVE, e.getType()); - assertEquals(DocumentAdapterTests.this.documentAdapter, e.getDocument()); - // this will be the removal of "23456" - assertEquals(2, e.getOffset()); - assertEquals(5, e.getLength()); - } - }); - this.documentAdapter.remove(2, 5); - assertTrue(this.eventFired); - assertEquals("01789", this.stringHolder.getValue()); - } - - public void testInsert() throws Exception { - this.eventFired = false; - this.documentAdapter.addDocumentListener(new TestDocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) { - DocumentAdapterTests.this.eventFired = true; - assertEquals(EventType.INSERT, e.getType()); - assertEquals(DocumentAdapterTests.this.documentAdapter, e.getDocument()); - // this will be the insert of "xxxxxx" - assertEquals(2, e.getOffset()); - assertEquals(5, e.getLength()); - } - }); - this.documentAdapter.insertString(2, "xxxxx", null); - assertTrue(this.eventFired); - assertEquals("01xxxxx23456789", this.stringHolder.getValue()); - } - - public void testSetValue() throws Exception { - this.eventFired = false; - this.documentAdapter.addDocumentListener(new TestDocumentListener() { - @Override - public void insertUpdate(DocumentEvent e) { - DocumentAdapterTests.this.eventFired = true; - assertEquals(EventType.INSERT, e.getType()); - assertEquals(DocumentAdapterTests.this.documentAdapter, e.getDocument()); - // this will be the insert of "foo" - assertEquals(0, e.getOffset()); - assertEquals(3, e.getLength()); - } - @Override - public void removeUpdate(DocumentEvent e) { - assertEquals(EventType.REMOVE, e.getType()); - assertEquals(DocumentAdapterTests.this.documentAdapter, e.getDocument()); - // this will be the removal of "0123456789" - assertEquals(0, e.getOffset()); - assertEquals(10, e.getLength()); - } - }); - assertEquals("0123456789", this.documentAdapter.getText(0, this.documentAdapter.getLength())); - this.stringHolder.setValue("foo"); - assertTrue(this.eventFired); - assertEquals("foo", this.documentAdapter.getText(0, this.documentAdapter.getLength())); - } - - public void testHasListeners() throws Exception { - SimplePropertyValueModel<String> localStringHolder = (SimplePropertyValueModel<String>) this.stringHolder; - assertFalse(localStringHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.documentAdapter); - - DocumentListener listener = new TestDocumentListener(); - this.documentAdapter.addDocumentListener(listener); - assertTrue(localStringHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasListeners(this.documentAdapter); - - this.documentAdapter.removeDocumentListener(listener); - assertFalse(localStringHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.documentAdapter); - } - - private void verifyHasNoListeners(Object document) throws Exception { - Object delegate = ClassTools.fieldValue(document, "delegate"); - Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getDocumentListeners"); - assertEquals(0, listeners.length); - } - - private void verifyHasListeners(Object document) throws Exception { - Object delegate = ClassTools.fieldValue(document, "delegate"); - Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getDocumentListeners"); - assertFalse(listeners.length == 0); - } - - -private class TestDocumentListener implements DocumentListener { - TestDocumentListener() { - super(); - } - public void changedUpdate(DocumentEvent e) { - fail("unexpected event"); - } - public void insertUpdate(DocumentEvent e) { - fail("unexpected event"); - } - public void removeUpdate(DocumentEvent e) { - fail("unexpected event"); - } -} - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java deleted file mode 100644 index 39b43388cd..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/DocumentAdapterUITest.java +++ /dev/null @@ -1,255 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.WindowConstants; -import javax.swing.text.AbstractDocument; -import javax.swing.text.AttributeSet; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import javax.swing.text.PlainDocument; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.DocumentAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * Play around with a set of entry fields. - */ -public class DocumentAdapterUITest { - - private TestModel testModel; - private static final String DEFAULT_NAME = "Scooby Doo"; - private WritablePropertyValueModel<TestModel> testModelHolder; - private WritablePropertyValueModel<String> nameHolder; - private Document nameDocument; - private Document upperCaseNameDocument; - - public static void main(String[] args) throws Exception { - new DocumentAdapterUITest().exec(args); - } - - private DocumentAdapterUITest() { - super(); - } - - private void exec(String[] args) throws Exception { - this.testModel = new TestModel(DEFAULT_NAME); - this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel); - this.nameHolder = this.buildNameHolder(this.testModelHolder); - this.nameDocument = this.buildNameDocument(this.nameHolder); - this.upperCaseNameDocument = this.buildUpperCaseNameDocument(this.nameHolder); - this.openWindow(); - } - - private WritablePropertyValueModel<String> buildNameHolder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, String>(vm, TestModel.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return this.subject.getName(); - } - @Override - protected void setValue_(String value) { - this.subject.setName(value); - } - }; - } - - private Document buildNameDocument(WritablePropertyValueModel<String> stringHolder) { - return new DocumentAdapter(stringHolder); - } - - private Document buildUpperCaseNameDocument(WritablePropertyValueModel<String> stringHolder) { - return new DocumentAdapter(stringHolder, this.buildUpperCaseNameDocumentDelegate()); - } - - private AbstractDocument buildUpperCaseNameDocumentDelegate() { - return new PlainDocument() { - @Override - public void insertString(int offset, String string, AttributeSet a) throws BadLocationException { - if (string == null) { - return; - } - char[] upper = string.toCharArray(); - for (int i = 0; i < upper.length; i++) { - upper[i] = Character.toUpperCase(upper[i]); - } - super.insertString(offset, new String(upper), a); - } - }; - } - - private void openWindow() { - JFrame window = new JFrame(this.getClass().getName()); - window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - window.addWindowListener(this.buildWindowListener()); - window.getContentPane().add(this.buildMainPanel(), "Center"); - window.setSize(400, 100); - window.setVisible(true); - } - - private WindowListener buildWindowListener() { - return new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - System.exit(0); - } - }; - } - - private Component buildMainPanel() { - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(this.buildTextFieldPanel(), BorderLayout.NORTH); - mainPanel.add(this.buildControlPanel(), BorderLayout.SOUTH); - return mainPanel; - } - - private Component buildTextFieldPanel() { - JPanel taskListPanel = new JPanel(new GridLayout(1, 0)); - taskListPanel.add(this.buildNameTextField()); - taskListPanel.add(this.buildReadOnlyNameTextField()); - taskListPanel.add(this.buildUpperCaseNameTextField()); - return taskListPanel; - } - - private JTextField buildNameTextField() { - return new JTextField(this.nameDocument, null, 0); - } - - private JTextField buildReadOnlyNameTextField() { - JTextField nameTextField = this.buildNameTextField(); - nameTextField.setEditable(false); - return nameTextField; - } - - private JTextField buildUpperCaseNameTextField() { - return new JTextField(this.upperCaseNameDocument, null, 0); - } - - private Component buildControlPanel() { - JPanel controlPanel = new JPanel(new GridLayout(1, 0)); - controlPanel.add(this.buildResetNameButton()); - controlPanel.add(this.buildClearModelButton()); - controlPanel.add(this.buildRestoreModelButton()); - controlPanel.add(this.buildPrintModelButton()); - return controlPanel; - } - - private JButton buildResetNameButton() { - return new JButton(this.buildResetNameAction()); - } - - private Action buildResetNameAction() { - Action action = new AbstractAction("reset name") { - public void actionPerformed(ActionEvent event) { - DocumentAdapterUITest.this.resetName(); - } - }; - action.setEnabled(true); - return action; - } - - void resetName() { - this.testModel.setName(DEFAULT_NAME); - } - - private JButton buildClearModelButton() { - return new JButton(this.buildClearModelAction()); - } - - private Action buildClearModelAction() { - Action action = new AbstractAction("clear model") { - public void actionPerformed(ActionEvent event) { - DocumentAdapterUITest.this.clearModel(); - } - }; - action.setEnabled(true); - return action; - } - - void clearModel() { - this.testModelHolder.setValue(null); - } - - private JButton buildRestoreModelButton() { - return new JButton(this.buildRestoreModelAction()); - } - - private Action buildRestoreModelAction() { - Action action = new AbstractAction("restore model") { - public void actionPerformed(ActionEvent event) { - DocumentAdapterUITest.this.restoreModel(); - } - }; - action.setEnabled(true); - return action; - } - - void restoreModel() { - this.testModelHolder.setValue(this.testModel); - } - - private JButton buildPrintModelButton() { - return new JButton(this.buildPrintModelAction()); - } - - private Action buildPrintModelAction() { - Action action = new AbstractAction("print model") { - public void actionPerformed(ActionEvent event) { - DocumentAdapterUITest.this.printModel(); - } - }; - action.setEnabled(true); - return action; - } - - void printModel() { - System.out.println("name: " + this.testModel.getName()); - } - - - private class TestModel extends AbstractModel { - private String name; - public static final String NAME_PROPERTY = "name"; - - public TestModel(String name) { - this.name = name; - } - public String getName() { - return this.name; - } - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - @Override - public String toString() { - return "TestModel(" + this.getName() + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/JptUtilityModelValueSwingTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/JptUtilityModelValueSwingTests.java deleted file mode 100644 index b531bd3c73..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/JptUtilityModelValueSwingTests.java +++ /dev/null @@ -1,42 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import junit.framework.Test; -import junit.framework.TestSuite; - -public class JptUtilityModelValueSwingTests { - - public static Test suite() { - TestSuite suite = new TestSuite(JptUtilityModelValueSwingTests.class.getPackage().getName()); - - suite.addTestSuite(CheckBoxModelAdapterTests.class); - suite.addTestSuite(ComboBoxModelAdapterTests.class); - suite.addTestSuite(DateSpinnerModelAdapterTests.class); - suite.addTestSuite(DocumentAdapterTests.class); - suite.addTestSuite(ListModelAdapterTests.class); - suite.addTestSuite(ListSpinnerModelAdapterTests.class); - suite.addTestSuite(NumberSpinnerModelAdapterTests.class); - suite.addTestSuite(ObjectListSelectionModelTests.class); - suite.addTestSuite(PrimitiveListTreeModelTests.class); - suite.addTestSuite(RadioButtonModelAdapterTests.class); - suite.addTestSuite(SpinnerModelAdapterTests.class); - suite.addTestSuite(TableModelAdapterTests.class); - suite.addTestSuite(TreeModelAdapterTests.class); - - return suite; - } - - private JptUtilityModelValueSwingTests() { - super(); - throw new UnsupportedOperationException(); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java deleted file mode 100644 index 6765325f00..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterTests.java +++ /dev/null @@ -1,320 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.Comparator; -import java.util.Iterator; -import java.util.List; -import java.util.SortedSet; -import java.util.TreeSet; - -import javax.swing.ListModel; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.Bag; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.model.value.CoordinatedList; - -@SuppressWarnings("nls") -public class ListModelAdapterTests extends TestCase { - - public ListModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - // nothing yet... - } - - @Override - protected void tearDown() throws Exception { - // nothing yet... - super.tearDown(); - } - - private ListModelAdapter buildListModel(ListValueModel<String> listHolder) { - return new ListModelAdapter(listHolder) { - @Override - protected ListChangeListener buildListChangeListener() { - return this.buildListChangeListener_(); - } - }; - } - - private ListModel buildListModel(CollectionValueModel<String> collectionHolder) { - return new ListModelAdapter(collectionHolder) { - @Override - protected ListChangeListener buildListChangeListener() { - return this.buildListChangeListener_(); - } - }; - } - - public void testCollectionSynchronization() { - SimpleCollectionValueModel<String> collectionHolder = this.buildCollectionHolder(); - ListModel listModel = this.buildListModel(collectionHolder); - CoordinatedList<String> synchList = new CoordinatedList<String>(listModel); - assertEquals(6, synchList.size()); - this.compare(listModel, synchList); - - collectionHolder.add("tom"); - collectionHolder.add("dick"); - collectionHolder.add("harry"); - collectionHolder.add(null); - assertEquals(10, synchList.size()); - this.compare(listModel, synchList); - - collectionHolder.remove("foo"); - collectionHolder.remove("jar"); - collectionHolder.remove("harry"); - collectionHolder.remove(null); - assertEquals(6, synchList.size()); - this.compare(listModel, synchList); - } - - public void testListSynchronization() { - SimpleListValueModel<String> listHolder = this.buildListHolder(); - ListModel listModel = this.buildListModel(listHolder); - CoordinatedList<String> synchList = new CoordinatedList<String>(listModel); - assertEquals(6, synchList.size()); - this.compare(listModel, synchList); - - listHolder.add(6, "tom"); - listHolder.add(7, "dick"); - listHolder.add(8, "harry"); - listHolder.add(9, null); - assertEquals(10, synchList.size()); - this.compare(listModel, synchList); - - listHolder.remove(9); - listHolder.remove(8); - listHolder.remove(4); - listHolder.remove(0); - assertEquals(6, synchList.size()); - this.compare(listModel, synchList); - } - - public void testSetModel() { - SimpleListValueModel<String> listHolder1 = this.buildListHolder(); - ListModelAdapter listModel = this.buildListModel(listHolder1); - CoordinatedList<String> synchList = new CoordinatedList<String>(listModel); - assertTrue(listHolder1.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - assertEquals(6, synchList.size()); - this.compare(listModel, synchList); - - SimpleListValueModel<String> listHolder2 = this.buildListHolder2(); - listModel.setModel(listHolder2); - assertEquals(3, synchList.size()); - this.compare(listModel, synchList); - assertTrue(listHolder1.hasNoListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(listHolder2.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - listModel.setModel(new SimpleListValueModel<String>()); - assertEquals(0, synchList.size()); - this.compare(listModel, synchList); - assertTrue(listHolder1.hasNoListChangeListeners(ListValueModel.LIST_VALUES)); - assertTrue(listHolder2.hasNoListChangeListeners(ListValueModel.LIST_VALUES)); - } - - private void compare(ListModel listModel, List<String> list) { - assertEquals(listModel.getSize(), list.size()); - for (int i = 0; i < listModel.getSize(); i++) { - assertEquals(listModel.getElementAt(i), list.get(i)); - } - } - - public void testCollectionSort() { - this.verifyCollectionSort(null); - } - - public void testListSort() { - this.verifyListSort(null); - } - - public void testCustomCollectionSort() { - this.verifyCollectionSort(this.buildCustomComparator()); - } - - public void testCustomListSort() { - this.verifyListSort(this.buildCustomComparator()); - } - - private Comparator<String> buildCustomComparator() { - // sort with reverse order - return new Comparator<String>() { - public int compare(String s1, String s2) { - return s2.compareTo(s1); - } - }; - } - - private void verifyCollectionSort(Comparator<String> comparator) { - SimpleCollectionValueModel<String> collectionHolder = this.buildCollectionHolder(); - ListModel listModel = this.buildListModel(new SortedListValueModelAdapter<String>(collectionHolder, comparator)); - CoordinatedList<String> synchList = new CoordinatedList<String>(listModel); - assertEquals(6, synchList.size()); - this.compareSort(listModel, synchList, comparator); - - collectionHolder.add("tom"); - collectionHolder.add("dick"); - collectionHolder.add("harry"); - assertEquals(9, synchList.size()); - this.compareSort(listModel, synchList, comparator); - - collectionHolder.remove("foo"); - collectionHolder.remove("jar"); - collectionHolder.remove("harry"); - assertEquals(6, synchList.size()); - this.compareSort(listModel, synchList, comparator); - } - - private void verifyListSort(Comparator<String> comparator) { - SimpleListValueModel<String> listHolder = this.buildListHolder(); - ListModel listModel = this.buildListModel(new SortedListValueModelWrapper<String>(listHolder, comparator)); - CoordinatedList<String> synchList = new CoordinatedList<String>(listModel); - assertEquals(6, synchList.size()); - this.compareSort(listModel, synchList, comparator); - - listHolder.add(0, "tom"); - listHolder.add(0, "dick"); - listHolder.add(0, "harry"); - assertEquals(9, synchList.size()); - this.compareSort(listModel, synchList, comparator); - - listHolder.remove(8); - listHolder.remove(4); - listHolder.remove(0); - listHolder.remove(5); - assertEquals(5, synchList.size()); - this.compareSort(listModel, synchList, comparator); - } - - private void compareSort(ListModel listModel, List<String> list, Comparator<String> comparator) { - SortedSet<String> ss = new TreeSet<String>(comparator); - for (int i = 0; i < listModel.getSize(); i++) { - ss.add((String) listModel.getElementAt(i)); - } - assertEquals(ss.size(), list.size()); - for (Iterator<String> stream1 = ss.iterator(), stream2 = list.iterator(); stream1.hasNext(); ) { - assertEquals(stream1.next(), stream2.next()); - } - } - - public void testHasListeners() throws Exception { - SimpleListValueModel<String> listHolder = this.buildListHolder(); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - - ListModel listModel = this.buildListModel(listHolder); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.verifyHasNoListeners(listModel); - - CoordinatedList<String> synchList = new CoordinatedList<String>(listModel); - assertTrue(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.verifyHasListeners(listModel); - - listModel.removeListDataListener(synchList); - assertFalse(listHolder.hasAnyListChangeListeners(ListValueModel.LIST_VALUES)); - this.verifyHasNoListeners(listModel); - } - - public void testGetSize() throws Exception { - SimpleListValueModel<String> listHolder = this.buildListHolder(); - ListModel listModel = this.buildListModel(listHolder); - this.verifyHasNoListeners(listModel); - assertEquals(6, listModel.getSize()); - - CoordinatedList<String> synchList = new CoordinatedList<String>(listModel); - this.verifyHasListeners(listModel); - assertEquals(6, listModel.getSize()); - - listModel.removeListDataListener(synchList); - this.verifyHasNoListeners(listModel); - assertEquals(6, listModel.getSize()); - } - - public void testGetElementAt() throws Exception { - SimpleListValueModel<String> listHolder = this.buildListHolder(); - ListModel listModel = this.buildListModel(new SortedListValueModelWrapper<String>(listHolder)); - CoordinatedList<String> synchList = new CoordinatedList<String>(listModel); - this.verifyHasListeners(listModel); - assertEquals("bar", listModel.getElementAt(0)); - assertEquals("bar", synchList.get(0)); - } - - private void verifyHasNoListeners(ListModel listModel) throws Exception { - boolean hasNoListeners = ((Boolean) ClassTools.executeMethod(listModel, "hasNoListDataListeners")).booleanValue(); - assertTrue(hasNoListeners); - } - - private void verifyHasListeners(ListModel listModel) throws Exception { - boolean hasListeners = ((Boolean) ClassTools.executeMethod(listModel, "hasListDataListeners")).booleanValue(); - assertTrue(hasListeners); - } - - private SimpleCollectionValueModel<String> buildCollectionHolder() { - return new SimpleCollectionValueModel<String>(this.buildCollection()); - } - - private Collection<String> buildCollection() { - Bag<String> bag = new HashBag<String>(); - this.populateCollection(bag); - return bag; - } - - private SimpleListValueModel<String> buildListHolder() { - return new SimpleListValueModel<String>(this.buildList()); - } - - private List<String> buildList() { - List<String> list = new ArrayList<String>(); - this.populateCollection(list); - return list; - } - - private void populateCollection(Collection<String> c) { - c.add("foo"); - c.add("bar"); - c.add("baz"); - c.add("joo"); - c.add("jar"); - c.add("jaz"); - } - - private SimpleListValueModel<String> buildListHolder2() { - return new SimpleListValueModel<String>(this.buildList2()); - } - - private List<String> buildList2() { - List<String> list = new ArrayList<String>(); - this.populateCollection2(list); - return list; - } - - private void populateCollection2(Collection<String> c) { - c.add("tom"); - c.add("dick"); - c.add("harry"); - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterUITest.java deleted file mode 100644 index 168ee487f5..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListModelAdapterUITest.java +++ /dev/null @@ -1,370 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.TextField; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.util.ArrayList; -import java.util.Comparator; -import java.util.Date; -import java.util.List; -import java.util.ListIterator; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.Icon; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JLabel; -import javax.swing.JList; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.ListModel; -import javax.swing.WindowConstants; - -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; -import org.eclipse.jpt.utility.internal.swing.Displayable; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * an example UI for testing various permutations of the ListModelAdapter - */ -@SuppressWarnings("nls") -public class ListModelAdapterUITest { - - private WritablePropertyValueModel<TaskList> taskListHolder; - private TextField taskTextField; - - public static void main(String[] args) throws Exception { - new ListModelAdapterUITest().exec(args); - } - - private ListModelAdapterUITest() { - super(); - } - - private void exec(@SuppressWarnings("unused") String[] args) throws Exception { - this.taskListHolder = new SimplePropertyValueModel<TaskList>(new TaskList()); - this.openWindow(); - } - - private void openWindow() { - JFrame window = new JFrame(this.getClass().getName()); - window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - window.addWindowListener(this.buildWindowListener()); - window.getContentPane().add(this.buildMainPanel(), "Center"); - window.setSize(800, 400); - window.setVisible(true); - } - - private WindowListener buildWindowListener() { - return new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - System.exit(0); - } - }; - } - - private Component buildMainPanel() { - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(this.buildTaskListPanel(), BorderLayout.CENTER); - mainPanel.add(this.buildControlPanel(), BorderLayout.SOUTH); - return mainPanel; - } - - private Component buildTaskListPanel() { - JPanel taskListPanel = new JPanel(new GridLayout(0, 1)); - taskListPanel.add(this.buildPrimitiveTaskListPanel()); - taskListPanel.add(this.buildDisplayableTaskListPanel()); - return taskListPanel; - } - - private Component buildPrimitiveTaskListPanel() { - JPanel taskListPanel = new JPanel(new GridLayout(1, 0)); - taskListPanel.add(this.buildUnsortedPrimitiveListPanel()); - taskListPanel.add(this.buildStandardSortedPrimitiveListPanel()); - taskListPanel.add(this.buildCustomSortedPrimitiveListPanel()); - return taskListPanel; - } - - private Component buildDisplayableTaskListPanel() { - JPanel taskListPanel = new JPanel(new GridLayout(1, 0)); - taskListPanel.add(this.buildUnsortedDisplayableListPanel()); - taskListPanel.add(this.buildStandardSortedDisplayableListPanel()); - taskListPanel.add(this.buildCustomSortedDisplayableListPanel()); - return taskListPanel; - } - - private Component buildUnsortedPrimitiveListPanel() { - return this.buildListPanel("primitive unsorted", this.buildUnsortedPrimitiveListModel()); - } - - private Component buildStandardSortedPrimitiveListPanel() { - return this.buildListPanel("primitive sorted", this.buildStandardSortedPrimitiveListModel()); - } - - private Component buildCustomSortedPrimitiveListPanel() { - return this.buildListPanel("primitive reverse sorted", this.buildCustomSortedPrimitiveListModel()); - } - - private Component buildUnsortedDisplayableListPanel() { - return this.buildListPanel("displayable unsorted", this.buildUnsortedDisplayableListModel()); - } - - private Component buildStandardSortedDisplayableListPanel() { - return this.buildListPanel("displayable sorted", this.buildStandardSortedDisplayableListModel()); - } - - private Component buildCustomSortedDisplayableListPanel() { - return this.buildListPanel("displayable reverse sorted", this.buildCustomSortedDisplayableListModel()); - } - - private ListModel buildUnsortedPrimitiveListModel() { - return new ListModelAdapter(this.buildPrimitiveTaskListAdapter()); - } - - private ListModel buildStandardSortedPrimitiveListModel() { - return new ListModelAdapter(new SortedListValueModelWrapper<String>(this.buildPrimitiveTaskListAdapter())); - } - - private ListModel buildCustomSortedPrimitiveListModel() { - return new ListModelAdapter(new SortedListValueModelWrapper<String>(this.buildPrimitiveTaskListAdapter(), this.buildCustomStringComparator())); - } - - private ListModel buildUnsortedDisplayableListModel() { - return new ListModelAdapter(this.buildDisplayableTaskListAdapter()); - } - - private ListModel buildStandardSortedDisplayableListModel() { - return new ListModelAdapter(new SortedListValueModelWrapper<Task>(this.buildDisplayableTaskListAdapter())); - } - - private ListModel buildCustomSortedDisplayableListModel() { - return new ListModelAdapter(new SortedListValueModelWrapper<Task>(this.buildDisplayableTaskListAdapter(), this.buildCustomTaskObjectComparator())); - } - - private Component buildListPanel(String label, ListModel listModel) { - JPanel listPanel = new JPanel(new BorderLayout()); - JLabel listLabel = new JLabel(" " + label); - listPanel.add(listLabel, BorderLayout.NORTH); - - JList listBox = new JList(); - listBox.setModel(listModel); - listBox.setDoubleBuffered(true); - listLabel.setLabelFor(listBox); - listPanel.add(new JScrollPane(listBox), BorderLayout.CENTER); - return listPanel; - } - - private Comparator<String> buildCustomStringComparator() { - return new Comparator<String>() { - public int compare(String s1, String s2) { - return s2.compareTo(s1); - } - }; - } - - private Comparator<Task> buildCustomTaskObjectComparator() { - return new Comparator<Task>() { - public int compare(Task to1, Task to2) { - return to2.displayString().compareTo(to1.displayString()); - } - }; - } - - private ListValueModel<String> buildPrimitiveTaskListAdapter() { - return new ListAspectAdapter<TaskList, String>(TaskList.TASK_NAMES_LIST, this.taskList()) { - @Override - protected ListIterator<String> listIterator_() { - return this.subject.taskNames(); - } - }; - } - - private ListValueModel<Task> buildDisplayableTaskListAdapter() { - return new ListAspectAdapter<TaskList, Task>(TaskList.TASKS_LIST, this.taskList()) { - @Override - protected ListIterator<Task> listIterator_() { - return this.subject.tasks(); - } - }; - } - - private Component buildControlPanel() { - JPanel controlPanel = new JPanel(new BorderLayout()); - controlPanel.add(this.buildAddRemoveTaskPanel(), BorderLayout.CENTER); - controlPanel.add(this.buildClearButton(), BorderLayout.EAST); - return controlPanel; - } - - private Component buildAddRemoveTaskPanel() { - JPanel addRemoveTaskPanel = new JPanel(new BorderLayout()); - addRemoveTaskPanel.add(this.buildAddButton(), BorderLayout.WEST); - addRemoveTaskPanel.add(this.buildTaskTextField(), BorderLayout.CENTER); - addRemoveTaskPanel.add(this.buildRemoveButton(), BorderLayout.EAST); - return addRemoveTaskPanel; - } - - private String getTask() { - return this.taskTextField.getText(); - } - - private TaskList taskList() { - return this.taskListHolder.getValue(); - } - - void addTask() { - String task = this.getTask(); - if (task.length() != 0) { - this.taskList().addTask(task); - } - } - - void removeTask() { - String task = this.getTask(); - if (task.length() != 0) { - this.taskList().removeTask(task); - } - } - - void clearTasks() { - this.taskList().clearTasks(); - } - - private TextField buildTaskTextField() { - this.taskTextField = new TextField(); - return this.taskTextField; - } - - private JButton buildAddButton() { - return new JButton(this.buildAddAction()); - } - - private Action buildAddAction() { - Action action = new AbstractAction("add") { - public void actionPerformed(ActionEvent event) { - ListModelAdapterUITest.this.addTask(); - } - }; - action.setEnabled(true); - return action; - } - - private JButton buildRemoveButton() { - return new JButton(this.buildRemoveAction()); - } - - private Action buildRemoveAction() { - Action action = new AbstractAction("remove") { - public void actionPerformed(ActionEvent event) { - ListModelAdapterUITest.this.removeTask(); - } - }; - action.setEnabled(true); - return action; - } - - private JButton buildClearButton() { - return new JButton(this.buildClearAction()); - } - - private Action buildClearAction() { - Action action = new AbstractAction("clear") { - public void actionPerformed(ActionEvent event) { - ListModelAdapterUITest.this.clearTasks(); - } - }; - action.setEnabled(true); - return action; - } - - public class TaskList extends AbstractModel { - private List<String> taskNames = new ArrayList<String>(); - private List<Task> taskObjects = new ArrayList<Task>(); - public static final String TASK_NAMES_LIST = "taskNames"; - public static final String TASKS_LIST = "tasks"; - TaskList() { - super(); - } - public ListIterator<String> taskNames() { - return this.taskNames.listIterator(); - } - public ListIterator<Task> tasks() { - return this.taskObjects.listIterator(); - } - public void addTask(String taskName) { - int index = this.taskNames.size(); - this.taskNames.add(index, taskName); - this.fireItemAdded(TASK_NAMES_LIST, index, taskName); - - Task taskObject = new Task(taskName); - this.taskObjects.add(index, taskObject); - this.fireItemAdded(TASKS_LIST, index, taskObject); - } - public void removeTask(String taskName) { - int index = this.taskNames.indexOf(taskName); - if (index != -1) { - Object removedTask = this.taskNames.remove(index); - this.fireItemRemoved(TASK_NAMES_LIST, index, removedTask); - // assume the indexes match... - Object removedTaskObject = this.taskObjects.remove(index); - this.fireItemRemoved(TASKS_LIST, index, removedTaskObject); - } - } - public void clearTasks() { - this.taskNames.clear(); - this.fireListChanged(TASK_NAMES_LIST, this.taskNames); - this.taskObjects.clear(); - this.fireListChanged(TASKS_LIST, this.taskObjects); - } - } - - public class Task extends AbstractModel implements Displayable { - private String name; - private Date creationTimeStamp; - public Task(String name) { - this.name = name; - this.creationTimeStamp = new Date(); - } - public String displayString() { - return this.name + ": " + this.creationTimeStamp.getTime(); - } - public Icon icon() { - return null; - } - public String getName() { - return this.name; - } - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(DISPLAY_STRING_PROPERTY, old, name); - } - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.displayString()); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java deleted file mode 100644 index 0407b59a60..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ListSpinnerModelAdapterTests.java +++ /dev/null @@ -1,133 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import javax.swing.SpinnerModel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.ListSpinnerModelAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class ListSpinnerModelAdapterTests extends TestCase { - private WritablePropertyValueModel<Object> valueHolder; - private SpinnerModel spinnerModelAdapter; - boolean eventFired; - private static final String[] VALUE_LIST = {"red", "green", "blue"}; - private static final String DEFAULT_VALUE = VALUE_LIST[0]; - - public ListSpinnerModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.valueHolder = new SimplePropertyValueModel<Object>(DEFAULT_VALUE); - this.spinnerModelAdapter = new ListSpinnerModelAdapter(this.valueHolder, VALUE_LIST) { - @Override - protected PropertyChangeListener buildValueChangeListener() { - return this.buildValueChangeListener_(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSetValueSpinnerModel() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - ListSpinnerModelAdapterTests.this.eventFired = true; - } - }); - assertEquals(DEFAULT_VALUE, this.valueHolder.getValue()); - this.spinnerModelAdapter.setValue(VALUE_LIST[2]); - assertTrue(this.eventFired); - assertEquals(VALUE_LIST[2], this.valueHolder.getValue()); - } - - public void testSetValueValueHolder() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - ListSpinnerModelAdapterTests.this.eventFired = true; - } - }); - assertEquals(DEFAULT_VALUE, this.spinnerModelAdapter.getValue()); - this.valueHolder.setValue(VALUE_LIST[2]); - assertTrue(this.eventFired); - assertEquals(VALUE_LIST[2], this.spinnerModelAdapter.getValue()); - } - - public void testDefaultValue() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - ListSpinnerModelAdapterTests.this.eventFired = true; - } - }); - assertEquals(DEFAULT_VALUE, this.spinnerModelAdapter.getValue()); - - this.valueHolder.setValue(VALUE_LIST[2]); - assertTrue(this.eventFired); - assertEquals(VALUE_LIST[2], this.spinnerModelAdapter.getValue()); - - this.eventFired = false; - this.valueHolder.setValue(null); - assertTrue(this.eventFired); - assertEquals(VALUE_LIST[0], this.spinnerModelAdapter.getValue()); - } - - public void testHasListeners() throws Exception { - SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueHolder; - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.spinnerModelAdapter); - - ChangeListener listener = new TestChangeListener(); - this.spinnerModelAdapter.addChangeListener(listener); - assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasListeners(this.spinnerModelAdapter); - - this.spinnerModelAdapter.removeChangeListener(listener); - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.spinnerModelAdapter); - } - - private void verifyHasNoListeners(SpinnerModel adapter) throws Exception { - assertEquals(0, ((ListSpinnerModelAdapter) adapter).getChangeListeners().length); - } - - private void verifyHasListeners(Object adapter) throws Exception { - assertFalse(((ListSpinnerModelAdapter) adapter).getChangeListeners().length == 0); - } - - - private class TestChangeListener implements ChangeListener { - TestChangeListener() { - super(); - } - public void stateChanged(ChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java deleted file mode 100644 index bc5df140e8..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/NumberSpinnerModelAdapterTests.java +++ /dev/null @@ -1,147 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import javax.swing.SpinnerModel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.NumberSpinnerModelAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class NumberSpinnerModelAdapterTests extends TestCase { - private WritablePropertyValueModel<Number> valueHolder; - private SpinnerModel spinnerModelAdapter; - boolean eventFired; - - public NumberSpinnerModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.valueHolder = new SimplePropertyValueModel<Number>(new Integer(0)); - this.spinnerModelAdapter = new NumberSpinnerModelAdapter(this.valueHolder, -33, 33, 1) { - @Override - protected PropertyChangeListener buildNumberChangeListener() { - return this.buildNumberChangeListener_(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSetValueSpinnerModel() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - NumberSpinnerModelAdapterTests.this.eventFired = true; - } - }); - this.spinnerModelAdapter.setValue(new Integer(5)); - assertTrue(this.eventFired); - assertEquals(new Integer(5), this.valueHolder.getValue()); - } - - public void testSetValueValueHolder() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - NumberSpinnerModelAdapterTests.this.eventFired = true; - } - }); - assertEquals(new Integer(0), this.spinnerModelAdapter.getValue()); - this.valueHolder.setValue(new Integer(7)); - assertTrue(this.eventFired); - assertEquals(new Integer(7), this.spinnerModelAdapter.getValue()); - } - - public void testDefaultValue() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - NumberSpinnerModelAdapterTests.this.eventFired = true; - } - }); - assertEquals(new Integer(0), this.spinnerModelAdapter.getValue()); - this.valueHolder.setValue(null); - assertTrue(this.eventFired); - assertEquals(new Integer(-33), this.spinnerModelAdapter.getValue()); - } - - public void testHasListeners() throws Exception { - SimplePropertyValueModel<Number> localValueHolder = (SimplePropertyValueModel<Number>) this.valueHolder; - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.spinnerModelAdapter); - - ChangeListener listener = new TestChangeListener(); - this.spinnerModelAdapter.addChangeListener(listener); - assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasListeners(this.spinnerModelAdapter); - - this.spinnerModelAdapter.removeChangeListener(listener); - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.spinnerModelAdapter); - } - - private void verifyHasNoListeners(SpinnerModel adapter) throws Exception { - assertEquals(0, ((NumberSpinnerModelAdapter) adapter).getChangeListeners().length); - } - - private void verifyHasListeners(Object adapter) throws Exception { - assertFalse(((NumberSpinnerModelAdapter) adapter).getChangeListeners().length == 0); - } - - public void testNullInitialValue() { - this.valueHolder = new SimplePropertyValueModel<Number>(); - this.spinnerModelAdapter = new NumberSpinnerModelAdapter(this.valueHolder, new Integer(-33), new Integer(33), new Integer(1), new Integer(0)) { - @Override - protected PropertyChangeListener buildNumberChangeListener() { - return this.buildNumberChangeListener_(); - } - }; - - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - NumberSpinnerModelAdapterTests.this.eventFired = true; - } - }); - assertEquals(new Integer(0), this.spinnerModelAdapter.getValue()); - this.valueHolder.setValue(new Integer(7)); - assertTrue(this.eventFired); - assertEquals(new Integer(7), this.spinnerModelAdapter.getValue()); - } - - - // ********** inner class ********** - private class TestChangeListener implements ChangeListener { - TestChangeListener() { - super(); - } - public void stateChanged(ChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ObjectListSelectionModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ObjectListSelectionModelTests.java deleted file mode 100644 index 0d2f73e61d..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ObjectListSelectionModelTests.java +++ /dev/null @@ -1,205 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import javax.swing.DefaultListModel; -import javax.swing.ListModel; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -@SuppressWarnings("nls") -public class ObjectListSelectionModelTests extends TestCase { - private DefaultListModel listModel; - private ObjectListSelectionModel selectionModel; - - public ObjectListSelectionModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.listModel = this.buildListModel(); - this.selectionModel = this.buildSelectionModel(this.listModel); - } - - private DefaultListModel buildListModel() { - DefaultListModel lm = new DefaultListModel(); - lm.addElement("foo"); - lm.addElement("bar"); - lm.addElement("baz"); - return lm; - } - - private ObjectListSelectionModel buildSelectionModel(ListModel lm) { - return new ObjectListSelectionModel(lm); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testListDataListener() { - this.selectionModel.addListSelectionListener(this.buildListSelectionListener()); - this.selectionModel.setSelectionInterval(0, 0); - assertEquals("foo", this.selectionModel.selectedValue()); - this.listModel.set(0, "jar"); - assertEquals("jar", this.selectionModel.selectedValue()); - } - - public void testGetSelectedValue() { - this.selectionModel.setSelectionInterval(0, 0); - assertEquals("foo", this.selectionModel.selectedValue()); - } - - public void testGetSelectedValues() { - this.selectionModel.setSelectionInterval(0, 0); - this.selectionModel.addSelectionInterval(2, 2); - assertEquals(2, this.selectionModel.selectedValues().length); - assertTrue(ArrayTools.contains(this.selectionModel.selectedValues(), "foo")); - assertTrue(ArrayTools.contains(this.selectionModel.selectedValues(), "baz")); - } - - public void testSetSelectedValue() { - this.selectionModel.setSelectedValue("foo"); - assertEquals(0, this.selectionModel.getMinSelectionIndex()); - assertEquals(0, this.selectionModel.getMaxSelectionIndex()); - } - - public void testSetSelectedValues() { - this.selectionModel.setSelectedValues(new Object[] {"foo", "baz"}); - assertEquals(0, this.selectionModel.getMinSelectionIndex()); - assertEquals(2, this.selectionModel.getMaxSelectionIndex()); - } - - public void testAddSelectedValue() { - this.listModel.addElement("joo"); - this.listModel.addElement("jar"); - this.listModel.addElement("jaz"); - this.selectionModel.setSelectedValue("foo"); - this.selectionModel.addSelectedValue("jaz"); - assertEquals(0, this.selectionModel.getMinSelectionIndex()); - assertEquals(5, this.selectionModel.getMaxSelectionIndex()); - assertTrue(this.selectionModel.isSelectedIndex(0)); - assertFalse(this.selectionModel.isSelectedIndex(1)); - assertFalse(this.selectionModel.isSelectedIndex(2)); - assertFalse(this.selectionModel.isSelectedIndex(3)); - assertFalse(this.selectionModel.isSelectedIndex(4)); - assertTrue(this.selectionModel.isSelectedIndex(5)); - } - - public void testAddSelectedValues() { - this.listModel.addElement("joo"); - this.listModel.addElement("jar"); - this.listModel.addElement("jaz"); - this.selectionModel.setSelectedValue("foo"); - this.selectionModel.addSelectedValues(new Object[] {"bar", "jar"}); - assertEquals(0, this.selectionModel.getMinSelectionIndex()); - assertEquals(4, this.selectionModel.getMaxSelectionIndex()); - assertTrue(this.selectionModel.isSelectedIndex(0)); - assertTrue(this.selectionModel.isSelectedIndex(1)); - assertFalse(this.selectionModel.isSelectedIndex(2)); - assertFalse(this.selectionModel.isSelectedIndex(3)); - assertTrue(this.selectionModel.isSelectedIndex(4)); - assertFalse(this.selectionModel.isSelectedIndex(5)); - } - - public void testRemoveSelectedValue() { - this.listModel.addElement("joo"); - this.listModel.addElement("jar"); - this.listModel.addElement("jaz"); - this.selectionModel.setSelectedValues(new Object[] {"foo", "baz", "jar"}); - this.selectionModel.removeSelectedValue("jar"); - assertEquals(0, this.selectionModel.getMinSelectionIndex()); - assertEquals(2, this.selectionModel.getMaxSelectionIndex()); - assertTrue(this.selectionModel.isSelectedIndex(0)); - assertFalse(this.selectionModel.isSelectedIndex(1)); - assertTrue(this.selectionModel.isSelectedIndex(2)); - assertFalse(this.selectionModel.isSelectedIndex(3)); - assertFalse(this.selectionModel.isSelectedIndex(4)); - assertFalse(this.selectionModel.isSelectedIndex(5)); - } - - public void testRemoveSelectedValues() { - this.listModel.addElement("joo"); - this.listModel.addElement("jar"); - this.listModel.addElement("jaz"); - this.selectionModel.setSelectedValues(new Object[] {"foo", "baz", "joo", "jar"}); - this.selectionModel.removeSelectedValues(new Object[] {"foo", "joo"}); - assertEquals(2, this.selectionModel.getMinSelectionIndex()); - assertEquals(4, this.selectionModel.getMaxSelectionIndex()); - assertFalse(this.selectionModel.isSelectedIndex(0)); - assertFalse(this.selectionModel.isSelectedIndex(1)); - assertTrue(this.selectionModel.isSelectedIndex(2)); - assertFalse(this.selectionModel.isSelectedIndex(3)); - assertTrue(this.selectionModel.isSelectedIndex(4)); - assertFalse(this.selectionModel.isSelectedIndex(5)); - } - - public void testGetAnchorSelectedValue() { - this.selectionModel.setAnchorSelectionIndex(1); - assertEquals("bar", this.selectionModel.getAnchorSelectedValue()); - } - - public void testGetLeadSelectedValue() { - this.selectionModel.setSelectedValue("bar"); - assertEquals("bar", this.selectionModel.getLeadSelectedValue()); - this.selectionModel.setSelectedValues(new Object[] {"foo", "baz"}); - assertEquals("baz", this.selectionModel.getLeadSelectedValue()); - } - - public void testGetMinMaxSelectedValue() { - this.listModel.addElement("joo"); - this.listModel.addElement("jar"); - this.listModel.addElement("jaz"); - this.selectionModel.setSelectedValue("foo"); - this.selectionModel.addSelectedValues(new Object[] {"bar", "jar"}); - assertEquals("foo", this.selectionModel.getMinSelectedValue()); - assertEquals("jar", this.selectionModel.getMaxSelectedValue()); - } - - public void testValueIsSelected() { - this.listModel.addElement("joo"); - this.listModel.addElement("jar"); - this.listModel.addElement("jaz"); - this.selectionModel.setSelectedValue("foo"); - this.selectionModel.addSelectedValues(new Object[] {"bar", "jar"}); - assertTrue(this.selectionModel.valueIsSelected("foo")); - assertTrue(this.selectionModel.valueIsSelected("bar")); - assertTrue(this.selectionModel.valueIsSelected("jar")); - assertFalse(this.selectionModel.valueIsSelected("baz")); - } - - public void testHasListeners() throws Exception { - ListSelectionListener listener = this.buildListSelectionListener(); - assertEquals(0, this.listModel.getListDataListeners().length); - this.selectionModel.addListSelectionListener(listener); - assertEquals(1, this.listModel.getListDataListeners().length); - this.selectionModel.removeListSelectionListener(listener); - assertEquals(0, this.listModel.getListDataListeners().length); - } - - private ListSelectionListener buildListSelectionListener() { - return new ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - // do nothing for now... - } - }; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java deleted file mode 100644 index 3a8384c1a7..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/PrimitiveListTreeModelTests.java +++ /dev/null @@ -1,197 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.ListIterator; -import javax.swing.event.TreeModelEvent; -import javax.swing.event.TreeModelListener; -import javax.swing.tree.DefaultMutableTreeNode; -import javax.swing.tree.TreeModel; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyListIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.ListAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.PrimitiveListTreeModel; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class PrimitiveListTreeModelTests extends TestCase { - TestModel testModel; - private TreeModel treeModel; - - public PrimitiveListTreeModelTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.testModel = this.buildTestModel(); - this.treeModel = this.buildTreeModel(); - } - - private TestModel buildTestModel() { - return new TestModel(); - } - - private TreeModel buildTreeModel() { - return new PrimitiveListTreeModel(this.buildListValueModel()) { - @Override - protected void primitiveChanged(int index, Object newValue) { - if ( ! newValue.equals("")) { - PrimitiveListTreeModelTests.this.testModel.replaceName(index, (String) newValue); - } - } - @Override - protected ListChangeListener buildListChangeListener() { - return this.buildListChangeListener_(); - } - }; - } - - private ListValueModel<?> buildListValueModel() { - return new ListAspectAdapter<TestModel, String>(TestModel.NAMES_LIST, this.testModel) { - @Override - protected ListIterator<String> listIterator_() { - return this.subject.names(); - } - @Override - public String get(int index) { - return this.subject.getName(index); - } - @Override - public int size() { - return this.subject.namesSize(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testAddPrimitive() { - this.treeModel.addTreeModelListener(new TestTreeModelListener() { - @Override - public void treeNodesInserted(TreeModelEvent e) { - PrimitiveListTreeModelTests.this.verifyTreeModelEvent(e, new int[] {0}, new String[] {"foo"}); - } - }); - this.testModel.addName("foo"); - } - - public void testRemovePrimitive() { - this.testModel.addName("foo"); - this.testModel.addName("bar"); - this.testModel.addName("baz"); - this.treeModel.addTreeModelListener(new TestTreeModelListener() { - @Override - public void treeNodesRemoved(TreeModelEvent e) { - PrimitiveListTreeModelTests.this.verifyTreeModelEvent(e, new int[] {1}, new String[] {"bar"}); - } - }); - String name = this.testModel.removeName(1); - assertEquals("bar", name); - } - - public void testReplacePrimitive() { - this.testModel.addName("foo"); - this.testModel.addName("bar"); - this.testModel.addName("baz"); - this.treeModel.addTreeModelListener(new TestTreeModelListener() { - @Override - public void treeNodesChanged(TreeModelEvent e) { - PrimitiveListTreeModelTests.this.verifyTreeModelEvent(e, new int[] {1}, new String[] {"jar"}); - } - }); - String name = this.testModel.replaceName(1, "jar"); - assertEquals("bar", name); - } - - void verifyTreeModelEvent(TreeModelEvent e, int[] expectedChildIndices, String[] expectedNames) { - assertTrue(Arrays.equals(expectedChildIndices, e.getChildIndices())); - Object[] actualChildren = e.getChildren(); - assertEquals(expectedNames.length, actualChildren.length); - for (int i = 0; i < expectedNames.length; i++) { - DefaultMutableTreeNode node = (DefaultMutableTreeNode) actualChildren[i]; - assertEquals(expectedNames[i], node.getUserObject()); - } - assertEquals(1, e.getPath().length); - assertEquals(this.treeModel.getRoot(), e.getPath()[0]); - assertEquals(this.treeModel, e.getSource()); - } - - -// ********** inner classes ********** - - private class TestModel extends AbstractModel { - private final List<String> names; - static final String NAMES_LIST = "names"; - - TestModel() { - super(); - this.names = new ArrayList<String>(); - } - - public ListIterator<String> names() { - return new ReadOnlyListIterator<String>(this.names); - } - public int namesSize() { - return this.names.size(); - } - public String getName(int index) { - return this.names.get(index); - } - public void addName(int index, String name) { - this.addItemToList(index, name, this.names, NAMES_LIST); - } - public void addName(String name) { - this.addName(this.namesSize(), name); - } - public void addNames(int index, List<String> list) { - this.addItemsToList(index, this.names, list, NAMES_LIST); - } - public void addNames(List<String> list) { - this.addNames(this.namesSize(), list); - } - public String removeName(int index) { - return this.removeItemFromList(index, this.names, NAMES_LIST); - } - public List<String> removeNames(int index, int length) { - return this.removeItemsFromList(index, length, this.names, NAMES_LIST); - } - public String replaceName(int index, String newName) { - return this.setItemInList(index, newName, this.names, NAMES_LIST); - } - } - - - public class TestTreeModelListener implements TreeModelListener { - public void treeNodesChanged(TreeModelEvent e) { - fail("unexpected event"); - } - public void treeNodesInserted(TreeModelEvent e) { - fail("unexpected event"); - } - public void treeNodesRemoved(TreeModelEvent e) { - fail("unexpected event"); - } - public void treeStructureChanged(TreeModelEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java deleted file mode 100644 index 0c4bbeb9f3..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterTests.java +++ /dev/null @@ -1,229 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import javax.swing.ButtonModel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import javax.swing.event.EventListenerList; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.RadioButtonModelAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class RadioButtonModelAdapterTests extends TestCase { - private WritablePropertyValueModel<Object> valueHolder; - - private ButtonModel redButtonModelAdapter; - private ChangeListener redListener; - boolean redEventFired; - - private ButtonModel greenButtonModelAdapter; - private ChangeListener greenListener; - boolean greenEventFired; - - private ButtonModel blueButtonModelAdapter; - private ChangeListener blueListener; - boolean blueEventFired; - -// private ButtonGroup buttonGroup; // DO NOT use a ButtonGroup - - private static final String RED = "red"; - private static final String GREEN = "green"; - private static final String BLUE = "blue"; - - public RadioButtonModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.valueHolder = new SimplePropertyValueModel<Object>(null); -// buttonGroup = new ButtonGroup(); - - this.redButtonModelAdapter = this.buildButtonModel(this.valueHolder, RED); -// this.redButtonModelAdapter.setGroup(buttonGroup); - this.redListener = new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - RadioButtonModelAdapterTests.this.redEventFired = true; - } - }; - - this.greenButtonModelAdapter = this.buildButtonModel(this.valueHolder, GREEN); -// this.greenButtonModelAdapter.setGroup(buttonGroup); - this.greenListener = new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - RadioButtonModelAdapterTests.this.greenEventFired = true; - } - }; - - this.blueButtonModelAdapter = this.buildButtonModel(this.valueHolder, BLUE); -// this.blueButtonModelAdapter.setGroup(buttonGroup); - this.blueListener = new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - RadioButtonModelAdapterTests.this.blueEventFired = true; - } - }; - - this.clearFlags(); - } - - private ButtonModel buildButtonModel(WritablePropertyValueModel<Object> pvm, Object buttonValue) { - return new RadioButtonModelAdapter(pvm, buttonValue) { - @Override - protected PropertyChangeListener buildBooleanChangeListener() { - return this.buildBooleanChangeListener_(); - } - }; - } - - private void listenToModelAdapters() { - this.redButtonModelAdapter.addChangeListener(this.redListener); - this.greenButtonModelAdapter.addChangeListener(this.greenListener); - this.blueButtonModelAdapter.addChangeListener(this.blueListener); - } - - private void clearFlags() { - this.redEventFired = false; - this.greenEventFired = false; - this.blueEventFired = false; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSetSelected() throws Exception { - this.listenToModelAdapters(); - - this.greenButtonModelAdapter.setSelected(true); - assertFalse(this.redEventFired); - assertTrue(this.greenEventFired); - assertFalse(this.blueEventFired); - assertEquals(GREEN, this.valueHolder.getValue()); - - this.clearFlags(); - this.blueButtonModelAdapter.setSelected(true); - assertFalse(this.redEventFired); - assertTrue(this.greenEventFired); - assertTrue(this.blueEventFired); - assertEquals(BLUE, this.valueHolder.getValue()); - - this.clearFlags(); - this.redButtonModelAdapter.setSelected(true); - assertTrue(this.redEventFired); - assertFalse(this.greenEventFired); - assertTrue(this.blueEventFired); - assertEquals(RED, this.valueHolder.getValue()); - } - - public void testSetValue() throws Exception { - this.listenToModelAdapters(); - - this.greenButtonModelAdapter.setSelected(true); - - this.clearFlags(); - this.valueHolder.setValue(BLUE); - assertFalse(this.redEventFired); - assertTrue(this.greenEventFired); - assertTrue(this.blueEventFired); - assertFalse(this.redButtonModelAdapter.isSelected()); - assertFalse(this.greenButtonModelAdapter.isSelected()); - assertTrue(this.blueButtonModelAdapter.isSelected()); - - this.clearFlags(); - this.valueHolder.setValue(RED); - assertTrue(this.redEventFired); - assertFalse(this.greenEventFired); - assertTrue(this.blueEventFired); - assertTrue(this.redButtonModelAdapter.isSelected()); - assertFalse(this.greenButtonModelAdapter.isSelected()); - assertFalse(this.blueButtonModelAdapter.isSelected()); - } - - public void testDefaultValue() throws Exception { - this.listenToModelAdapters(); - - this.valueHolder.setValue(GREEN); - assertFalse(this.redButtonModelAdapter.isSelected()); - assertTrue(this.greenButtonModelAdapter.isSelected()); - assertFalse(this.blueButtonModelAdapter.isSelected()); - - this.clearFlags(); - this.valueHolder.setValue(null); - assertFalse(this.redEventFired); - assertTrue(this.greenEventFired); - assertFalse(this.blueEventFired); - assertFalse(this.redButtonModelAdapter.isSelected()); - assertFalse(this.greenButtonModelAdapter.isSelected()); - assertFalse(this.blueButtonModelAdapter.isSelected()); - - this.clearFlags(); - this.valueHolder.setValue(BLUE); - assertFalse(this.redEventFired); - assertFalse(this.greenEventFired); - assertTrue(this.blueEventFired); - assertFalse(this.redButtonModelAdapter.isSelected()); - assertFalse(this.greenButtonModelAdapter.isSelected()); - assertTrue(this.blueButtonModelAdapter.isSelected()); - } - - public void testHasListeners() throws Exception { - SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueHolder; - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.redButtonModelAdapter); - this.verifyHasNoListeners(this.greenButtonModelAdapter); - this.verifyHasNoListeners(this.blueButtonModelAdapter); - - ChangeListener listener = new TestChangeListener(); - this.redButtonModelAdapter.addChangeListener(listener); - assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasListeners(this.redButtonModelAdapter); - this.verifyHasNoListeners(this.greenButtonModelAdapter); - this.verifyHasNoListeners(this.blueButtonModelAdapter); - - this.redButtonModelAdapter.removeChangeListener(listener); - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.redButtonModelAdapter); - this.verifyHasNoListeners(this.greenButtonModelAdapter); - this.verifyHasNoListeners(this.blueButtonModelAdapter); - } - - private void verifyHasNoListeners(Object model) throws Exception { - EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList"); - assertEquals(0, listenerList.getListenerList().length); - } - - private void verifyHasListeners(Object model) throws Exception { - EventListenerList listenerList = (EventListenerList) ClassTools.fieldValue(model, "listenerList"); - assertFalse(listenerList.getListenerList().length == 0); - } - - - private class TestChangeListener implements ChangeListener { - TestChangeListener() { - super(); - } - public void stateChanged(ChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java deleted file mode 100644 index b4373dede7..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/RadioButtonModelAdapterUITest.java +++ /dev/null @@ -1,260 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ButtonModel; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JRadioButton; -import javax.swing.WindowConstants; - -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.RadioButtonModelAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - - -/** - * Play around with a set of radio buttons. - */ -@SuppressWarnings("nls") -public class RadioButtonModelAdapterUITest { - - private TestModel testModel; - private WritablePropertyValueModel<TestModel> testModelHolder; - private WritablePropertyValueModel<Object> colorHolder; - private ButtonModel redButtonModel; - private ButtonModel greenButtonModel; - private ButtonModel blueButtonModel; - - public static void main(String[] args) throws Exception { - new RadioButtonModelAdapterUITest().exec(); - } - - private RadioButtonModelAdapterUITest() { - super(); - } - - 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.openWindow(); - } - - private WritablePropertyValueModel<Object> buildColorHolder(PropertyValueModel<TestModel> subjectHolder) { - return new PropertyAspectAdapter<TestModel, Object>(subjectHolder, TestModel.COLOR_PROPERTY) { - @Override - protected Object buildValue_() { - return this.subject.getColor(); - } - @Override - protected void setValue_(Object value) { - this.subject.setColor((String) value); - } - }; - } - - private ButtonModel buildRadioButtonModelAdapter(WritablePropertyValueModel<Object> colorPVM, String color) { - return new RadioButtonModelAdapter(colorPVM, color); - } - - private void openWindow() { - JFrame window = new JFrame(this.getClass().getName()); - window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - window.addWindowListener(this.buildWindowListener()); - window.getContentPane().add(this.buildMainPanel(), "Center"); - window.setSize(400, 100); - window.setLocation(200, 200); - window.setVisible(true); - } - - private WindowListener buildWindowListener() { - return new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - System.exit(0); - } - }; - } - - private Component buildMainPanel() { - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(this.buildRadioButtonPanel(), BorderLayout.NORTH); - mainPanel.add(this.buildControlPanel(), BorderLayout.SOUTH); - return mainPanel; - } - - private Component buildRadioButtonPanel() { - JPanel taskListPanel = new JPanel(new GridLayout(1, 0)); - taskListPanel.add(this.buildRedRadioButton()); - taskListPanel.add(this.buildGreenRadioButton()); - taskListPanel.add(this.buildBlueRadioButton()); - return taskListPanel; - } - - private JRadioButton buildRedRadioButton() { - JRadioButton radioButton = new JRadioButton(); - radioButton.setText("red"); - radioButton.setModel(this.redButtonModel); - return radioButton; - } - - private JRadioButton buildGreenRadioButton() { - JRadioButton radioButton = new JRadioButton(); - radioButton.setText("green"); - radioButton.setModel(this.greenButtonModel); - return radioButton; - } - - private JRadioButton buildBlueRadioButton() { - JRadioButton radioButton = new JRadioButton(); - radioButton.setText("blue"); - radioButton.setModel(this.blueButtonModel); - return radioButton; - } - - private Component buildControlPanel() { - JPanel controlPanel = new JPanel(new GridLayout(1, 0)); - controlPanel.add(this.buildResetColorButton()); - controlPanel.add(this.buildClearModelButton()); - controlPanel.add(this.buildRestoreModelButton()); - controlPanel.add(this.buildPrintModelButton()); - return controlPanel; - } - - private JButton buildResetColorButton() { - return new JButton(this.buildResetColorAction()); - } - - private Action buildResetColorAction() { - Action action = new AbstractAction("reset color") { - public void actionPerformed(ActionEvent event) { - RadioButtonModelAdapterUITest.this.resetColor(); - } - }; - action.setEnabled(true); - return action; - } - - void resetColor() { - this.testModel.setColor(TestModel.DEFAULT_COLOR); - } - - private JButton buildClearModelButton() { - return new JButton(this.buildClearModelAction()); - } - - private Action buildClearModelAction() { - Action action = new AbstractAction("clear model") { - public void actionPerformed(ActionEvent event) { - RadioButtonModelAdapterUITest.this.clearModel(); - } - }; - action.setEnabled(true); - return action; - } - - void clearModel() { - this.testModelHolder.setValue(null); - } - - private JButton buildRestoreModelButton() { - return new JButton(this.buildRestoreModelAction()); - } - - private Action buildRestoreModelAction() { - Action action = new AbstractAction("restore model") { - public void actionPerformed(ActionEvent event) { - RadioButtonModelAdapterUITest.this.restoreModel(); - } - }; - action.setEnabled(true); - return action; - } - - void restoreModel() { - this.testModelHolder.setValue(this.testModel); - } - - private JButton buildPrintModelButton() { - return new JButton(this.buildPrintModelAction()); - } - - private Action buildPrintModelAction() { - Action action = new AbstractAction("print model") { - public void actionPerformed(ActionEvent event) { - RadioButtonModelAdapterUITest.this.printModel(); - } - }; - action.setEnabled(true); - return action; - } - - void printModel() { - System.out.println(this.testModel); - } - - - private static class TestModel extends AbstractModel { - private String color; - public static final String COLOR_PROPERTY = "color"; - public static final String RED = "red"; - public static final String GREEN = "green"; - public static final String BLUE = "blue"; - public static final String DEFAULT_COLOR = RED; - public static final String[] VALID_COLORS = { - RED, - GREEN, - BLUE - }; - - public TestModel() { - this(DEFAULT_COLOR); - } - public TestModel(String color) { - this.color = color; - } - public String getColor() { - return this.color; - } - public void setColor(String color) { - if ( ! ArrayTools.contains(VALID_COLORS, color)) { - throw new IllegalArgumentException(color); - } - Object old = this.color; - this.color = color; - this.firePropertyChanged(COLOR_PROPERTY, old, color); - } - @Override - public String toString() { - return "TestModel(" + this.color + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ReadOnlyTableModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ReadOnlyTableModelAdapterUITest.java deleted file mode 100644 index 3bfb66f4ba..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/ReadOnlyTableModelAdapterUITest.java +++ /dev/null @@ -1,39 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import org.eclipse.jpt.utility.internal.model.value.swing.ColumnAdapter; -import org.eclipse.jpt.utility.tests.internal.model.value.swing.TableModelAdapterTests.PersonColumnAdapter; - -/** - * Make it easy to test the table model adapter and - * renderers without any editing allowed. - */ -public class ReadOnlyTableModelAdapterUITest extends TableModelAdapterUITest { - - public static void main(String[] args) throws Exception { - new ReadOnlyTableModelAdapterUITest().exec(args); - } - - protected ReadOnlyTableModelAdapterUITest() { - super(); - } - - @Override - protected ColumnAdapter buildColumnAdapter() { - return new PersonColumnAdapter() { - @Override - public boolean columnIsEditable(int index) { - return false; - } - }; - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java deleted file mode 100644 index c8bb0234ef..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterTests.java +++ /dev/null @@ -1,117 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import javax.swing.SpinnerModel; -import javax.swing.event.ChangeEvent; -import javax.swing.event.ChangeListener; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.SpinnerModelAdapter; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -public class SpinnerModelAdapterTests extends TestCase { - private WritablePropertyValueModel<Object> valueHolder; - SpinnerModel spinnerModelAdapter; - boolean eventFired; - - public SpinnerModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.valueHolder = new SimplePropertyValueModel<Object>(new Integer(0)); - this.spinnerModelAdapter = new SpinnerModelAdapter(this.valueHolder) { - @Override - protected PropertyChangeListener buildValueListener() { - return this.buildValueListener_(); - } - }; - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testSetValueSpinnerModel() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - SpinnerModelAdapterTests.this.eventFired = true; - assertEquals(SpinnerModelAdapterTests.this.spinnerModelAdapter, e.getSource()); - } - }); - this.spinnerModelAdapter.setValue(new Integer(5)); - assertTrue(this.eventFired); - assertEquals(new Integer(5), this.valueHolder.getValue()); - } - - public void testSetValueValueHolder() throws Exception { - this.eventFired = false; - this.spinnerModelAdapter.addChangeListener(new TestChangeListener() { - @Override - public void stateChanged(ChangeEvent e) { - SpinnerModelAdapterTests.this.eventFired = true; - assertEquals(SpinnerModelAdapterTests.this.spinnerModelAdapter, e.getSource()); - } - }); - assertEquals(new Integer(0), this.spinnerModelAdapter.getValue()); - this.valueHolder.setValue(new Integer(7)); - assertTrue(this.eventFired); - assertEquals(new Integer(7), this.spinnerModelAdapter.getValue()); - } - - public void testHasListeners() throws Exception { - SimplePropertyValueModel<Object> localValueHolder = (SimplePropertyValueModel<Object>) this.valueHolder; - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.spinnerModelAdapter); - - ChangeListener listener = new TestChangeListener(); - this.spinnerModelAdapter.addChangeListener(listener); - assertTrue(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasListeners(this.spinnerModelAdapter); - - this.spinnerModelAdapter.removeChangeListener(listener); - assertFalse(localValueHolder.hasAnyPropertyChangeListeners(PropertyValueModel.VALUE)); - this.verifyHasNoListeners(this.spinnerModelAdapter); - } - - private void verifyHasNoListeners(Object adapter) throws Exception { - Object delegate = ClassTools.fieldValue(adapter, "delegate"); - Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getChangeListeners"); - assertEquals(0, listeners.length); - } - - private void verifyHasListeners(Object adapter) throws Exception { - Object delegate = ClassTools.fieldValue(adapter, "delegate"); - Object[] listeners = (Object[]) ClassTools.executeMethod(delegate, "getChangeListeners"); - assertFalse(listeners.length == 0); - } - - - private class TestChangeListener implements ChangeListener { - TestChangeListener() { - super(); - } - public void stateChanged(ChangeEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterUITest.java deleted file mode 100644 index c8ebb05b21..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/SpinnerModelAdapterUITest.java +++ /dev/null @@ -1,344 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.util.Calendar; -import java.util.Date; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JSpinner; -import javax.swing.SpinnerModel; -import javax.swing.WindowConstants; - -import org.eclipse.jpt.utility.internal.ArrayTools; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.DateSpinnerModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.ListSpinnerModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.NumberSpinnerModelAdapter; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -/** - * Play around with a set of spinners. - */ -@SuppressWarnings("nls") -public class SpinnerModelAdapterUITest { - - private TestModel testModel; - private WritablePropertyValueModel<TestModel> testModelHolder; - - private WritablePropertyValueModel<Object> birthDateHolder; - private SpinnerModel birthDateSpinnerModel; - - private WritablePropertyValueModel<Number> ageHolder; - private SpinnerModel ageSpinnerModel; - - private WritablePropertyValueModel<Object> eyeColorHolder; - private SpinnerModel eyeColorSpinnerModel; - - - public static void main(String[] args) throws Exception { - new SpinnerModelAdapterUITest().exec(); - } - - private SpinnerModelAdapterUITest() { - super(); - } - - private void exec() throws Exception { - this.testModel = new TestModel(); - this.testModelHolder = new SimplePropertyValueModel<TestModel>(this.testModel); - - this.birthDateHolder = this.buildBirthDateHolder(this.testModelHolder); - this.birthDateSpinnerModel = this.buildBirthDateSpinnerModel(this.birthDateHolder); - - this.ageHolder = this.buildAgeHolder(this.testModelHolder); - this.ageSpinnerModel = this.buildAgeSpinnerModel(this.ageHolder); - - this.eyeColorHolder = this.buildEyeColorHolder(this.testModelHolder); - this.eyeColorSpinnerModel = this.buildEyeColorSpinnerModel(this.eyeColorHolder); - - this.openWindow(); - } - - private WritablePropertyValueModel<Object> buildBirthDateHolder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, Object>(vm, TestModel.BIRTH_DATE_PROPERTY) { - @Override - protected Object buildValue_() { - return this.subject.getBirthDate(); - } - @Override - protected void setValue_(Object value) { - this.subject.setBirthDate((Date) value); - } - }; - } - - private SpinnerModel buildBirthDateSpinnerModel(WritablePropertyValueModel<Object> valueHolder) { - return new DateSpinnerModelAdapter(valueHolder); - } - - private WritablePropertyValueModel<Number> buildAgeHolder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, Number>(vm, TestModel.AGE_PROPERTY) { - @Override - protected Number buildValue_() { - return new Integer(this.subject.getAge()); - } - @Override - protected void setValue_(Number value) { - this.subject.setAge(value.intValue()); - } - }; - } - - private SpinnerModel buildAgeSpinnerModel(WritablePropertyValueModel<Number> valueHolder) { - return new NumberSpinnerModelAdapter(valueHolder, valueHolder.getValue().intValue(), TestModel.MIN_AGE, TestModel.MAX_AGE, 1); - } - - private WritablePropertyValueModel<Object> buildEyeColorHolder(PropertyValueModel<TestModel> vm) { - return new PropertyAspectAdapter<TestModel, Object>(vm, TestModel.EYE_COLOR_PROPERTY) { - @Override - protected Object buildValue_() { - return this.subject.getEyeColor(); - } - @Override - protected void setValue_(Object value) { - this.subject.setEyeColor((String) value); - } - }; - } - - private SpinnerModel buildEyeColorSpinnerModel(WritablePropertyValueModel<Object> valueHolder) { - return new ListSpinnerModelAdapter(valueHolder, TestModel.VALID_EYE_COLORS); - } - - private void openWindow() { - JFrame window = new JFrame(this.getClass().getName()); - window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - window.addWindowListener(this.buildWindowListener()); - window.getContentPane().add(this.buildMainPanel(), "Center"); - window.setSize(600, 100); - window.setVisible(true); - } - - private WindowListener buildWindowListener() { - return new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - System.exit(0); - } - }; - } - - private Component buildMainPanel() { - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(this.buildSpinnerPanel(), BorderLayout.NORTH); - mainPanel.add(this.buildControlPanel(), BorderLayout.SOUTH); - return mainPanel; - } - - private Component buildSpinnerPanel() { - JPanel taskListPanel = new JPanel(new GridLayout(1, 0)); - taskListPanel.add(this.buildBirthDateSpinner()); - taskListPanel.add(this.buildAgeSpinner()); - taskListPanel.add(this.buildEyeColorSpinner()); - return taskListPanel; - } - - private JSpinner buildBirthDateSpinner() { - return new JSpinner(this.birthDateSpinnerModel); - } - - private JSpinner buildAgeSpinner() { - return new JSpinner(this.ageSpinnerModel); - } - - private JSpinner buildEyeColorSpinner() { - return new JSpinner(this.eyeColorSpinnerModel); - } - - private Component buildControlPanel() { - JPanel controlPanel = new JPanel(new GridLayout(1, 0)); - controlPanel.add(this.buildResetModelButton()); - controlPanel.add(this.buildClearModelButton()); - controlPanel.add(this.buildRestoreModelButton()); - controlPanel.add(this.buildPrintModelButton()); - return controlPanel; - } - - private JButton buildResetModelButton() { - return new JButton(this.buildResetModelAction()); - } - - private Action buildResetModelAction() { - Action action = new AbstractAction("reset model") { - public void actionPerformed(ActionEvent event) { - SpinnerModelAdapterUITest.this.resetModel(); - } - }; - action.setEnabled(true); - return action; - } - - void resetModel() { - this.testModel.setBirthDate(TestModel.DEFAULT_BIRTH_DATE); - this.testModel.setEyeColor(TestModel.DEFAULT_EYE_COLOR); - } - - private JButton buildClearModelButton() { - return new JButton(this.buildClearModelAction()); - } - - private Action buildClearModelAction() { - Action action = new AbstractAction("clear model") { - public void actionPerformed(ActionEvent event) { - SpinnerModelAdapterUITest.this.clearModel(); - } - }; - action.setEnabled(true); - return action; - } - - void clearModel() { - this.testModelHolder.setValue(null); - } - - private JButton buildRestoreModelButton() { - return new JButton(this.buildRestoreModelAction()); - } - - private Action buildRestoreModelAction() { - Action action = new AbstractAction("restore model") { - public void actionPerformed(ActionEvent event) { - SpinnerModelAdapterUITest.this.restoreModel(); - } - }; - action.setEnabled(true); - return action; - } - - void restoreModel() { - this.testModelHolder.setValue(this.testModel); - } - - private JButton buildPrintModelButton() { - return new JButton(this.buildPrintModelAction()); - } - - private Action buildPrintModelAction() { - Action action = new AbstractAction("print model") { - public void actionPerformed(ActionEvent event) { - SpinnerModelAdapterUITest.this.printModel(); - } - }; - action.setEnabled(true); - return action; - } - - void printModel() { - System.out.println("birth date: " + this.testModel.getBirthDate()); - System.out.println("age: " + this.testModel.getAge()); - System.out.println("eyes: " + this.testModel.getEyeColor()); - } - - - static class TestModel extends AbstractModel { - private Calendar birthCal = Calendar.getInstance(); - // "virtual" properties - public static final String BIRTH_DATE_PROPERTY = "birthDate"; - public static final String AGE_PROPERTY = "age"; - public static final Date DEFAULT_BIRTH_DATE = new Date(); - public static final int DEFAULT_AGE = 0; - public static final int MIN_AGE = 0; - public static final int MAX_AGE = 150; - private String eyeColor; - public static final String EYE_COLOR_PROPERTY = "eyeColor"; - public static final String[] VALID_EYE_COLORS = {"blue", "brown", "green", "hazel", "pink"}; - public static final String DEFAULT_EYE_COLOR = VALID_EYE_COLORS[3]; - - TestModel() { - this(DEFAULT_BIRTH_DATE, DEFAULT_EYE_COLOR); - } - public TestModel(Date birthDate, String eyeColor) { - this.setBirthDate(birthDate); - this.setEyeColor(eyeColor); - } - public Date getBirthDate() { - return (Date) this.birthCal.getTime().clone(); - } - public void setBirthDate(Date birthDate) { - Date oldBirthDate = this.getBirthDate(); - int oldAge = this.getAge(); - this.birthCal.setTimeInMillis(birthDate.getTime()); - int newAge = this.getAge(); - if (newAge < MIN_AGE || newAge > MAX_AGE) { - throw new IllegalArgumentException(birthDate.toString()); - } - this.firePropertyChanged(BIRTH_DATE_PROPERTY, oldBirthDate, this.getBirthDate()); - this.firePropertyChanged(AGE_PROPERTY, oldAge, newAge); - } - public int getAge() { - Calendar currentCal = Calendar.getInstance(); - int age = currentCal.get(Calendar.YEAR) - this.birthCal.get(Calendar.YEAR); - if (currentCal.get(Calendar.MONTH) < this.birthCal.get(Calendar.MONTH)) { - age--; - } else if (currentCal.get(Calendar.MONTH) == this.birthCal.get(Calendar.MONTH)) { - if (currentCal.get(Calendar.DAY_OF_MONTH) < this.birthCal.get(Calendar.DAY_OF_MONTH)) { - age--; - } - } - return age; - } - public void setAge(int newAge) { - if (newAge < MIN_AGE || newAge > MAX_AGE) { - throw new IllegalArgumentException(String.valueOf(newAge)); - } - - int oldAge = this.getAge(); - int delta = newAge - oldAge; - - Calendar newBirthCal = Calendar.getInstance(); - newBirthCal.setTimeInMillis(this.birthCal.getTime().getTime()); - // if the age increased, the birth date must be "decreased"; and vice versa - newBirthCal.set(Calendar.YEAR, newBirthCal.get(Calendar.YEAR) - delta); - this.setBirthDate(newBirthCal.getTime()); - } - public String getEyeColor() { - return this.eyeColor; - } - public void setEyeColor(String eyeColor) { - if ( ! ArrayTools.contains(VALID_EYE_COLORS, eyeColor)) { - throw new IllegalArgumentException(eyeColor); - } - Object old = this.eyeColor; - this.eyeColor = eyeColor; - this.firePropertyChanged(EYE_COLOR_PROPERTY, old, eyeColor); - } - @Override - public String toString() { - return "TestModel(birth: " + this.getBirthDate() + " - eyes: " + this.eyeColor + ")"; - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java deleted file mode 100644 index c08467d97d..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterTests.java +++ /dev/null @@ -1,643 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.text.DateFormat; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collection; -import java.util.Date; -import java.util.Iterator; -import java.util.List; -import javax.swing.event.TableModelEvent; -import javax.swing.event.TableModelListener; -import junit.framework.TestCase; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.CloneIterator; -import org.eclipse.jpt.utility.internal.iterators.TransformationIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.ColumnAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.TableModelAdapter; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.TestTools; - -/** - * - */ -public class TableModelAdapterTests extends TestCase { - private Crowd crowd; - TableModelEvent event; - - public TableModelAdapterTests(String name) { - super(name); - } - - @Override - protected void setUp() throws Exception { - super.setUp(); - this.crowd = this.buildCrowd(); - } - - @Override - protected void tearDown() throws Exception { - TestTools.clear(this); - super.tearDown(); - } - - public void testGetRowCount() throws Exception { - TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter(); - assertEquals(0, tableModelAdapter.getRowCount()); - // we need to add a listener to wake up the adapter - tableModelAdapter.addTableModelListener(this.buildTableModelListener()); - assertEquals(this.crowd.peopleSize(), tableModelAdapter.getRowCount()); - } - - public void testGetColumnCount() throws Exception { - TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter(); - assertEquals(PersonColumnAdapter.COLUMN_COUNT, tableModelAdapter.getColumnCount()); - } - - public void testGetValueAt() throws Exception { - TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter(); - tableModelAdapter.addTableModelListener(this.buildTableModelListener()); - - List<String> sortedNames = this.sortedNames(); - for (int i = 0; i < this.crowd.peopleSize(); i++) { - assertEquals(sortedNames.get(i), tableModelAdapter.getValueAt(i, PersonColumnAdapter.NAME_COLUMN)); - } - } - - public void testSetValueAt() throws Exception { - TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter(); - this.event = null; - tableModelAdapter.addTableModelListener(new TestTableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { - TableModelAdapterTests.this.event = e; - } - }); - - Person person = this.crowd.personNamed("Gollum"); - assertEquals(Person.EYE_COLOR_BLUE, person.getEyeColor()); - assertFalse(person.isEvil()); - assertEquals(0, person.getRank()); - - for (int i = 0; i < tableModelAdapter.getRowCount(); i++) { - if (tableModelAdapter.getValueAt(i, PersonColumnAdapter.NAME_COLUMN).equals("Gollum")) { - tableModelAdapter.setValueAt(Person.EYE_COLOR_HAZEL, i, PersonColumnAdapter.EYE_COLOR_COLUMN); - tableModelAdapter.setValueAt(Boolean.TRUE, i, PersonColumnAdapter.EVIL_COLUMN); - tableModelAdapter.setValueAt(new Integer(-1), i, PersonColumnAdapter.RANK_COLUMN); - break; - } - } - assertNotNull(this.event); - assertEquals(Person.EYE_COLOR_HAZEL, person.getEyeColor()); - assertTrue(person.isEvil()); - assertEquals(-1, person.getRank()); - } - - public void testAddRow() throws Exception { - TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter(); - this.event = null; - tableModelAdapter.addTableModelListener(this.buildSingleEventListener()); - // add a person to the end of the list so we only trigger one event - this.crowd.addPerson("Zzzzz"); - assertNotNull(this.event); - assertEquals(TableModelEvent.INSERT, this.event.getType()); - assertEquals(TableModelEvent.ALL_COLUMNS, this.event.getColumn()); - } - - public void testRemoveRow() throws Exception { - TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter(); - this.event = null; - tableModelAdapter.addTableModelListener(this.buildSingleEventListener()); - // removing a person should only trigger one event, since a re-sort is not needed - this.crowd.removePerson(this.crowd.personNamed("Gollum")); - assertNotNull(this.event); - assertEquals(TableModelEvent.DELETE, this.event.getType()); - assertEquals(TableModelEvent.ALL_COLUMNS, this.event.getColumn()); - } - - public void testChangeCell() throws Exception { - TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter(); - this.event = null; - tableModelAdapter.addTableModelListener(this.buildSingleEventListener()); - // add a person to the end of the list so we only trigger one event - Person person = this.crowd.personNamed("Gollum"); - person.setEvil(true); - assertNotNull(this.event); - assertEquals(TableModelEvent.UPDATE, this.event.getType()); - assertEquals(PersonColumnAdapter.EVIL_COLUMN, this.event.getColumn()); - } - - public void testLazyListListener() throws Exception { - TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter(); - TableModelListener listener = this.buildTableModelListener(); - assertTrue(this.crowd.hasNoCollectionChangeListeners(Crowd.PEOPLE_COLLECTION)); - tableModelAdapter.addTableModelListener(listener); - assertTrue(this.crowd.hasAnyCollectionChangeListeners(Crowd.PEOPLE_COLLECTION)); - tableModelAdapter.removeTableModelListener(listener); - assertTrue(this.crowd.hasNoCollectionChangeListeners(Crowd.PEOPLE_COLLECTION)); - } - - public void testLazyCellListener() throws Exception { - TableModelAdapter<Person> tableModelAdapter = this.buildTableModelAdapter(); - TableModelListener listener = this.buildTableModelListener(); - Person person = this.crowd.personNamed("Gollum"); - assertTrue(person.hasNoPropertyChangeListeners(Person.NAME_PROPERTY)); - assertTrue(person.hasNoPropertyChangeListeners(Person.BIRTH_DATE_PROPERTY)); - assertTrue(person.hasNoPropertyChangeListeners(Person.EYE_COLOR_PROPERTY)); - assertTrue(person.hasNoPropertyChangeListeners(Person.EVIL_PROPERTY)); - assertTrue(person.hasNoPropertyChangeListeners(Person.RANK_PROPERTY)); - - tableModelAdapter.addTableModelListener(listener); - assertTrue(person.hasAnyPropertyChangeListeners(Person.NAME_PROPERTY)); - assertTrue(person.hasAnyPropertyChangeListeners(Person.BIRTH_DATE_PROPERTY)); - assertTrue(person.hasAnyPropertyChangeListeners(Person.EYE_COLOR_PROPERTY)); - assertTrue(person.hasAnyPropertyChangeListeners(Person.EVIL_PROPERTY)); - assertTrue(person.hasAnyPropertyChangeListeners(Person.RANK_PROPERTY)); - - tableModelAdapter.removeTableModelListener(listener); - assertTrue(person.hasNoPropertyChangeListeners(Person.NAME_PROPERTY)); - assertTrue(person.hasNoPropertyChangeListeners(Person.BIRTH_DATE_PROPERTY)); - assertTrue(person.hasNoPropertyChangeListeners(Person.EYE_COLOR_PROPERTY)); - assertTrue(person.hasNoPropertyChangeListeners(Person.EVIL_PROPERTY)); - assertTrue(person.hasNoPropertyChangeListeners(Person.RANK_PROPERTY)); - } - - private TableModelAdapter<Person> buildTableModelAdapter() { - return new TableModelAdapter<Person>(this.buildSortedPeopleAdapter(), this.buildColumnAdapter()) { - @Override - protected PropertyChangeListener buildCellListener() { - return this.buildCellListener_(); - } - @Override - protected ListChangeListener buildListChangeListener() { - return this.buildListChangeListener_(); - } - }; - } - - private ListValueModel<Person> buildSortedPeopleAdapter() { - return new SortedListValueModelAdapter<Person>(this.buildPeopleAdapter()); - } - - private CollectionValueModel<Person> buildPeopleAdapter() { - return new CollectionAspectAdapter<Crowd, Person>(Crowd.PEOPLE_COLLECTION, this.crowd) { - @Override - protected Iterator<Person> iterator_() { - return this.subject.people(); - } - @Override - protected int size_() { - return this.subject.peopleSize(); - } - }; - } - - private Crowd buildCrowd() { - Crowd result = new Crowd(); - result.addPerson("Bilbo"); - result.addPerson("Gollum"); - result.addPerson("Frodo"); - result.addPerson("Samwise"); - return result; - } - - private ColumnAdapter buildColumnAdapter() { - return new PersonColumnAdapter(); - } - - private TableModelListener buildTableModelListener() { - return new TestTableModelListener(); - } - - private List<String> sortedNames() { - return new ArrayList<String>(CollectionTools.sortedSet(this.crowd.peopleNames())); - } - - private TableModelListener buildSingleEventListener() { - return new TestTableModelListener() { - @Override - public void tableChanged(TableModelEvent e) { - // we expect only a single event - if (TableModelAdapterTests.this.event == null) { - TableModelAdapterTests.this.event = e; - } else { - fail("unexpected event"); - } - } - }; - } - - - // ********** classes ********** - - public static class PersonColumnAdapter implements ColumnAdapter { - public static final int COLUMN_COUNT = 7; - - public static final int NAME_COLUMN = 0; - public static final int BIRTH_DATE_COLUMN = 1; - public static final int GONE_WEST_DATE_COLUMN = 2; - public static final int EYE_COLOR_COLUMN = 3; - public static final int EVIL_COLUMN = 4; - public static final int RANK_COLUMN = 5; - public static final int ADVENTURE_COUNT_COLUMN = 6; - - private static final String[] COLUMN_NAMES = new String[] { - "Name", - "Birth", - "Gone West", - "Eyes", - "Evil", - "Rank", - "Adventures" - }; - - - public int columnCount() { - return COLUMN_COUNT; - } - - public String columnName(int index) { - return COLUMN_NAMES[index]; - } - - public Class<?> columnClass(int index) { - switch (index) { - case NAME_COLUMN: return Object.class; - case BIRTH_DATE_COLUMN: return Date.class; - case GONE_WEST_DATE_COLUMN: return Date.class; - case EYE_COLOR_COLUMN: return Object.class; - case EVIL_COLUMN: return Boolean.class; - case RANK_COLUMN: return Integer.class; - case ADVENTURE_COUNT_COLUMN:return Integer.class; - default: return Object.class; - } - } - - public boolean columnIsEditable(int index) { - return index != NAME_COLUMN; - } - - public WritablePropertyValueModel<Object>[] cellModels(Object subject) { - Person person = (Person) subject; - @SuppressWarnings("unchecked") - WritablePropertyValueModel<Object>[] result = new WritablePropertyValueModel[COLUMN_COUNT]; - - result[NAME_COLUMN] = this.buildNameAdapter(person); - result[BIRTH_DATE_COLUMN] = this.buildBirthDateAdapter(person); - result[GONE_WEST_DATE_COLUMN] = this.buildGoneWestDateAdapter(person); - result[EYE_COLOR_COLUMN] = this.buildEyeColorAdapter(person); - result[EVIL_COLUMN] = this.buildEvilAdapter(person); - result[RANK_COLUMN] = this.buildRankAdapter(person); - result[ADVENTURE_COUNT_COLUMN] = this.buildAdventureCountAdapter(person); - - return result; - } - - private WritablePropertyValueModel<Object> buildNameAdapter(Person person) { - return new PropertyAspectAdapter<Person, Object>(Person.NAME_PROPERTY, person) { - @Override - protected String buildValue_() { - return this.subject.getName(); - } - @Override - protected void setValue_(Object value) { - this.subject.setName((String) value); - } - }; - } - - private WritablePropertyValueModel<Object> buildBirthDateAdapter(Person person) { - return new PropertyAspectAdapter<Person, Object>(Person.BIRTH_DATE_PROPERTY, person) { - @Override - protected Date buildValue_() { - return this.subject.getBirthDate(); - } - @Override - protected void setValue_(Object value) { - this.subject.setBirthDate((Date) value); - } - }; - } - - private WritablePropertyValueModel<Object> buildGoneWestDateAdapter(Person person) { - return new PropertyAspectAdapter<Person, Object>(Person.GONE_WEST_DATE_PROPERTY, person) { - @Override - protected Date buildValue_() { - return this.subject.getGoneWestDate(); - } - @Override - protected void setValue_(Object value) { - this.subject.setGoneWestDate((Date) value); - } - }; - } - - private WritablePropertyValueModel<Object> buildEyeColorAdapter(Person person) { - return new PropertyAspectAdapter<Person, Object>(Person.EYE_COLOR_PROPERTY, person) { - @Override - protected String buildValue_() { - return this.subject.getEyeColor(); - } - @Override - protected void setValue_(Object value) { - this.subject.setEyeColor((String) value); - } - }; - } - - private WritablePropertyValueModel<Object> buildEvilAdapter(Person person) { - return new PropertyAspectAdapter<Person, Object>(Person.EVIL_PROPERTY, person) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isEvil()); - } - @Override - protected void setValue_(Object value) { - this.subject.setEvil(((Boolean)value).booleanValue()); - } - }; - } - - private WritablePropertyValueModel<Object> buildRankAdapter(Person person) { - return new PropertyAspectAdapter<Person, Object>(Person.RANK_PROPERTY, person) { - @Override - protected Integer buildValue_() { - return new Integer(this.subject.getRank()); - } - @Override - protected void setValue_(Object value) { - this.subject.setRank(((Integer) value).intValue()); - } - }; - } - - private WritablePropertyValueModel<Object> buildAdventureCountAdapter(Person person) { - return new PropertyAspectAdapter<Person, Object>(Person.ADVENTURE_COUNT_PROPERTY, person) { - @Override - protected Integer buildValue_() { - return new Integer(this.subject.getAdventureCount()); - } - @Override - protected void setValue_(Object value) { - this.subject.setAdventureCount(((Integer) value).intValue()); - } - }; - } - - } - - - public static class Crowd extends AbstractModel { - private final Collection<Person> people; - public static final String PEOPLE_COLLECTION = "people"; - - public Crowd() { - super(); - this.people = new ArrayList<Person>(); - } - - - public Iterator<Person> people() { - return new CloneIterator<Person>(this.people) { - @Override - protected void remove(Person person) { - Crowd.this.removePerson(person); - } - }; - } - - public int peopleSize() { - return this.people.size(); - } - - public Person addPerson(String name) { - this.checkPersonName(name); - return this.addPerson(new Person(this, name)); - } - - private Person addPerson(Person person) { - this.addItemToCollection(person, this.people, PEOPLE_COLLECTION); - return person; - } - - public void removePerson(Person person) { - this.removeItemFromCollection(person, this.people, PEOPLE_COLLECTION); - } - - public void removePeople(Collection<Person> persons) { - this.removeItemsFromCollection(persons, this.people, PEOPLE_COLLECTION); - } - - public void removePeople(Iterator<Person> persons) { - this.removeItemsFromCollection(persons, this.people, PEOPLE_COLLECTION); - } - - void checkPersonName(String personName) { - if (personName == null) { - throw new NullPointerException(); - } - if (CollectionTools.contains(this.peopleNames(), personName)) { - throw new IllegalArgumentException(personName); - } - } - - public Iterator<String> peopleNames() { - return new TransformationIterator<Person, String>(this.people.iterator()) { - @Override - protected String transform(Person person) { - return person.getName(); - } - }; - } - - public Person personNamed(String name) { - for (Iterator<Person> stream = this.people.iterator(); stream.hasNext(); ) { - Person person = stream.next(); - if (person.getName().equals(name)) { - return person; - } - } - return null; - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, String.valueOf(this.people.size()) + " people"); - } - - } - - - public static class Person extends AbstractModel implements Comparable<Person> { - private Crowd crowd; - private String name; - public static final String NAME_PROPERTY= "name"; - private Date birthDate; - public static final String BIRTH_DATE_PROPERTY= "birthDate"; - private Date goneWestDate; - public static final String GONE_WEST_DATE_PROPERTY= "goneWestDate"; - private String eyeColor; - public static final String EYE_COLOR_PROPERTY= "eyeColor"; - public static final String EYE_COLOR_BLUE = "blue"; - public static final String EYE_COLOR_GREEN = "green"; - public static final String EYE_COLOR_BROWN = "brown"; - public static final String EYE_COLOR_HAZEL = "hazel"; - public static final String EYE_COLOR_PINK = "pink"; - private static Collection<String> validEyeColors; - public static final String DEFAULT_EYE_COLOR = EYE_COLOR_BLUE; - private boolean evil; - public static final String EVIL_PROPERTY= "evil"; - private int rank; - public static final String RANK_PROPERTY= "rank"; - private int adventureCount; - public static final String ADVENTURE_COUNT_PROPERTY= "adventureCount"; - - Person(Crowd crowd, String name) { - super(); - this.crowd = crowd; - this.name = name; - this.birthDate = new Date(); - Calendar c = Calendar.getInstance(); - c.add(Calendar.YEAR, 250); - this.goneWestDate = new Date(c.getTimeInMillis()); - this.eyeColor = DEFAULT_EYE_COLOR; - this.evil = false; - this.rank = 0; - this.adventureCount = 0; - } - - public static Collection<String> getValidEyeColors() { - if (validEyeColors == null) { - validEyeColors = buildValidEyeColors(); - } - return validEyeColors; - } - - private static Collection<String> buildValidEyeColors() { - Collection<String> result = new ArrayList<String>(); - result.add(EYE_COLOR_BLUE); - result.add(EYE_COLOR_GREEN); - result.add(EYE_COLOR_BROWN); - result.add(EYE_COLOR_HAZEL); - result.add(EYE_COLOR_PINK); - return result; - } - - public Crowd getCrowd() { - return this.crowd; - } - - public String getName() { - return this.name; - } - public void setName(String name) { - this.crowd.checkPersonName(name); - Object old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - public Date getBirthDate() { - return this.birthDate; - } - public void setBirthDate(Date birthDate) { - Object old = this.birthDate; - this.birthDate = birthDate; - this.firePropertyChanged(BIRTH_DATE_PROPERTY, old, birthDate); - } - - public Date getGoneWestDate() { - return this.goneWestDate; - } - public void setGoneWestDate(Date goneWestDate) { - Object old = this.goneWestDate; - this.goneWestDate = goneWestDate; - this.firePropertyChanged(GONE_WEST_DATE_PROPERTY, old, goneWestDate); - } - - public String getEyeColor() { - return this.eyeColor; - } - public void setEyeColor(String eyeColor) { - if (! getValidEyeColors().contains(eyeColor)) { - throw new IllegalArgumentException(eyeColor); - } - Object old = this.eyeColor; - this.eyeColor = eyeColor; - this.firePropertyChanged(EYE_COLOR_PROPERTY, old, eyeColor); - } - - public boolean isEvil() { - return this.evil; - } - public void setEvil(boolean evil) { - boolean old = this.evil; - this.evil = evil; - this.firePropertyChanged(EVIL_PROPERTY, old, evil); - } - - public int getRank() { - return this.rank; - } - public void setRank(int rank) { - int old = this.rank; - this.rank = rank; - this.firePropertyChanged(RANK_PROPERTY, old, rank); - } - - public int getAdventureCount() { - return this.adventureCount; - } - public void setAdventureCount(int adventureCount) { - int old = this.adventureCount; - this.adventureCount = adventureCount; - this.firePropertyChanged(ADVENTURE_COUNT_PROPERTY, old, adventureCount); - } - - public int compareTo(Person p) { - return this.name.compareToIgnoreCase(p.name); - } - - @Override - public String toString() { - return this.name + - "\tborn: " + DateFormat.getDateInstance().format(this.birthDate) + - "\tgone west: " + DateFormat.getDateInstance().format(this.goneWestDate) + - "\teyes: " + this.eyeColor + - "\tevil: " + this.evil + - "\trank: " + this.rank + - "\tadventures: " + this.adventureCount - ; - } - - } - - - private class TestTableModelListener implements TableModelListener { - TestTableModelListener() { - super(); - } - public void tableChanged(TableModelEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java deleted file mode 100644 index 6b70b279ca..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TableModelAdapterUITest.java +++ /dev/null @@ -1,734 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.util.ArrayList; -import java.util.Date; -import java.util.Iterator; - -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.ButtonModel; -import javax.swing.ComboBoxModel; -import javax.swing.DefaultListCellRenderer; -import javax.swing.JButton; -import javax.swing.JCheckBox; -import javax.swing.JComboBox; -import javax.swing.JFrame; -import javax.swing.JList; -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JSpinner; -import javax.swing.JTable; -import javax.swing.JTextField; -import javax.swing.ListCellRenderer; -import javax.swing.ListSelectionModel; -import javax.swing.SpinnerModel; -import javax.swing.UIManager; -import javax.swing.WindowConstants; -import javax.swing.event.ListSelectionEvent; -import javax.swing.event.ListSelectionListener; -import javax.swing.table.TableColumn; -import javax.swing.table.TableModel; -import javax.swing.text.Document; - -import org.eclipse.jpt.utility.internal.ClassTools; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleCollectionValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.model.value.swing.CheckBoxModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.ColumnAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.ComboBoxModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.DateSpinnerModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.DocumentAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.ListModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.NumberSpinnerModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.ObjectListSelectionModel; -import org.eclipse.jpt.utility.internal.model.value.swing.TableModelAdapter; -import org.eclipse.jpt.utility.internal.swing.CheckBoxTableCellRenderer; -import org.eclipse.jpt.utility.internal.swing.ComboBoxTableCellRenderer; -import org.eclipse.jpt.utility.internal.swing.SpinnerTableCellRenderer; -import org.eclipse.jpt.utility.internal.swing.TableCellEditorAdapter; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.model.value.swing.TableModelAdapterTests.Crowd; -import org.eclipse.jpt.utility.tests.internal.model.value.swing.TableModelAdapterTests.Person; -import org.eclipse.jpt.utility.tests.internal.model.value.swing.TableModelAdapterTests.PersonColumnAdapter; - -/** - * an example UI for testing the TableModelAdapter - * "name" column is read-only text field - * "birth date" column is date text field - * "gone west date" column is date spinner - * "eye color" column is combo-box - * "evil" column is check box - * "rank" column is number text field - * "adventure count" column is number spinner - * - * Note that the table model and row selection model share the same - * list value model (the sorted people adapter) - */ -@SuppressWarnings("nls") -public class TableModelAdapterUITest { - private SimpleCollectionValueModel<Object> eyeColorsHolder; // Object because it adapts to a combo-box - private WritablePropertyValueModel<Crowd> crowdHolder; - private WritablePropertyValueModel<Person> selectedPersonHolder; - private ListValueModel<Person> sortedPeopleAdapter; - private TableModel tableModel; - private ObjectListSelectionModel rowSelectionModel; - private Action removeAction; - private Action renameAction; - - public static void main(String[] args) throws Exception { - new TableModelAdapterUITest().exec(args); - } - - protected TableModelAdapterUITest() { - super(); - } - - protected void exec(@SuppressWarnings("unused") String[] args) throws Exception { - UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); - this.eyeColorsHolder = this. buildEyeColorCollectionHolder(); - this.crowdHolder = this.buildCrowdHolder(); - this.selectedPersonHolder = this.buildSelectedPersonHolder(); - this.sortedPeopleAdapter = this.buildSortedPeopleAdapter(); - this.tableModel = this.buildTableModel(); - this.rowSelectionModel = this.buildRowSelectionModel(); - this.openWindow(); - } - - private SimpleCollectionValueModel<Object> buildEyeColorCollectionHolder() { - return new SimpleCollectionValueModel<Object>(new ArrayList<Object>(Person.getValidEyeColors())); - } - - private WritablePropertyValueModel<Crowd> buildCrowdHolder() { - return new SimplePropertyValueModel<Crowd>(this.buildCrowd()); - } - - private Crowd buildCrowd() { - Crowd crowd = new Crowd(); - - Person p = crowd.addPerson("Bilbo"); - p.setEyeColor(Person.EYE_COLOR_BROWN); - p.setRank(22); - p.setAdventureCount(1); - - p = crowd.addPerson("Gollum"); - p.setEyeColor(Person.EYE_COLOR_PINK); - p.setEvil(true); - p.setRank(2); - p.setAdventureCount(50); - - p = crowd.addPerson("Frodo"); - p.setEyeColor(Person.EYE_COLOR_BLUE); - p.setRank(34); - p.setAdventureCount(1); - - p = crowd.addPerson("Samwise"); - p.setEyeColor(Person.EYE_COLOR_GREEN); - p.setRank(19); - p.setAdventureCount(1); - - return crowd; - } - - private WritablePropertyValueModel<Person> buildSelectedPersonHolder() { - return new SimplePropertyValueModel<Person>(); - } - - private ListValueModel<Person> buildSortedPeopleAdapter() { - return new SortedListValueModelWrapper<Person>(this.buildPeopleNameAdapter()); - } - - // the list will need to be re-sorted if a name changes - private ListValueModel<Person> buildPeopleNameAdapter() { - return new ItemPropertyListValueModelAdapter<Person>(this.buildPeopleAdapter(), Person.NAME_PROPERTY); - } - - private CollectionValueModel<Person> buildPeopleAdapter() { - return new CollectionAspectAdapter<Crowd, Person>(this.crowdHolder, Crowd.PEOPLE_COLLECTION) { - @Override - protected Iterator<Person> iterator_() { - return this.subject.people(); - } - @Override - protected int size_() { - return this.subject.peopleSize(); - } - }; - } - - private TableModel buildTableModel() { - return new TableModelAdapter<Person>(this.sortedPeopleAdapter, this.buildColumnAdapter()); - } - - protected ColumnAdapter buildColumnAdapter() { - return new PersonColumnAdapter(); - } - - private ObjectListSelectionModel buildRowSelectionModel() { - ObjectListSelectionModel rsm = new ObjectListSelectionModel(new ListModelAdapter(this.sortedPeopleAdapter)); - rsm.addListSelectionListener(this.buildRowSelectionListener()); - rsm.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); - return rsm; - } - - private ListSelectionListener buildRowSelectionListener() { - return new ListSelectionListener() { - public void valueChanged(ListSelectionEvent e) { - if (e.getValueIsAdjusting()) { - return; - } - TableModelAdapterUITest.this.rowSelectionChanged(e); - } - }; - } - - void rowSelectionChanged(@SuppressWarnings("unused") ListSelectionEvent event) { - Person selection = (Person) this.rowSelectionModel.selectedValue(); - this.selectedPersonHolder.setValue(selection); - boolean personSelected = (selection != null); - this.removeAction.setEnabled(personSelected); - this.renameAction.setEnabled(personSelected); - } - - private void openWindow() { - JFrame window = new JFrame(ClassTools.shortClassNameForObject(this)); - window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - window.addWindowListener(this.buildWindowListener()); - window.getContentPane().add(this.buildMainPanel(), "Center"); - window.setLocation(200, 200); - window.setSize(600, 400); - window.setVisible(true); - } - - private WindowListener buildWindowListener() { - return new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - System.exit(0); - } - }; - } - - private Component buildMainPanel() { - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(this.buildTablePane(), BorderLayout.CENTER); - mainPanel.add(this.buildControlPanel(), BorderLayout.SOUTH); - return mainPanel; - } - - private Component buildTablePane() { - return new JScrollPane(this.buildTable()); - } - - private JTable buildTable() { - JTable table = new JTable(this.tableModel); - table.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); // see Java bug 5007652 - table.setSelectionModel(this.rowSelectionModel); - table.setDoubleBuffered(true); - table.setAutoResizeMode(JTable.AUTO_RESIZE_NEXT_COLUMN); - int rowHeight = 20; // start with minimum of 20 - - // gone west column (spinner) - TableColumn column = table.getColumnModel().getColumn(PersonColumnAdapter.GONE_WEST_DATE_COLUMN); - SpinnerTableCellRenderer spinnerRenderer = this.buildDateSpinnerRenderer(); - column.setCellRenderer(spinnerRenderer); - column.setCellEditor(new TableCellEditorAdapter(this.buildDateSpinnerRenderer())); - rowHeight = Math.max(rowHeight, spinnerRenderer.preferredHeight()); - - // eye color column (combo-box) - // the jdk combo-box renderer looks like a text field - // until the user starts an edit - use a custom one - column = table.getColumnModel().getColumn(PersonColumnAdapter.EYE_COLOR_COLUMN); - ComboBoxTableCellRenderer eyeColorRenderer = this.buildEyeColorComboBoxRenderer(); - column.setCellRenderer(eyeColorRenderer); - column.setCellEditor(new TableCellEditorAdapter(this.buildEyeColorComboBoxRenderer())); - rowHeight = Math.max(rowHeight, eyeColorRenderer.preferredHeight()); - - // evil (check box) - // the jdk check box renderer and editor suck - use a custom ones - column = table.getColumnModel().getColumn(PersonColumnAdapter.EVIL_COLUMN); - CheckBoxTableCellRenderer evilRenderer = new CheckBoxTableCellRenderer(); - column.setCellRenderer(evilRenderer); - column.setCellEditor(new TableCellEditorAdapter(new CheckBoxTableCellRenderer())); - rowHeight = Math.max(rowHeight, evilRenderer.preferredHeight()); - - // adventure count column (spinner) - column = table.getColumnModel().getColumn(PersonColumnAdapter.ADVENTURE_COUNT_COLUMN); - spinnerRenderer = this.buildNumberSpinnerRenderer(); - column.setCellRenderer(spinnerRenderer); - column.setCellEditor(new TableCellEditorAdapter(this.buildNumberSpinnerRenderer())); - rowHeight = Math.max(rowHeight, spinnerRenderer.preferredHeight()); - - table.setRowHeight(rowHeight); - return table; - } - - private SpinnerTableCellRenderer buildDateSpinnerRenderer() { - return new SpinnerTableCellRenderer(new DateSpinnerModelAdapter(new SimplePropertyValueModel<Object>())); - } - - private SpinnerTableCellRenderer buildNumberSpinnerRenderer() { - return new SpinnerTableCellRenderer(new NumberSpinnerModelAdapter(new SimplePropertyValueModel<Number>())); - } - - private ComboBoxTableCellRenderer buildEyeColorComboBoxRenderer() { - return new ComboBoxTableCellRenderer(this.buildReadOnlyEyeColorComboBoxModel(), this.buildEyeColorRenderer()); - } - - private ComboBoxModel buildReadOnlyEyeColorComboBoxModel() { - return new ComboBoxModelAdapter(this.eyeColorsHolder, new SimplePropertyValueModel<Object>()); - } - - private ListCellRenderer buildEyeColorRenderer() { - return new EyeColorRenderer(); - } - - private Component buildControlPanel() { - JPanel controlPanel = new JPanel(new GridLayout(0, 1)); - controlPanel.add(this.buildButtonPanel()); - controlPanel.add(this.buildPersonPanel()); - return controlPanel; - } - - private Component buildButtonPanel() { - JPanel buttonPanel = new JPanel(new GridLayout(1, 0)); - buttonPanel.add(this.buildAddButton()); - buttonPanel.add(this.buildRemoveButton()); - buttonPanel.add(this.buildRenameButton()); - buttonPanel.add(this.buildAddEyeColorButton()); - buttonPanel.add(this.buildPrintButton()); - buttonPanel.add(this.buildResetButton()); - return buttonPanel; - } - - private Component buildPersonPanel() { - JPanel personPanel = new JPanel(new GridLayout(1, 0)); - personPanel.add(this.buildNameTextField()); - personPanel.add(this.buildBirthDateSpinner()); - personPanel.add(this.buildGoneWestDateSpinner()); - personPanel.add(this.buildEyeColorComboBox()); - personPanel.add(this.buildEvilCheckBox()); - personPanel.add(this.buildRankSpinner()); - personPanel.add(this.buildAdventureCountSpinner()); - return personPanel; - } - - - // ********** add button ********** - - private JButton buildAddButton() { - return new JButton(this.buildAddAction()); - } - - private Action buildAddAction() { - Action action = new AbstractAction("add") { - public void actionPerformed(ActionEvent event) { - TableModelAdapterUITest.this.addPerson(); - } - }; - action.setEnabled(true); - return action; - } - - void addPerson() { - String name = this.getNameFromUser(); - if (name != null) { - this.setSelectedPerson(this.crowd().addPerson(name)); - } - } - - - // ********** remove button ********** - - private JButton buildRemoveButton() { - return new JButton(this.buildRemoveAction()); - } - - private Action buildRemoveAction() { - this.removeAction = new AbstractAction("remove") { - public void actionPerformed(ActionEvent event) { - TableModelAdapterUITest.this.removePerson(); - } - }; - this.removeAction.setEnabled(false); - return this.removeAction; - } - - void removePerson() { - Person person = this.selectedPerson(); - if (person != null) { - this.crowd().removePerson(person); - } - } - - - // ********** rename button ********** - - private JButton buildRenameButton() { - return new JButton(this.buildRenameAction()); - } - - private Action buildRenameAction() { - this.renameAction = new AbstractAction("rename") { - public void actionPerformed(ActionEvent event) { - TableModelAdapterUITest.this.renamePerson(); - } - }; - this.renameAction.setEnabled(false); - return this.renameAction; - } - - void renamePerson() { - Person person = this.selectedPerson(); - if (person != null) { - String name = this.promptUserForName(person.getName()); - if (name != null) { - person.setName(name); - this.setSelectedPerson(person); - } - } - } - - - // ********** add eye color button ********** - - private JButton buildAddEyeColorButton() { - return new JButton(this.buildAddEyeColorAction()); - } - - private Action buildAddEyeColorAction() { - Action action = new AbstractAction("add eye color") { - public void actionPerformed(ActionEvent event) { - TableModelAdapterUITest.this.addEyeColor(); - } - }; - action.setEnabled(true); - return action; - } - - void addEyeColor() { - String color = this.promptUserForEyeColor(); - if (color != null) { - this.eyeColorsHolder.add(color); - } - } - - private String promptUserForEyeColor() { - while (true) { - String eyeColor = JOptionPane.showInputDialog("Eye Color"); - if (eyeColor == null) { - return null; // user pressed <Cancel> - } - if ((eyeColor.length() == 0)) { - JOptionPane.showMessageDialog(null, "The eye color is required.", "Invalid Eye Color", JOptionPane.ERROR_MESSAGE); - } else if (CollectionTools.contains(this.eyeColorsHolder.iterator(), eyeColor)) { - JOptionPane.showMessageDialog(null, "The eye color already exists.", "Invalid Eye Color", JOptionPane.ERROR_MESSAGE); - } else { - return eyeColor; - } - } - } - - - // ********** print button ********** - - private JButton buildPrintButton() { - return new JButton(this.buildPrintAction()); - } - - private Action buildPrintAction() { - Action action = new AbstractAction("print") { - public void actionPerformed(ActionEvent event) { - TableModelAdapterUITest.this.printCrowd(); - } - }; - action.setEnabled(true); - return action; - } - - void printCrowd() { - System.out.println(this.crowd()); - for (Iterator<Person> stream = this.crowd().people(); stream.hasNext(); ) { - System.out.println("\t" + stream.next()); - } - } - - - // ********** reset button ********** - - private JButton buildResetButton() { - return new JButton(this.buildResetAction()); - } - - private Action buildResetAction() { - Action action = new AbstractAction("reset") { - public void actionPerformed(ActionEvent event) { - TableModelAdapterUITest.this.reset(); - } - }; - action.setEnabled(true); - return action; - } - - void reset() { - this.crowdHolder.setValue(this.buildCrowd()); - } - - - // ********** new name dialog ********** - - private String getNameFromUser() { - return this.promptUserForName(null); - } - - private String promptUserForName(String originalName) { - while (true) { - String name = JOptionPane.showInputDialog("Person Name"); - if (name == null) { - return null; // user pressed <Cancel> - } - if ((name.length() == 0)) { - JOptionPane.showMessageDialog(null, "The name is required.", "Invalid Name", JOptionPane.ERROR_MESSAGE); - } else if (CollectionTools.contains(this.crowd().peopleNames(), name)) { - JOptionPane.showMessageDialog(null, "The name already exists.", "Invalid Name", JOptionPane.ERROR_MESSAGE); - } else { - return name; - } - } - } - - - // ********** name text field ********** - - private Component buildNameTextField() { - JTextField textField = new JTextField(this.buildNameDocument(), null, 0); - textField.setEditable(false); - return textField; - } - - private Document buildNameDocument() { - return new DocumentAdapter(this.buildNameAdapter()); - } - - private WritablePropertyValueModel<String> buildNameAdapter() { - return new PropertyAspectAdapter<Person, String>(this.selectedPersonHolder, Person.NAME_PROPERTY) { - @Override - protected String buildValue_() { - return this.subject.getName(); - } - @Override - protected void setValue_(String value) { - this.subject.setName(value); - } - }; - } - - - // ********** birth date spinner ********** - - private JSpinner buildBirthDateSpinner() { - return new JSpinner(this.buildBirthDateSpinnerModel()); - } - - private SpinnerModel buildBirthDateSpinnerModel() { - return new DateSpinnerModelAdapter(this.buildBirthDateAdapter()); - } - - private WritablePropertyValueModel<Object> buildBirthDateAdapter() { - return new PropertyAspectAdapter<Person, Object>(this.selectedPersonHolder, Person.BIRTH_DATE_PROPERTY) { - @Override - protected Date buildValue_() { - return this.subject.getBirthDate(); - } - @Override - protected void setValue_(Object value) { - this.subject.setBirthDate((Date) value); - } - }; - } - - - // ********** gone west date spinner ********** - - private JSpinner buildGoneWestDateSpinner() { - return new JSpinner(this.buildGoneWestDateSpinnerModel()); - } - - private SpinnerModel buildGoneWestDateSpinnerModel() { - return new DateSpinnerModelAdapter(this.buildGoneWestDateAdapter()); - } - - private WritablePropertyValueModel<Object> buildGoneWestDateAdapter() { - return new PropertyAspectAdapter<Person, Object>(this.selectedPersonHolder, Person.GONE_WEST_DATE_PROPERTY) { - @Override - protected Date buildValue_() { - return this.subject.getGoneWestDate(); - } - @Override - protected void setValue_(Object value) { - this.subject.setGoneWestDate((Date) value); - } - }; - } - - - // ********** eye color combo-box ********** - - private JComboBox buildEyeColorComboBox() { - return new JComboBox(this.buildEyeColorComboBoxModel()); - } - - private ComboBoxModel buildEyeColorComboBoxModel() { - return new ComboBoxModelAdapter(this.eyeColorsHolder, this.buildEyeColorAdapter()); - } - - private WritablePropertyValueModel<Object> buildEyeColorAdapter() { - return new PropertyAspectAdapter<Person, Object>(this.selectedPersonHolder, Person.EYE_COLOR_PROPERTY) { - @Override - protected Object buildValue_() { - return this.subject.getEyeColor(); - } - @Override - protected void setValue_(Object value) { - this.subject.setEyeColor((String) value); - } - }; - } - - - // ********** evil check box ********** - - private JCheckBox buildEvilCheckBox() { - JCheckBox checkBox = new JCheckBox(); - checkBox.setText("evil"); - checkBox.setModel(this.buildEvilCheckBoxModel()); - return checkBox; - } - - private ButtonModel buildEvilCheckBoxModel() { - return new CheckBoxModelAdapter(this.buildEvilAdapter()); - } - - private WritablePropertyValueModel<Boolean> buildEvilAdapter() { - return new PropertyAspectAdapter<Person, Boolean>(this.selectedPersonHolder, Person.EVIL_PROPERTY) { - @Override - protected Boolean buildValue_() { - return Boolean.valueOf(this.subject.isEvil()); - } - @Override - protected void setValue_(Boolean value) { - this.subject.setEvil(value.booleanValue()); - } - }; - } - - - // ********** rank spinner ********** - - private JSpinner buildRankSpinner() { - return new JSpinner(this.buildRankSpinnerModel()); - } - - private SpinnerModel buildRankSpinnerModel() { - return new NumberSpinnerModelAdapter(this.buildRankAdapter()); - } - - private WritablePropertyValueModel<Number> buildRankAdapter() { - return new PropertyAspectAdapter<Person, Number>(this.selectedPersonHolder, Person.RANK_PROPERTY) { - @Override - protected Number buildValue_() { - return new Integer(this.subject.getRank()); - } - @Override - protected void setValue_(Number value) { - this.subject.setRank(value.intValue()); - } - }; - } - - - // ********** adventure count spinner ********** - - private JSpinner buildAdventureCountSpinner() { - return new JSpinner(this.buildAdventureCountSpinnerModel()); - } - - private SpinnerModel buildAdventureCountSpinnerModel() { - return new NumberSpinnerModelAdapter(this.buildAdventureCountAdapter()); - } - - private WritablePropertyValueModel<Number> buildAdventureCountAdapter() { - return new PropertyAspectAdapter<Person, Number>(this.selectedPersonHolder, Person.ADVENTURE_COUNT_PROPERTY) { - @Override - protected Number buildValue_() { - return new Integer(this.subject.getAdventureCount()); - } - @Override - protected void setValue_(Number value) { - this.subject.setAdventureCount(value.intValue()); - } - }; - } - - - // ********** queries ********** - - private Crowd crowd() { - return this.crowdHolder.getValue(); - } - - private Person selectedPerson() { - if (this.rowSelectionModel.isSelectionEmpty()) { - return null; - } - return (Person) this.rowSelectionModel.selectedValue(); - } - - private void setSelectedPerson(Person person) { - this.rowSelectionModel.setSelectedValue(person); - } - - - // ********** custom renderer ********** - - /** - * This is simply an example of a renderer for the embedded combo-box. - * It does nothing special unless you uncomment the code below.... - */ - private class EyeColorRenderer extends DefaultListCellRenderer { - EyeColorRenderer() { - super(); - } - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - // just do something to show the renderer is working... - // value = ">" + value; - return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java deleted file mode 100644 index 257096ce20..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterTests.java +++ /dev/null @@ -1,812 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2009 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.io.OutputStream; -import java.io.OutputStreamWriter; -import java.io.StringWriter; -import java.util.Arrays; -import java.util.Collection; -import java.util.Iterator; - -import javax.swing.Icon; -import javax.swing.JTree; -import javax.swing.event.TreeModelEvent; -import javax.swing.event.TreeModelListener; -import javax.swing.tree.TreeModel; - -import junit.framework.TestCase; - -import org.eclipse.jpt.utility.internal.HashBag; -import org.eclipse.jpt.utility.internal.IndentingPrintWriter; -import org.eclipse.jpt.utility.internal.StringTools; -import org.eclipse.jpt.utility.internal.iterators.ReadOnlyIterator; -import org.eclipse.jpt.utility.internal.model.AbstractModel; -import org.eclipse.jpt.utility.internal.model.value.AbstractTreeNodeValueModel; -import org.eclipse.jpt.utility.internal.model.value.CollectionAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.ItemPropertyListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.NullListValueModel; -import org.eclipse.jpt.utility.internal.model.value.PropertyAspectAdapter; -import org.eclipse.jpt.utility.internal.model.value.SimpleListValueModel; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.SortedListValueModelWrapper; -import org.eclipse.jpt.utility.internal.model.value.StaticPropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.TransformationListValueModelAdapter; -import org.eclipse.jpt.utility.internal.model.value.swing.TreeModelAdapter; -import org.eclipse.jpt.utility.internal.swing.Displayable; -import org.eclipse.jpt.utility.model.event.PropertyChangeEvent; -import org.eclipse.jpt.utility.model.listener.ListChangeListener; -import org.eclipse.jpt.utility.model.listener.PropertyChangeListener; -import org.eclipse.jpt.utility.model.listener.StateChangeListener; -import org.eclipse.jpt.utility.model.value.CollectionValueModel; -import org.eclipse.jpt.utility.model.value.ListValueModel; -import org.eclipse.jpt.utility.model.value.PropertyValueModel; -import org.eclipse.jpt.utility.model.value.TreeNodeValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; - -@SuppressWarnings("nls") -public class TreeModelAdapterTests extends TestCase { - boolean eventFired; - - public TreeModelAdapterTests(String name) { - super(name); - } - - public void testGetRoot() { - TreeModel treeModel = this.buildSortedTreeModel(); - treeModel.addTreeModelListener(new TestTreeModelListener()); - TestNode rootNode = (TestNode) treeModel.getRoot(); - TestModel root = rootNode.getTestModel(); - assertEquals("root", root.getName()); -// root.dump(); -// rootNode.dump(); - } - - public void testGetChild() { - TreeModel treeModel = this.buildSortedTreeModel(); - treeModel.addTreeModelListener(new TestTreeModelListener()); - TestNode rootNode = (TestNode) treeModel.getRoot(); - - TestNode expected = rootNode.childNamed("node 1"); - TestNode actual = (TestNode) treeModel.getChild(rootNode, 1); - assertEquals(expected, actual); - - expected = rootNode.childNamed("node 2"); - actual = (TestNode) treeModel.getChild(rootNode, 2); - assertEquals(expected, actual); - } - - public void testGetChildCount() { - TreeModel treeModel = this.buildSortedTreeModel(); - treeModel.addTreeModelListener(new TestTreeModelListener()); - TestNode rootNode = (TestNode) treeModel.getRoot(); - - assertEquals(5, treeModel.getChildCount(rootNode)); - - TestNode node = rootNode.childNamed("node 1"); - assertEquals(1, treeModel.getChildCount(node)); - } - - public void testGetIndexOfChild() { - TreeModel treeModel = this.buildSortedTreeModel(); - treeModel.addTreeModelListener(new TestTreeModelListener()); - TestNode rootNode = (TestNode) treeModel.getRoot(); - - TestNode child = rootNode.childNamed("node 0"); - assertEquals(0, treeModel.getIndexOfChild(rootNode, child)); - - child = rootNode.childNamed("node 1"); - assertEquals(1, treeModel.getIndexOfChild(rootNode, child)); - - child = rootNode.childNamed("node 2"); - assertEquals(2, treeModel.getIndexOfChild(rootNode, child)); - TestNode grandchild = child.childNamed("node 2.2"); - assertEquals(2, treeModel.getIndexOfChild(child, grandchild)); - } - - public void testIsLeaf() { - TreeModel treeModel = this.buildSortedTreeModel(); - treeModel.addTreeModelListener(new TestTreeModelListener()); - TestNode rootNode = (TestNode) treeModel.getRoot(); - assertFalse(treeModel.isLeaf(rootNode)); - TestNode node = rootNode.childNamed("node 1"); - assertFalse(treeModel.isLeaf(node)); - node = rootNode.childNamed("node 3"); - assertTrue(treeModel.isLeaf(node)); - } - - - public void testTreeNodesChanged() { - // the only way to trigger a "node changed" event is to use an unsorted tree; - // a sorted tree will will trigger only "node removed" and "node inserted" events - TreeModel treeModel = this.buildUnsortedTreeModel(); - this.eventFired = false; - treeModel.addTreeModelListener(new TestTreeModelListener() { - @Override - public void treeNodesChanged(TreeModelEvent e) { - TreeModelAdapterTests.this.eventFired = true; - } - }); - TestNode rootNode = (TestNode) treeModel.getRoot(); - TestNode node = rootNode.childNamed("node 1"); - TestModel tm = node.getTestModel(); - tm.setName("node 1++"); - assertTrue(this.eventFired); - - this.eventFired = false; - node = node.childNamed("node 1.1"); - tm = node.getTestModel(); - tm.setName("node 1.1++"); - assertTrue(this.eventFired); - } - - public void testTreeNodesInserted() { - // use an unsorted tree so the nodes are not re-shuffled... - TreeModel treeModel = this.buildUnsortedTreeModel(); - this.eventFired = false; - treeModel.addTreeModelListener(new TestTreeModelListener() { - @Override - public void treeNodesInserted(TreeModelEvent e) { - TreeModelAdapterTests.this.eventFired = true; - } - }); - TestNode rootNode = (TestNode) treeModel.getRoot(); - TestNode node = rootNode.childNamed("node 1"); - TestModel tm = node.getTestModel(); - tm.addChild("new child..."); - assertTrue(this.eventFired); - - this.eventFired = false; - node = node.childNamed("node 1.1"); - tm = node.getTestModel(); - tm.addChild("another new child..."); - assertTrue(this.eventFired); - } - - public void testTreeNodesRemoved() { - TreeModel treeModel = this.buildUnsortedTreeModel(); - this.eventFired = false; - treeModel.addTreeModelListener(new TestTreeModelListener() { - @Override - public void treeNodesRemoved(TreeModelEvent e) { - TreeModelAdapterTests.this.eventFired = true; - } - }); - TestNode rootNode = (TestNode) treeModel.getRoot(); - TestModel root = rootNode.getTestModel(); - root.removeChild(root.childNamed("node 3")); - assertTrue(this.eventFired); - - this.eventFired = false; - TestNode node = rootNode.childNamed("node 2"); - TestModel tm = node.getTestModel(); - tm.removeChild(tm.childNamed("node 2.2")); - assertTrue(this.eventFired); - } - - public void testTreeStructureChanged() { - WritablePropertyValueModel<TreeNodeValueModel<Object>> nodeHolder = new SimplePropertyValueModel<TreeNodeValueModel<Object>>(this.buildSortedRootNode()); - TreeModel treeModel = this.buildTreeModel(nodeHolder); - this.eventFired = false; - treeModel.addTreeModelListener(new TestTreeModelListener() { - @Override - public void treeNodesInserted(TreeModelEvent e) { - // do nothing - } - @Override - public void treeNodesRemoved(TreeModelEvent e) { - // do nothing - } - @Override - public void treeStructureChanged(TreeModelEvent e) { - TreeModelAdapterTests.this.eventFired = true; - } - }); - nodeHolder.setValue(this.buildUnsortedRootNode()); - assertTrue(this.eventFired); - } - - /** - * test a problem we had where removing a child from a tree would cause - * the JTree to call #equals(Object) on each node removed (actually, it was - * TreePath, but that was because its own #equals(Object) was called by - * JTree); and since we had already removed the last listener from the - * aspect adapter, the aspect adapter would say its value was null; this - * would cause a NPE until we tweaked TreeModelAdapter to remove its - * listeners from a node only *after* the node had been completely - * removed from the JTree - * @see TreeModelAdapter#removeNode(Object[], int, TreeNodeValueModel) - * @see TreeModelAdapter#addNode(Object[], int, TreeNodeValueModel) - */ - public void testLazyInitialization() { - TreeModel treeModel = this.buildSpecialTreeModel(); - JTree jTree = new JTree(treeModel); - TestNode rootNode = (TestNode) treeModel.getRoot(); - TestModel root = rootNode.getTestModel(); - // this would cause a NPE: - root.removeChild(root.childNamed("node 3")); - assertEquals(treeModel, jTree.getModel()); - } - - - private TreeModel buildSortedTreeModel() { - return this.buildTreeModel(this.buildSortedRootNode()); - } - - private TestNode buildSortedRootNode() { - return new SortedTestNode(this.buildRoot()); - } - - private TreeModel buildUnsortedTreeModel() { - return this.buildTreeModel(this.buildUnsortedRootNode()); - } - - private TestNode buildUnsortedRootNode() { - return new UnsortedTestNode(this.buildRoot()); - } - - private TreeModel buildSpecialTreeModel() { - return this.buildTreeModel(this.buildSpecialRootNode()); - } - - private TestNode buildSpecialRootNode() { - return new SpecialTestNode(this.buildRoot()); - } - - private TestModel buildRoot() { - TestModel root = new TestModel("root"); - /*Node node_0 = */root.addChild("node 0"); - TestModel node_1 = root.addChild("node 1"); - TestModel node_1_1 = node_1.addChild("node 1.1"); - /*Node node_1_1_1 = */node_1_1.addChild("node 1.1.1"); - TestModel node_2 = root.addChild("node 2"); - /*Node node_2_0 = */node_2.addChild("node 2.0"); - /*Node node_2_1 = */node_2.addChild("node 2.1"); - /*Node node_2_2 = */node_2.addChild("node 2.2"); - /*Node node_2_3 = */node_2.addChild("node 2.3"); - /*Node node_2_4 = */node_2.addChild("node 2.4"); - /*Node node_2_5 = */node_2.addChild("node 2.5"); - /*Node node_3 = */root.addChild("node 3"); - /*Node node_4 = */root.addChild("node 4"); - return root; - } - - - // ********** member classes ********** - - /** - * This is a typical model class with the typical change notifications - * for #name and #children. - */ - public static class TestModel extends AbstractModel { - - // the parent is immutable; the root's parent is null - private final TestModel parent; - - // the name is mutable; so I guess it isn't the "primary key" :-) - private String name; - public static final String NAME_PROPERTY = "name"; - - private final Collection<TestModel> children; - public static final String CHILDREN_COLLECTION = "children"; - - - public TestModel(String name) { // root ctor - this(null, name); - } - private TestModel(TestModel parent, String name) { - super(); - this.parent = parent; - this.name = name; - this.children = new HashBag<TestModel>(); - } - - public TestModel getParent() { - return this.parent; - } - - public String getName() { - return this.name; - } - public void setName(String name) { - Object old = this.name; - this.name = name; - this.firePropertyChanged(NAME_PROPERTY, old, name); - } - - public Iterator<TestModel> children() { - return new ReadOnlyIterator<TestModel>(this.children); - } - public int childrenSize() { - return this.children.size(); - } - public TestModel addChild(String childName) { - TestModel child = new TestModel(this, childName); - this.addItemToCollection(child, this.children, CHILDREN_COLLECTION); - return child; - } - public TestModel[] addChildren(String[] childNames) { - TestModel[] newChildren = new TestModel[childNames.length]; - for (int i = 0; i < childNames.length; i++) { - newChildren[i] = new TestModel(this, childNames[i]); - } - this.addItemsToCollection(newChildren, this.children, CHILDREN_COLLECTION); - return newChildren; - } - public void removeChild(TestModel child) { - this.removeItemFromCollection(child, this.children, CHILDREN_COLLECTION); - } - public void removeChildren(TestModel[] testModels) { - this.removeItemsFromCollection(testModels, this.children, CHILDREN_COLLECTION); - } - public void clearChildren() { - this.clearCollection(this.children, CHILDREN_COLLECTION); - } - public TestModel childNamed(String childName) { - for (TestModel child : this.children) { - if (child.getName().equals(childName)) { - return child; - } - } - throw new RuntimeException("child not found: " + childName); - } - - public String dumpString() { - StringWriter sw = new StringWriter(); - IndentingPrintWriter ipw = new IndentingPrintWriter(sw); - this.dumpOn(ipw); - return sw.toString(); - } - public void dumpOn(IndentingPrintWriter writer) { - writer.println(this); - writer.indent(); - for (TestModel child : this.children) { - child.dumpOn(writer); - } - writer.undent(); - } - public void dumpOn(OutputStream stream) { - IndentingPrintWriter writer = new IndentingPrintWriter(new OutputStreamWriter(stream)); - this.dumpOn(writer); - writer.flush(); - } - public void dump() { - this.dumpOn(System.out); - } - - @Override - public String toString() { - return StringTools.buildToStringFor(this, this.name); - } - - } - - - /** - * This Node wraps a TestModel and converts into something that can - * be used by TreeModelAdapter. It converts changes to the TestModel's - * name into "state changes" to the Node; and converts the - * TestModel's children into a ListValueModel of Nodes whose order is - * determined by subclass implementations. - */ - public static abstract class TestNode extends AbstractTreeNodeValueModel<Object> implements Displayable, Comparable<TestNode> { - /** the model object wrapped by this node */ - private final TestModel testModel; - /** this node's parent node; null for the root node */ - private final TestNode parent; - /** this node's child nodes */ - private final ListValueModel<TreeNodeValueModel<Object>> childrenModel; - /** a listener that notifies us when the model object's "internal state" changes */ - private final PropertyChangeListener testModelListener; - - - // ********** constructors/initialization ********** - - /** - * root node constructor - */ - public TestNode(TestModel testModel) { - this(null, testModel); - } - - /** - * branch or leaf node constructor - */ - public TestNode(TestNode parent, TestModel testModel) { - super(); - this.parent = parent; - this.testModel = testModel; - this.childrenModel = this.buildChildrenModel(testModel); - this.testModelListener = this.buildTestModelListener(); - } - - private PropertyChangeListener buildTestModelListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - TestNode.this.testModelChanged(e); - } - }; - } - - /** - * subclasses decide the order of the child nodes - */ - protected abstract ListValueModel<TreeNodeValueModel<Object>> buildChildrenModel(TestModel model); - - /** - * used by subclasses; - * transform the test model children into nodes - */ - protected ListValueModel<TreeNodeValueModel<Object>> buildNodeAdapter(TestModel model) { - return new TransformationListValueModelAdapter<TestModel, TreeNodeValueModel<Object>>(this.buildChildrenAdapter(model)) { - @Override - protected TestNode transformItem(TestModel item) { - return TestNode.this.buildChildNode(item); - } - }; - } - - /** - * subclasses must build a concrete node for the specified test model - */ - protected abstract TestNode buildChildNode(TestModel childTestModel); - - /** - * return a collection value model on the specified model's children - */ - protected CollectionValueModel<TestModel> buildChildrenAdapter(TestModel model) { - return new CollectionAspectAdapter<TestModel, TestModel>(TestModel.CHILDREN_COLLECTION, model) { - @Override - protected Iterator<TestModel> iterator_() { - return this.subject.children(); - } - @Override - protected int size_() { - return this.subject.childrenSize(); - } - }; - } - - - // ********** TreeNodeValueModel implementation ********** - - public TestModel getValue() { - return this.testModel; - } - - public TreeNodeValueModel<Object> parent() { - return this.parent; - } - - public ListValueModel<TreeNodeValueModel<Object>> childrenModel() { - return this.childrenModel; - } - - - // ********** AbstractTreeNodeValueModel implementation ********** - - @Override - protected void engageValue() { - this.testModel.addPropertyChangeListener(TestModel.NAME_PROPERTY, this.testModelListener); - } - - @Override - protected void disengageValue() { - this.testModel.removePropertyChangeListener(TestModel.NAME_PROPERTY, this.testModelListener); - } - - - // ********** Displayable implementation ********** - - public String displayString() { - return this.testModel.getName(); - } - - public Icon icon() { - return null; - } - - - // ********** debugging support ********** - - public String dumpString() { - StringWriter sw = new StringWriter(); - IndentingPrintWriter ipw = new IndentingPrintWriter(sw); - this.dumpOn(ipw); - return sw.toString(); - } - - public void dumpOn(IndentingPrintWriter writer) { - writer.println(this); - writer.indent(); - for (Iterator<TreeNodeValueModel<Object>> stream = this.childrenModel.iterator(); stream.hasNext(); ) { - // cast to a TestNode (i.e. this won't work with a NameTestNode in the tree) - ((TestNode) stream.next()).dumpOn(writer); - } - writer.undent(); - } - - public void dumpOn(OutputStream stream) { - IndentingPrintWriter writer = new IndentingPrintWriter(new OutputStreamWriter(stream)); - this.dumpOn(writer); - writer.flush(); - } - - public void dump() { - this.dumpOn(System.out); - } - - - // ********** behavior ********** - - /** - * the model's name has changed, forward the event to our listeners - */ - protected void testModelChanged(PropertyChangeEvent e) { - // we need to notify listeners that our "internal state" has changed - this.fireStateChanged(); - // our display string stays in synch with the model's name - this.firePropertyChanged(DISPLAY_STRING_PROPERTY, e.getOldValue(), e.getNewValue()); - } - - - // ********** queries ********** - - public TestModel getTestModel() { - return this.testModel; - } - - /** - * testing convenience method - */ - public TestNode childNamed(String name) { - for (Iterator<TreeNodeValueModel<Object>> stream = this.childrenModel.iterator(); stream.hasNext(); ) { - TreeNodeValueModel<Object> childNode = stream.next(); - if (childNode instanceof TestNode) { - if (((TestNode) childNode).getTestModel().getName().equals(name)) { - return (TestNode) childNode; - } - } - } - throw new IllegalArgumentException("child not found: " + name); - } - - - // ********** standard methods ********** - - public int compareTo(TestNode o) { - return this.displayString().compareTo(o.displayString()); - } - - @Override - public String toString() { - return "Node(" + this.testModel + ")"; - } - - } - - /** - * concrete implementation that keeps its children sorted - */ - public static class SortedTestNode extends TestNode { - - // ********** constructors ********** - public SortedTestNode(TestModel testModel) { - super(testModel); - } - public SortedTestNode(TestNode parent, TestModel testModel) { - super(parent, testModel); - } - - // ********** initialization ********** - /** the list should be sorted */ - @Override - protected ListValueModel<TreeNodeValueModel<Object>> buildChildrenModel(TestModel testModel) { - return new SortedListValueModelWrapper<TreeNodeValueModel<Object>>(this.buildDisplayStringAdapter(testModel)); - } - /** the display string (name) of each node can change */ - protected ListValueModel<TreeNodeValueModel<Object>> buildDisplayStringAdapter(TestModel testModel) { - return new ItemPropertyListValueModelAdapter<TreeNodeValueModel<Object>>(this.buildNodeAdapter(testModel), DISPLAY_STRING_PROPERTY); - } - /** children are also sorted nodes */ - @Override - protected TestNode buildChildNode(TestModel childNode) { - return new SortedTestNode(this, childNode); - } - - } - - - /** - * concrete implementation that leaves its children unsorted - */ - public static class UnsortedTestNode extends TestNode { - - // ********** constructors ********** - public UnsortedTestNode(TestModel testModel) { - super(testModel); - } - public UnsortedTestNode(TestNode parent, TestModel testModel) { - super(parent, testModel); - } - - // ********** initialization ********** - /** the list should NOT be sorted */ - @Override - protected ListValueModel<TreeNodeValueModel<Object>> buildChildrenModel(TestModel testModel) { - return this.buildNodeAdapter(testModel); - } - /** children are also unsorted nodes */ - @Override - protected TestNode buildChildNode(TestModel childNode) { - return new UnsortedTestNode(this, childNode); - } - - } - - - /** - * concrete implementation that leaves its children unsorted - * and has a special set of children for "node 3" - */ - public static class SpecialTestNode extends UnsortedTestNode { - - // ********** constructors ********** - public SpecialTestNode(TestModel testModel) { - super(testModel); - } - public SpecialTestNode(TestNode parent, TestModel testModel) { - super(parent, testModel); - } - - // ********** initialization ********** - /** return a different list of children for "node 3" */ - @Override - protected ListValueModel<TreeNodeValueModel<Object>> buildChildrenModel(TestModel testModel) { - if (testModel.getName().equals("node 3")) { - return this.buildSpecialChildrenModel(); - } - return super.buildChildrenModel(testModel); - } - protected ListValueModel<TreeNodeValueModel<Object>> buildSpecialChildrenModel() { - TreeNodeValueModel<Object>[] children = new NameTestNode[1]; - children[0] = new NameTestNode(this); - return new SimpleListValueModel<TreeNodeValueModel<Object>>(Arrays.asList(children)); - } - /** children are also special nodes */ - @Override - protected TestNode buildChildNode(TestModel childNode) { - return new SpecialTestNode(this, childNode); - } - - } - - - public static class NameTestNode extends AbstractTreeNodeValueModel<Object> { - private final WritablePropertyValueModel<String> nameAdapter; - private final SpecialTestNode specialNode; // parent node - private final PropertyChangeListener nameListener; - private final ListValueModel<TreeNodeValueModel<Object>> childrenModel; - - // ********** construction/initialization ********** - - public NameTestNode(SpecialTestNode specialNode) { - super(); - this.nameListener = this.buildNameListener(); - this.specialNode = specialNode; - this.nameAdapter = this.buildNameAdapter(); - this.childrenModel = new NullListValueModel<TreeNodeValueModel<Object>>(); - } - protected PropertyChangeListener buildNameListener() { - return new PropertyChangeListener() { - public void propertyChanged(PropertyChangeEvent e) { - NameTestNode.this.nameChanged(e); - } - }; - } - protected WritablePropertyValueModel<String> buildNameAdapter() { - return new PropertyAspectAdapter<TestModel, String>(TestModel.NAME_PROPERTY, this.getTestModel()) { - @Override - protected String buildValue_() { - return this.subject.getName(); - } - @Override - protected void setValue_(String value) { - this.subject.setName(value); - } - }; - } - - public TestModel getTestModel() { - return this.specialNode.getTestModel(); - } - - // ********** TreeNodeValueModel implementation ********** - - public String getValue() { - return this.nameAdapter.getValue(); - } - @Override - public void setValue(Object value) { - this.nameAdapter.setValue((String) value); - } - public TreeNodeValueModel<Object> parent() { - return this.specialNode; - } - public ListValueModel<TreeNodeValueModel<Object>> childrenModel() { - return this.childrenModel; - } - - // ********** AbstractTreeNodeValueModel implementation ********** - - @Override - protected void engageValue() { - this.nameAdapter.addPropertyChangeListener(PropertyValueModel.VALUE, this.nameListener); - } - @Override - protected void disengageValue() { - this.nameAdapter.removePropertyChangeListener(PropertyValueModel.VALUE, this.nameListener); - } - - // ********** behavior ********** - - protected void nameChanged(PropertyChangeEvent e) { - // we need to notify listeners that our "value" has changed - this.firePropertyChanged(VALUE, e.getOldValue(), e.getNewValue()); - } - } - - private TreeModel buildTreeModel(TestNode root) { - return this.buildTreeModel(new StaticPropertyValueModel<TreeNodeValueModel<Object>>(root)); - } - - private TreeModel buildTreeModel(PropertyValueModel<TreeNodeValueModel<Object>> rootHolder) { - return new TreeModelAdapter<Object>(rootHolder) { - @Override - protected ListChangeListener buildChildrenListener() { - return this.buildChildrenListener_(); - } - @Override - protected StateChangeListener buildNodeStateListener() { - return this.buildNodeStateListener_(); - } - @Override - protected PropertyChangeListener buildNodeValueListener() { - return this.buildNodeValueListener_(); - } - @Override - protected PropertyChangeListener buildRootListener() { - return this.buildRootListener_(); - } - }; - } - - - - /** - * listener that will blow up with any event; - * override and implement expected event methods - */ - public class TestTreeModelListener implements TreeModelListener { - public void treeNodesChanged(TreeModelEvent e) { - fail("unexpected event"); - } - public void treeNodesInserted(TreeModelEvent e) { - fail("unexpected event"); - } - public void treeNodesRemoved(TreeModelEvent e) { - fail("unexpected event"); - } - public void treeStructureChanged(TreeModelEvent e) { - fail("unexpected event"); - } - } - -} diff --git a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java b/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java deleted file mode 100644 index b8f40c394f..0000000000 --- a/jpa/tests/org.eclipse.jpt.utility.tests/src/org/eclipse/jpt/utility/tests/internal/model/value/swing/TreeModelAdapterUITest.java +++ /dev/null @@ -1,424 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007, 2008 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. - * - * Contributors: - * Oracle - initial API and implementation - ******************************************************************************/ -package org.eclipse.jpt.utility.tests.internal.model.value.swing; - -import java.awt.BorderLayout; -import java.awt.Component; -import java.awt.GridLayout; -import java.awt.TextField; -import java.awt.event.ActionEvent; -import java.awt.event.WindowAdapter; -import java.awt.event.WindowEvent; -import java.awt.event.WindowListener; -import java.util.Collection; -import java.util.Collections; -import java.util.Enumeration; -import javax.swing.AbstractAction; -import javax.swing.Action; -import javax.swing.JButton; -import javax.swing.JFrame; -import javax.swing.JPanel; -import javax.swing.JScrollPane; -import javax.swing.JTree; -import javax.swing.WindowConstants; -import javax.swing.event.TreeSelectionEvent; -import javax.swing.event.TreeSelectionListener; -import javax.swing.tree.DefaultTreeSelectionModel; -import javax.swing.tree.TreeModel; -import javax.swing.tree.TreePath; -import javax.swing.tree.TreeSelectionModel; -import org.eclipse.jpt.utility.internal.CollectionTools; -import org.eclipse.jpt.utility.internal.iterators.EnumerationIterator; -import org.eclipse.jpt.utility.internal.model.value.SimplePropertyValueModel; -import org.eclipse.jpt.utility.internal.model.value.swing.TreeModelAdapter; -import org.eclipse.jpt.utility.internal.swing.Displayable; -import org.eclipse.jpt.utility.model.value.TreeNodeValueModel; -import org.eclipse.jpt.utility.model.value.WritablePropertyValueModel; -import org.eclipse.jpt.utility.tests.internal.model.value.swing.TreeModelAdapterTests.SortedTestNode; -import org.eclipse.jpt.utility.tests.internal.model.value.swing.TreeModelAdapterTests.TestModel; -import org.eclipse.jpt.utility.tests.internal.model.value.swing.TreeModelAdapterTests.TestNode; -import org.eclipse.jpt.utility.tests.internal.model.value.swing.TreeModelAdapterTests.UnsortedTestNode; - -/** - * an example UI for testing the TreeModelAdapter - */ -public class TreeModelAdapterUITest { - - // hold the tree so we can restore its expansion state - private JTree tree; - private WritablePropertyValueModel<TreeNodeValueModel<Object>> rootNodeHolder; - private boolean sorted; - private TreeModel treeModel; - private TreeSelectionModel treeSelectionModel; - private TextField nameTextField; - - public static void main(String[] args) throws Exception { - new TreeModelAdapterUITest().exec(args); - } - - private TreeModelAdapterUITest() { - super(); - } - - private void exec(String[] args) throws Exception { - this.rootNodeHolder = this.buildRootNodeHolder(); - this.sorted = this.rootNodeHolder.getValue() instanceof SortedTestNode; - this.treeModel = this.buildTreeModel(); - this.treeSelectionModel = this.buildTreeSelectionModel(); - this.nameTextField = new TextField(); - this.openWindow(); - } - - private WritablePropertyValueModel<TreeNodeValueModel<Object>> buildRootNodeHolder() { - return new SimplePropertyValueModel<TreeNodeValueModel<Object>>(this.buildSortedRootNode()); - } - - private TestNode buildSortedRootNode() { - return new SortedTestNode(this.buildRoot()); - } - - private TestNode buildUnsortedRootNode() { - return new UnsortedTestNode(this.buildRoot()); - } - - private TestModel buildRoot() { - TestModel root = new TestModel("root"); - - TestModel node_1 = root.addChild("node 1"); - /*Node node_1_1 = */node_1.addChild("node 1.1"); - - TestModel node_2 = root.addChild("node 2"); - /*Node node_2_1 = */node_2.addChild("node 2.1"); - TestModel node_2_2 = node_2.addChild("node 2.2"); - /*Node node_2_2_1 = */node_2_2.addChild("node 2.2.1"); - /*Node node_2_2_2 = */node_2_2.addChild("node 2.2.2"); - /*Node node_2_3 = */node_2.addChild("node 2.3"); - /*Node node_2_4 = */node_2.addChild("node 2.4"); - /*Node node_2_5 = */node_2.addChild("node 2.5"); - - TestModel node_3 = root.addChild("node 3"); - TestModel node_3_1 = node_3.addChild("node 3.1"); - TestModel node_3_1_1 = node_3_1.addChild("node 3.1.1"); - /*Node node_3_1_1_1 = */node_3_1_1.addChild("node 3.1.1.1"); - - /*Node node_4 = */root.addChild("node 4"); - - return root; - } - - private TreeModel buildTreeModel() { - return new TreeModelAdapter<Object>(this.rootNodeHolder); - } - - private TreeSelectionModel buildTreeSelectionModel() { - TreeSelectionModel tsm = new DefaultTreeSelectionModel(); - tsm.addTreeSelectionListener(this.buildTreeSelectionListener()); - tsm.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); - return tsm; - } - - private TreeSelectionListener buildTreeSelectionListener() { - return new TreeSelectionListener() { - public void valueChanged(TreeSelectionEvent e) { - TreeModelAdapterUITest.this.treeSelectionChanged(e); - } - }; - } - - void treeSelectionChanged(TreeSelectionEvent e) { - TestModel selectedTestModel = this.selectedTestModel(); - if (selectedTestModel != null) { - this.nameTextField.setText(selectedTestModel.getName()); - } - } - - private void openWindow() { - JFrame window = new JFrame(this.getClass().getName()); - window.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); - window.addWindowListener(this.buildWindowListener()); - window.getContentPane().add(this.buildMainPanel(), "Center"); - window.setLocation(300, 300); - window.setSize(400, 400); - window.setVisible(true); - } - - private WindowListener buildWindowListener() { - return new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - e.getWindow().setVisible(false); - System.exit(0); - } - }; - } - - private Component buildMainPanel() { - JPanel mainPanel = new JPanel(new BorderLayout()); - mainPanel.add(this.buildTreePane(), BorderLayout.CENTER); - mainPanel.add(this.buildControlPanel(), BorderLayout.SOUTH); - return mainPanel; - } - - private Component buildTreePane() { - return new JScrollPane(this.buildTree()); - } - - private JTree buildTree() { - this.tree = new JTree(this.treeModel) { - @Override - public String convertValueToText(Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { - return ((Displayable) value).displayString(); - } - }; - this.tree.setSelectionModel(this.treeSelectionModel); - this.tree.setRootVisible(true); - this.tree.setShowsRootHandles(true); - this.tree.setRowHeight(20); - this.tree.setDoubleBuffered(true); - return this.tree; - } - - private Component buildControlPanel() { - JPanel controlPanel = new JPanel(new GridLayout(0, 1)); - controlPanel.add(this.buildAddRenameNodePanel()); - controlPanel.add(this.buildMiscPanel()); - return controlPanel; - } - - private Component buildAddRenameNodePanel() { - JPanel addRenameNodePanel = new JPanel(new BorderLayout()); - addRenameNodePanel.add(this.buildAddButton(), BorderLayout.WEST); - addRenameNodePanel.add(this.nameTextField, BorderLayout.CENTER); - addRenameNodePanel.add(this.buildRenameButton(), BorderLayout.EAST); - return addRenameNodePanel; - } - - private Component buildMiscPanel() { - JPanel miscPanel = new JPanel(new GridLayout(1, 0)); - miscPanel.add(this.buildClearChildrenButton()); - miscPanel.add(this.buildRemoveButton()); - miscPanel.add(this.buildResetButton()); - return miscPanel; - } - - private String getName() { - return this.nameTextField.getText(); - } - - // ********** queries ********** - private TestNode selectedNode() { - if (this.treeSelectionModel.isSelectionEmpty()) { - return null; - } - return (TestNode) this.treeSelectionModel.getSelectionPath().getLastPathComponent(); - } - - private TestModel selectedTestModel() { - if (this.treeSelectionModel.isSelectionEmpty()) { - return null; - } - return this.selectedNode().getValue(); - } - - private TestNode rootNode() { - return (TestNode) this.treeModel.getRoot(); - } - - private TestModel root() { - return this.rootNode().getValue(); - } - - private Collection<TreePath> expandedPaths() { - Enumeration<TreePath> stream = this.tree.getExpandedDescendants(new TreePath(this.rootNode())); - if (stream == null) { - return Collections.emptyList(); - } - return CollectionTools.list(new EnumerationIterator<TreePath>(stream)); - } - - // ********** behavior ********** - private void setSelectedNode(TestNode selectedNode) { - this.treeSelectionModel.setSelectionPath(new TreePath(selectedNode.path())); - } - - private void expandPaths(Collection<TreePath> paths) { - for (TreePath path : paths) { - this.tree.expandPath(path); - } - } - - // ********** add ********** - private JButton buildAddButton() { - return new JButton(this.buildAddAction()); - } - - private Action buildAddAction() { - Action action = new AbstractAction("add") { - public void actionPerformed(ActionEvent event) { - TreeModelAdapterUITest.this.addNode(); - } - }; - action.setEnabled(true); - return action; - } - - /** - * adding causes the tree to be sorted and nodes to be - * removed and re-added; so we have to fiddle with the expansion state - */ - void addNode() { - TestModel selectedTestModel = this.selectedTestModel(); - if (selectedTestModel != null) { - String name = this.getName(); - // save the expansion state and restore it after the add - Collection<TreePath> paths = this.expandedPaths(); - - selectedTestModel.addChild(name); - - this.expandPaths(paths); - this.setSelectedNode(this.selectedNode().childNamed(name)); - } - } - - // ********** remove ********** - private JButton buildRemoveButton() { - return new JButton(this.buildRemoveAction()); - } - - private Action buildRemoveAction() { - Action action = new AbstractAction("remove") { - public void actionPerformed(ActionEvent event) { - TreeModelAdapterUITest.this.removeNode(); - } - }; - action.setEnabled(true); - return action; - } - - /** - * we need to figure out which node to select after - * the selected node is deleted - */ - void removeNode() { - TestModel selectedTestModel = this.selectedTestModel(); - // do not allow the root to be removed - if ((selectedTestModel != null) && (selectedTestModel != this.root())) { - // save the parent and index, so we can select another, nearby, node - // once the selected node is removed - TestNode parentNode = (TestNode) this.selectedNode().parent(); - int childIndex = parentNode.indexOfChild(this.selectedNode()); - - selectedTestModel.getParent().removeChild(selectedTestModel); - - int childrenSize = parentNode.childrenSize(); - if (childIndex < childrenSize) { - // select the child that moved up and replaced the just-deleted child - this.setSelectedNode((TestNode) parentNode.child(childIndex)); - } else { - if (childrenSize == 0) { - // if there are no more children, select the parent - this.setSelectedNode(parentNode); - } else { - // if the child at the bottom of the list was deleted, select the next child up - this.setSelectedNode((TestNode) parentNode.child(childIndex - 1)); - } - } - } - } - - // ********** rename ********** - private JButton buildRenameButton() { - return new JButton(this.buildRenameAction()); - } - - private Action buildRenameAction() { - Action action = new AbstractAction("rename") { - public void actionPerformed(ActionEvent event) { - TreeModelAdapterUITest.this.renameNode(); - } - }; - action.setEnabled(true); - return action; - } - - /** - * renaming causes the tree to be sorted and nodes to be - * removed and re-added; so we have to fiddle with the expansion state - */ - void renameNode() { - TestModel selectedTestModel = this.selectedTestModel(); - if (selectedTestModel != null) { - // save the node and re-select it after the rename - TestNode selectedNode = this.selectedNode(); - // save the expansion state and restore it after the rename - Collection<TreePath> paths = this.expandedPaths(); - - selectedTestModel.setName(this.getName()); - - this.expandPaths(paths); - this.setSelectedNode(selectedNode); - } - } - - // ********** clear children ********** - private JButton buildClearChildrenButton() { - return new JButton(this.buildClearChildrenAction()); - } - - private Action buildClearChildrenAction() { - Action action = new AbstractAction("clear children") { - public void actionPerformed(ActionEvent event) { - TreeModelAdapterUITest.this.clearChildren(); - } - }; - action.setEnabled(true); - return action; - } - - /** - * nothing special, we just want to test #fireCollectionChanged(String) - */ - void clearChildren() { - TestModel selectedTestModel = this.selectedTestModel(); - if (selectedTestModel != null) { - selectedTestModel.clearChildren(); - } - } - - // ********** reset ********** - private JButton buildResetButton() { - return new JButton(this.buildResetAction()); - } - - private Action buildResetAction() { - Action action = new AbstractAction("reset") { - public void actionPerformed(ActionEvent event) { - TreeModelAdapterUITest.this.reset(); - } - }; - action.setEnabled(true); - return action; - } - - /** - * test the adapter's root node holder; - * toggle between sorted and unsorted lists - */ - void reset() { - this.sorted = ! this.sorted; - if (this.sorted) { - this.rootNodeHolder.setValue(this.buildSortedRootNode()); - } else { - this.rootNodeHolder.setValue(this.buildUnsortedRootNode()); - } - this.tree.expandPath(new TreePath(this.rootNode())); - } - -} |