1 /******************************************************************************* 2 * Copyright (c) 2008, 2009 Matthew Hall and others. 3 * 4 * This program and the accompanying materials 5 * are made available under the terms of the Eclipse Public License 2.0 6 * which accompanies this distribution, and is available at 7 * https://www.eclipse.org/legal/epl-2.0/ 8 * 9 * SPDX-License-Identifier: EPL-2.0 10 * 11 * Contributors: 12 * Matthew Hall - initial API and implementation (bug 215531) 13 * Matthew Hall - bug 213145 14 * (through ObservableViewerElementSetTest.java) 15 * Matthew Hall - bug 262269 16 ******************************************************************************/ 17 18 package org.eclipse.core.tests.internal.databinding.observable; 19 20 import org.eclipse.core.databinding.observable.IObservable; 21 import org.eclipse.core.databinding.observable.IObservableCollection; 22 import org.eclipse.core.databinding.observable.Realm; 23 import org.eclipse.core.databinding.observable.set.IObservableSet; 24 import org.eclipse.core.internal.databinding.identity.IdentityObservableSet; 25 import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest; 26 import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate; 27 28 import junit.framework.TestSuite; 29 30 public class IdentityObservableSetTest { addConformanceTest(TestSuite suite)31 public static void addConformanceTest(TestSuite suite) { 32 suite.addTest(MutableObservableSetContractTest.suite(new Delegate())); 33 } 34 35 private static class Delegate extends 36 AbstractObservableCollectionContractDelegate { 37 38 @Override createObservableCollection(Realm realm, int elementCount)39 public IObservableCollection createObservableCollection(Realm realm, 40 int elementCount) { 41 IdentityObservableSet set = new IdentityObservableSet(realm, 42 Object.class); 43 for (int i = 0; i < elementCount; i++) 44 set.add(createElement(set)); 45 return set; 46 } 47 48 @Override createElement(IObservableCollection collection)49 public Object createElement(IObservableCollection collection) { 50 return new Object(); 51 } 52 53 @Override change(IObservable observable)54 public void change(IObservable observable) { 55 IObservableSet set = (IObservableSet) observable; 56 set.add(createElement(set)); 57 } 58 59 @Override getElementType(IObservableCollection collection)60 public Object getElementType(IObservableCollection collection) { 61 return Object.class; 62 } 63 } 64 } 65