001: /*
002: * Copyright 2003-2004 The Apache Software Foundation
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016: package org.apache.commons.events.observable;
017:
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.Collection;
021: import java.util.List;
022:
023: import junit.framework.Test;
024: import junit.framework.TestSuite;
025:
026: import org.apache.commons.collections.collection.AbstractTestCollection;
027:
028: /**
029: * Extension of {@link TestCollection} for exercising the
030: * {@link ObservedCollection} implementation.
031: *
032: * @since Commons Events 1.0
033: * @version $Revision: 155443 $ $Date: 2005-02-26 06:19:51 -0700 (Sat, 26 Feb 2005) $
034: *
035: * @author Stephen Colebourne
036: */
037: public class TestObservableCollection extends AbstractTestCollection
038: implements ObservedTestHelper.ObservedFactory {
039:
040: public TestObservableCollection(String testName) {
041: super (testName);
042: }
043:
044: public static Test suite() {
045: return new TestSuite(TestObservableCollection.class);
046: }
047:
048: public static void main(String args[]) {
049: String[] testCaseName = { TestObservableCollection.class
050: .getName() };
051: junit.textui.TestRunner.main(testCaseName);
052: }
053:
054: //-----------------------------------------------------------------------
055: public Collection makeConfirmedCollection() {
056: return new ArrayList();
057: }
058:
059: public Collection makeConfirmedFullCollection() {
060: List list = new ArrayList();
061: list.addAll(Arrays.asList(getFullElements()));
062: return list;
063: }
064:
065: public Collection makeCollection() {
066: return ObservableCollection.decorate(new ArrayList(),
067: ObservedTestHelper.LISTENER);
068: }
069:
070: public Collection makeFullCollection() {
071: List list = new ArrayList();
072: list.addAll(Arrays.asList(getFullElements()));
073: return ObservableCollection.decorate(list,
074: ObservedTestHelper.LISTENER);
075: }
076:
077: //-----------------------------------------------------------------------
078: public void testObservedCollection() {
079: ObservedTestHelper.bulkTestObservedCollection(this );
080: }
081:
082: //-----------------------------------------------------------------------
083: public ObservableCollection createObservedCollection() {
084: return ObservableCollection.decorate(new ArrayList());
085: }
086:
087: public ObservableCollection createObservedCollection(Object listener) {
088: return ObservableCollection.decorate(new ArrayList(), listener);
089: }
090:
091: // public void testFactoryWithMasks() {
092: // ObservedCollection coll = ObservedCollection.decorate(new ArrayList(), LISTENER, -1, 0);
093: // LISTENER.preEvent = null;
094: // LISTENER.postEvent = null;
095: // coll.add(SIX);
096: // assertTrue(LISTENER.preEvent != null);
097: // assertTrue(LISTENER.postEvent == null);
098: //
099: // coll = ObservedCollection.decorate(new ArrayList(), LISTENER, 0, -1);
100: // LISTENER.preEvent = null;
101: // LISTENER.postEvent = null;
102: // coll.add(SIX);
103: // assertTrue(LISTENER.preEvent == null);
104: // assertTrue(LISTENER.postEvent != null);
105: //
106: // coll = ObservedCollection.decorate(new ArrayList(), LISTENER, -1, -1);
107: // LISTENER.preEvent = null;
108: // LISTENER.postEvent = null;
109: // coll.add(SIX);
110: // assertTrue(LISTENER.preEvent != null);
111: // assertTrue(LISTENER.postEvent != null);
112: //
113: // coll = ObservedCollection.decorate(new ArrayList(), LISTENER, 0, 0);
114: // LISTENER.preEvent = null;
115: // LISTENER.postEvent = null;
116: // coll.add(SIX);
117: // assertTrue(LISTENER.preEvent == null);
118: // assertTrue(LISTENER.postEvent == null);
119: //
120: // coll = ObservedCollection.decorate(new ArrayList(), LISTENER, ModificationEventType.ADD, ModificationEventType.ADD_ALL);
121: // LISTENER.preEvent = null;
122: // LISTENER.postEvent = null;
123: // coll.add(SIX);
124: // assertTrue(LISTENER.preEvent != null);
125: // assertTrue(LISTENER.postEvent == null);
126: // }
127: //
128: }
|