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.AbstractObservableSet;
23: import org.eclipse.core.databinding.observable.set.SetDiff;
24: import org.eclipse.jface.conformance.databinding.AbstractObservableCollectionContractDelegate;
25: import org.eclipse.jface.conformance.databinding.ObservableCollectionContractTest;
26: import org.eclipse.jface.conformance.databinding.SuiteBuilder;
27:
28: /**
29: */
30: public class AbstractObservableSetTest extends TestCase {
31: public static Test suite() {
32: Delegate delegate = new Delegate();
33:
34: return new SuiteBuilder().addObservableContractTest(
35: ObservableCollectionContractTest.class, delegate)
36: .build();
37: }
38:
39: private static class Delegate extends
40: AbstractObservableCollectionContractDelegate {
41: public void change(IObservable observable) {
42: ((AbstractObservableSetStub) observable)
43: .fireSetChange(Diffs.createSetDiff(new HashSet(),
44: new HashSet()));
45: }
46:
47: public Object createElement(IObservableCollection collection) {
48: return Integer.toString(collection.size());
49: }
50:
51: public Object getElementType(IObservableCollection collection) {
52: return String.class;
53: }
54:
55: public IObservableCollection createObservableCollection(
56: Realm realm, int elementCount) {
57: AbstractObservableSetStub set = new AbstractObservableSetStub(
58: realm, String.class);
59:
60: for (int i = 0; i < elementCount; i++) {
61: set.getWrappedSet().add(Integer.toString(i));
62: }
63:
64: return set;
65: }
66: }
67:
68: private static class AbstractObservableSetStub extends
69: AbstractObservableSet {
70: private Object type;
71: private HashSet set;
72:
73: private AbstractObservableSetStub(Realm realm, Object type) {
74: super (realm);
75: set = new HashSet();
76: this .type = type;
77: }
78:
79: protected Set getWrappedSet() {
80: return set;
81: }
82:
83: public Object getElementType() {
84: return type;
85: }
86:
87: protected void fireSetChange(SetDiff diff) {
88: super.fireSetChange(diff);
89: }
90: }
91: }
|