01: /*******************************************************************************
02: * Copyright (c) 2007 Brad Reynolds and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Brad Reynolds - initial API and implementation
10: ******************************************************************************/package org.eclipse.core.tests.databinding.observable.set;
11:
12: import java.util.HashSet;
13: import java.util.Set;
14:
15: import junit.framework.Test;
16: import junit.framework.TestCase;
17:
18: import org.eclipse.core.databinding.observable.Diffs;
19: import org.eclipse.core.databinding.observable.IObservable;
20: import org.eclipse.core.databinding.observable.IObservableCollection;
21: import org.eclipse.core.databinding.observable.Realm;
22: import org.eclipse.core.databinding.observable.set.IObservableSet;
23: import org.eclipse.core.databinding.observable.set.ObservableSet;
24: import org.eclipse.core.databinding.observable.set.SetDiff;
25: import org.eclipse.jface.conformance.databinding.AbstractObservableCollectionContractDelegate;
26: import org.eclipse.jface.conformance.databinding.ObservableCollectionContractTest;
27: import org.eclipse.jface.conformance.databinding.SuiteBuilder;
28:
29: /**
30: * @since 1.1
31: */
32: public class ObservableSetTest extends TestCase {
33: public static Test suite() {
34: Delegate delegate = new Delegate();
35:
36: return new SuiteBuilder().addObservableContractTest(
37: ObservableCollectionContractTest.class, delegate)
38: .build();
39: }
40:
41: private static class Delegate extends
42: AbstractObservableCollectionContractDelegate {
43: private Delegate() {
44: }
45:
46: public void change(IObservable observable) {
47: ((ObservableSetStub) observable).fireSetChange(Diffs
48: .createSetDiff(new HashSet(), new HashSet()));
49: }
50:
51: public Object createElement(IObservableCollection collection) {
52: return Integer.toString(collection.size());
53: }
54:
55: public Object getElementType(IObservableCollection collection) {
56: return String.class;
57: }
58:
59: public IObservableCollection createObservableCollection(
60: Realm realm, int elementCount) {
61: IObservableSet set = new ObservableSetStub(realm,
62: new HashSet(), String.class);
63:
64: for (int i = 0; i < elementCount; i++) {
65: set.add(Integer.toString(i));
66: }
67:
68: return set;
69: }
70: }
71:
72: private static class ObservableSetStub extends ObservableSet {
73: /**
74: * @param wrappedSet
75: * @param elementType
76: */
77: protected ObservableSetStub(Realm realm, Set wrappedSet,
78: Object elementType) {
79: super (realm, wrappedSet, elementType);
80: }
81:
82: public void fireSetChange(SetDiff diff) {
83: super.fireSetChange(diff);
84: }
85: }
86: }
|