Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
View | Details | Raw Unified | Return to bug 182059 | Differences between
and this patch

Collapse All | Expand All

(-)plugin.properties (+12 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2007 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
#     IBM Corporation - initial API and implementation
10
###############################################################################
11
pluginName = JFace Data Binding Conformance Tests
12
providerName = Eclipse.org
(-)src/org/eclipse/jface/databinding/conformance/MutableObservableSetContractTest.java (+266 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.List;
17
import java.util.Set;
18
19
import org.eclipse.core.databinding.observable.set.IObservableSet;
20
import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate;
21
import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker;
22
import org.eclipse.jface.databinding.conformance.util.SetChangeEventTracker;
23
24
/**
25
 */
26
public class MutableObservableSetContractTest extends
27
		MutableObservableCollectionContractTest {
28
	private IObservableCollectionContractDelegate delegate;
29
30
	private IObservableSet set;
31
32
	public MutableObservableSetContractTest(String testName,
33
			IObservableCollectionContractDelegate delegate) {
34
		super(testName, delegate);
35
		this.delegate = delegate;
36
	}
37
38
	/**
39
	 * @param delegate
40
	 */
41
	public MutableObservableSetContractTest(
42
			IObservableCollectionContractDelegate delegate) {
43
		super(delegate);
44
	}
45
46
	protected void setUp() throws Exception {
47
		super.setUp();
48
		set = (IObservableSet) getObservable();
49
	}
50
51
	public void testAdd_SetChangeEvent() throws Exception {
52
		assertSetChangeEventFired(new Runnable() {
53
			public void run() {
54
				set.add(delegate.createElement(set));
55
			}
56
		}, "Set.add(Object)", set);
57
	}
58
59
	public void testAdd_SetDiffEntry() throws Exception {
60
		set.add(delegate.createElement(set));
61
		final Object element = delegate.createElement(set);
62
63
		assertAddDiffEntry(new Runnable() {
64
			public void run() {
65
				set.add(element);
66
			}
67
		}, "Set.add(Object)", set, element);
68
	}
69
70
	public void testAddAll_SetChangeEvent() throws Exception {
71
		assertSetChangeEventFired(new Runnable() {
72
			public void run() {
73
				set.addAll(Arrays.asList(new Object[] { delegate
74
						.createElement(set) }));
75
			}
76
		}, "Set.addAll(Collection", set);
77
	}
78
79
	public void testAddAll_SetDiffEntry() throws Exception {
80
		final Object element = delegate.createElement(set);
81
82
		assertAddDiffEntry(new Runnable() {
83
			public void run() {
84
				set.addAll(Arrays.asList(new Object[] { element }));
85
			}
86
		}, "Set.addAll(Collection)", set, element);
87
	}
88
89
	public void testRemove_SetChangeEvent() throws Exception {
90
		final Object element = delegate.createElement(set);
91
		set.add(element);
92
93
		assertSetChangeEventFired(new Runnable() {
94
			public void run() {
95
				set.remove(element);
96
			}
97
		}, "Set.remove(Object)", set);
98
	}
99
100
	public void testRemove_SetDiffEntry() throws Exception {
101
		set.add(delegate.createElement(set));
102
		final Object element = delegate.createElement(set);
103
		set.add(element);
104
105
		assertRemoveDiffEntry(new Runnable() {
106
			public void run() {
107
				set.remove(element);
108
			}
109
		}, "Set.remove(Object)", set, element);
110
	}
111
112
	public void testRemoveAll_SetChangeEvent() throws Exception {
113
		final Object element = delegate.createElement(set);
114
		set.add(element);
115
116
		assertSetChangeEventFired(new Runnable() {
117
			public void run() {
118
				set.removeAll(Arrays.asList(new Object[] { element }));
119
			}
120
		}, "Set.removeAll(Collection)", set);
121
	}
122
123
	public void testRemoveAll_SetDiffEntry() throws Exception {
124
		final Object element = delegate.createElement(set);
125
		set.add(element);
126
127
		assertRemoveDiffEntry(new Runnable() {
128
			public void run() {
129
				set.removeAll(Arrays.asList(new Object[] { element }));
130
			}
131
		}, "Set.removeAll(Collection)", set, element);
132
	}
133
134
	public void testRetainAll_SetChangeEvent() throws Exception {
135
		final Object element1 = delegate.createElement(set);
136
		set.add(element1);
137
		set.add(delegate.createElement(set));
138
139
		assertSetChangeEventFired(new Runnable() {
140
			public void run() {
141
				set.retainAll(Arrays.asList(new Object[] { element1 }));
142
			}
143
		}, "Set.retainAll(Collection", set);
144
	}
145
146
	public void testRetainAll_SetDiffEntry() throws Exception {
147
		final Object element1 = delegate.createElement(set);
148
		set.add(element1);
149
		Object element2 = delegate.createElement(set);
150
		set.add(delegate.createElement(set));
151
152
		assertRemoveDiffEntry(new Runnable() {
153
			public void run() {
154
				set.retainAll(Arrays.asList(new Object[] { element1 }));
155
			}
156
		}, "Set.retainAll(Collection)", set, element2);
157
	}
158
159
	public void testClear_SetChangeEvent() throws Exception {
160
		set.add(delegate.createElement(set));
161
162
		assertSetChangeEventFired(new Runnable() {
163
			public void run() {
164
				set.clear();
165
			}
166
		}, "Set.clear()", set);
167
	}
168
169
	public void testClear_SetDiffEntry() throws Exception {
170
		Object element = delegate.createElement(set);
171
		set.add(element);
172
173
		assertRemoveDiffEntry(new Runnable() {
174
			public void run() {
175
				set.clear();
176
			}
177
		}, "Set.clear()", set, element);
178
	}
179
180
	/**
181
	 * Asserts standard behaviors of firing set change events.
182
	 * <ul>
183
	 * <li>Event fires once.</li>
184
	 * <li>Source of the event is the provided <code>set</code>.
185
	 * <li>The set change event is fired after the change event.</li>
186
	 * </ul>
187
	 * 
188
	 * @param runnable
189
	 * @param methodName
190
	 * @param set
191
	 */
192
	private void assertSetChangeEventFired(Runnable runnable,
193
			String methodName, IObservableSet set) {
194
		List queue = new ArrayList();
195
		SetChangeEventTracker setListener = new SetChangeEventTracker(queue);
196
		ChangeEventTracker changeListener = new ChangeEventTracker(queue);
197
198
		set.addSetChangeListener(setListener);
199
		set.addChangeListener(changeListener);
200
201
		runnable.run();
202
203
		assertEquals(formatFail(methodName + " should fire one SetChangeEvent."), 1,
204
				setListener.count);
205
		assertEquals(formatFail(methodName
206
				+ "'s change event observable should be the created Set."), set,
207
				setListener.event.getObservable());
208
209
		assertEquals(formatFail("Two notifications should have been received."), 2, queue
210
				.size());
211
		assertEquals(formatFail("ChangeEvent of " + methodName
212
				+ " should have fired before the SetChangeEvent."),
213
				changeListener, queue.get(0));
214
		assertEquals(formatFail("SetChangeEvent of " + methodName
215
				+ " should have fired after the ChangeEvent."), setListener,
216
				queue.get(1));
217
	}
218
219
	/**
220
	 * Asserts the set diff entry for an add operation.
221
	 * 
222
	 * @param runnable
223
	 * @param methodName
224
	 * @param set
225
	 * @param element
226
	 */
227
	private void assertAddDiffEntry(Runnable runnable, String methodName,
228
			IObservableSet set, Object element) {
229
		SetChangeEventTracker listener = new SetChangeEventTracker();
230
		set.addSetChangeListener(listener);
231
232
		runnable.run();
233
234
		Set entries = listener.event.diff.getAdditions();
235
		assertEquals(formatFail(methodName + " should result in one diff entry."), 1,
236
				entries.size());
237
238
		assertTrue(formatFail(methodName
239
				+ " should result in a diff entry that is an addition."),
240
				entries.contains(element));
241
	}
242
243
	/**
244
	 * Asserts the set diff entry for a remove operation.
245
	 * 
246
	 * @param runnable
247
	 * @param methodName
248
	 * @param set
249
	 * @param element
250
	 */
251
	private void assertRemoveDiffEntry(Runnable runnable, String methodName,
252
			IObservableSet set, Object element) {
253
		SetChangeEventTracker listener = new SetChangeEventTracker();
254
		set.addSetChangeListener(listener);
255
256
		runnable.run();
257
258
		Set entries = listener.event.diff.getRemovals();
259
		assertEquals(formatFail(methodName + " should result in one diff entry."), 1,
260
				entries.size());
261
262
		assertTrue(formatFail(methodName
263
				+ " should result in a diff entry that is an addition."),
264
				entries.contains(element));
265
	}
266
}
(-)about.html (+28 lines)
Added Link Here
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
<html xmlns="http://www.w3.org/1999/xhtml">
4
<head>
5
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"/>
6
<title>About</title>
7
</head>
8
<body lang="EN-US">
9
<h2>About This Content</h2>
10
 
11
<p>June 2, 2006</p>	
12
<h3>License</h3>
13
14
<p>The Eclipse Foundation makes available all content in this plug-in (&quot;Content&quot;).  Unless otherwise 
15
indicated below, the Content is provided to you under the terms and conditions of the
16
Eclipse Public License Version 1.0 (&quot;EPL&quot;).  A copy of the EPL is available 
17
at <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a>.
18
For purposes of the EPL, &quot;Program&quot; will mean the Content.</p>
19
20
<p>If you did not receive this Content directly from the Eclipse Foundation, the Content is 
21
being redistributed by another party (&quot;Redistributor&quot;) and different terms and conditions may
22
apply to your use of any object code in the Content.  Check the Redistributor's license that was 
23
provided with the Content.  If no such license exists, contact the Redistributor.  Unless otherwise
24
indicated below, the terms and conditions of the EPL still apply to any source code in the Content
25
and such source code may be obtained at <a href="http://www.eclipse.org">http://www.eclipse.org</a>.</p>
26
27
</body>
28
</html>
(-)src/org/eclipse/jface/databinding/conformance/MutableObservableListContractTest.java (+493 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.List;
17
18
import org.eclipse.core.databinding.observable.list.IObservableList;
19
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
20
import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate;
21
import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker;
22
import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker;
23
24
25
/**
26
 * Mutability tests for IObservableList.
27
 * 
28
 * <p>
29
 * This class is experimental and can change at any time. It is recommended to
30
 * not subclass or assume the test names will not change. The only API that is
31
 * guaranteed to not change are the constructors. The tests will remain public
32
 * and not final in order to allow for consumers to turn off a test if needed by
33
 * subclassing.
34
 * </p>
35
 * 
36
 * @since 3.2
37
 */
38
public class MutableObservableListContractTest extends
39
		MutableObservableCollectionContractTest {
40
	private IObservableCollectionContractDelegate delegate;
41
42
	private IObservableList list;
43
44
	/**
45
	 * @param delegate
46
	 */
47
	public MutableObservableListContractTest(
48
			IObservableCollectionContractDelegate delegate) {
49
		super(delegate);
50
		this.delegate = delegate;
51
	}
52
53
	public MutableObservableListContractTest(String testName,
54
			IObservableCollectionContractDelegate delegate) {
55
		super(testName, delegate);
56
		this.delegate = delegate;
57
	}
58
59
	protected void setUp() throws Exception {
60
		super.setUp();
61
		list = (IObservableList) getObservable();
62
	}
63
64
	public void testAdd_ListChangeEvent() throws Exception {
65
		assertListChangeEventFired(new Runnable() {
66
			public void run() {
67
				list.add(delegate.createElement(list));
68
			}
69
		}, "List.add(Object)", list);
70
	}
71
72
	public void testAdd_ListDiffEntry() throws Exception {
73
		list.add(delegate.createElement(list));
74
		final Object element = delegate.createElement(list);
75
76
		assertAddDiffEntry(new Runnable() {
77
			public void run() {
78
				list.add(element);
79
			}
80
		}, "List.add(Object)", list, element, 1);
81
	}
82
83
	public void testAddAtIndex_ChangeEvent() throws Exception {
84
		assertChangeEventFired(new Runnable() {
85
			public void run() {
86
				list.add(0, delegate.createElement(list));
87
			}
88
		}, "List.add(int, Object)", list);
89
	}
90
91
	public void testAddAtIndex_ListChangeEvent() throws Exception {
92
		assertListChangeEventFired(new Runnable() {
93
			public void run() {
94
				list.add(0, delegate.createElement(list));
95
			}
96
		}, "List.add(int, Object)", list);
97
	}
98
99
	public void testAddAtIndex_ChangeEventFiredAfterElementIsAdded()
100
			throws Exception {
101
		final Object element = delegate.createElement(list);
102
103
		assertContainsDuringChangeEvent(new Runnable() {
104
			public void run() {
105
				list.add(0, element);
106
			}
107
		}, "List.add(int, Collection)", list, element);
108
	}
109
110
	public void testAddAtIndex_ListDiffEntry() throws Exception {
111
		list.add(delegate.createElement(list));
112
		final Object element = delegate.createElement(list);
113
114
		assertAddDiffEntry(new Runnable() {
115
			public void run() {
116
				list.add(1, element);
117
			}
118
		}, "List.add(int, Object)", list, element, 1);
119
	}
120
121
	public void testAddAll_ListChangeEvent() throws Exception {
122
		assertListChangeEventFired(new Runnable() {
123
			public void run() {
124
				list.addAll(Arrays.asList(new Object[] { delegate
125
						.createElement(list) }));
126
			}
127
		}, "List.addAll(Collection", list);
128
	}
129
130
	public void testAddAll_ListDiffEntry() throws Exception {
131
		final Object element = delegate.createElement(list);
132
133
		assertAddDiffEntry(new Runnable() {
134
			public void run() {
135
				list.addAll(Arrays.asList(new Object[] { element }));
136
			}
137
		}, "List.addAll(Collection)", list, element, 0);
138
	}
139
140
	public void testAddAllAtIndex_ChangeEvent() throws Exception {
141
		assertChangeEventFired(new Runnable() {
142
			public void run() {
143
				list.addAll(0, Arrays.asList(new Object[] { delegate
144
						.createElement(list) }));
145
			}
146
		}, "List.addAll(int, Collection)", list);
147
	}
148
149
	public void testAddAllAtIndex_ListChangeEvent() throws Exception {
150
		assertListChangeEventFired(new Runnable() {
151
			public void run() {
152
				list.addAll(0, Arrays.asList(new Object[] { delegate
153
						.createElement(list) }));
154
			}
155
		}, "List.addAll(int, Collection)", list);
156
	}
157
158
	public void testAddAllAtIndex_ChangeEventFiredAfterElementIsAdded()
159
			throws Exception {
160
		final Object element = delegate.createElement(list);
161
162
		assertContainsDuringChangeEvent(new Runnable() {
163
			public void run() {
164
				list.addAll(0, Arrays.asList(new Object[] { element }));
165
			}
166
		}, "List.addAll(int, Collection)", list, element);
167
	}
168
169
	public void testAddAllAtIndex_ListDiffEntry() throws Exception {
170
		list.add(delegate.createElement(list));
171
		final Object element = delegate.createElement(list);
172
173
		assertAddDiffEntry(new Runnable() {
174
			public void run() {
175
				list.addAll(1, Arrays.asList(new Object[] { element }));
176
			}
177
		}, "List.addAll(int, Collection)", list, element, 1);
178
	}
179
180
	public void testSet_ChangeEvent() throws Exception {
181
		list.add(delegate.createElement(list));
182
183
		assertChangeEventFired(new Runnable() {
184
			public void run() {
185
				list.set(0, delegate.createElement(list));
186
			}
187
		}, "List.set(int, Object)", list);
188
	}
189
190
	public void testSet_ListChangeEvent() throws Exception {
191
		list.add(delegate.createElement(list));
192
193
		assertListChangeEventFired(new Runnable() {
194
			public void run() {
195
				list.set(0, delegate.createElement(list));
196
			}
197
		}, "List.set(int, Object)", list);
198
	}
199
200
	public void testSet_ChangeEventFiredAfterElementIsSet() throws Exception {
201
		Object element1 = delegate.createElement(list);
202
		list.add(element1);
203
		final Object element2 = delegate.createElement(list);
204
205
		assertContainsDuringChangeEvent(new Runnable() {
206
			public void run() {
207
				list.set(0, element2);
208
			}
209
		}, "List.set(int, Object)", list, element2);
210
	}
211
212
	public void testSet_ListDiffEntry() throws Exception {
213
		list.add(delegate.createElement(list));
214
		Object oldElement = delegate.createElement(list);
215
		list.add(oldElement);
216
217
		ListChangeEventTracker listener = ListChangeEventTracker.observe(list);
218
219
		Object newElement = delegate.createElement(list);
220
		list.set(1, newElement);
221
222
		ListDiffEntry[] entries = listener.event.diff.getDifferences();
223
		assertEquals(
224
				"List.set(int, Object) should result in 2 list diff entries.",
225
				2, entries.length);
226
227
		ListDiffEntry add = null;
228
		ListDiffEntry remove = null;
229
230
		if (entries[0].isAddition() && !entries[1].isAddition()) {
231
			add = entries[0];
232
			remove = entries[1];
233
		} else if (!entries[0].isAddition() && entries[1].isAddition()) {
234
			add = entries[1];
235
			remove = entries[0];
236
		} else {
237
			fail("List.set(int, Object) should result in an add and a remove entry.");
238
		}
239
240
		assertEquals(
241
				"List.set(int, Object) removed element should be the old element.",
242
				oldElement, remove.getElement());
243
		assertEquals(
244
				"List.set(int, Object) removed index should be the index the new element was set at.",
245
				1, remove.getPosition());
246
247
		assertEquals(
248
				"List.set(int, Object) added element should be the set element.",
249
				newElement, add.getElement());
250
		assertEquals(
251
				"List.set(int, Object) add index should be the index the new element was set at.",
252
				1, add.getPosition());
253
	}
254
255
	public void testRemove_ListChangeEvent() throws Exception {
256
		final Object element = delegate.createElement(list);
257
		list.add(element);
258
259
		assertListChangeEventFired(new Runnable() {
260
			public void run() {
261
				list.remove(element);
262
			}
263
		}, "List.remove(Object)", list);
264
	}
265
266
	public void testRemove_ListDiffEntry() throws Exception {
267
		list.add(delegate.createElement(list));
268
		final Object element = delegate.createElement(list);
269
		list.add(element);
270
271
		assertRemoveDiffEntry(new Runnable() {
272
			public void run() {
273
				list.remove(element);
274
			}
275
		}, "List.remove(Object)", list, element, 1);
276
	}
277
278
	public void testRemoveAtIndex_ChangeEvent() throws Exception {
279
		list.add(delegate.createElement(list));
280
281
		assertChangeEventFired(new Runnable() {
282
			public void run() {
283
				list.remove(0);
284
			}
285
		}, "List.remove(int)", list);
286
	}
287
288
	public void testRemoveAtIndex_ListChangeEvent() throws Exception {
289
		list.add(delegate.createElement(list));
290
291
		assertListChangeEventFired(new Runnable() {
292
			public void run() {
293
				list.remove(0);
294
			}
295
		}, "List.remove(int)", list);
296
	}
297
298
	public void testRemoveAtIndex_ChangeEventFiredAfterElementIsRemoved()
299
			throws Exception {
300
		final Object element = delegate.createElement(list);
301
		list.add(element);
302
303
		assertDoesNotContainDuringChangeEvent(new Runnable() {
304
			public void run() {
305
				list.remove(0);
306
			}
307
		}, "List.remove(int)", list, element);
308
	}
309
310
	public void testRemoveAtIndex_ListDiffEntry() throws Exception {
311
		list.add(delegate.createElement(list));
312
		Object element = delegate.createElement(list);
313
		list.add(element);
314
315
		assertRemoveDiffEntry(new Runnable() {
316
			public void run() {
317
				list.remove(1);
318
			}
319
		}, "List.remove(int)", list, element, 1);
320
	}
321
322
	public void testRemoveAll_ListChangeEvent() throws Exception {
323
		final Object element = delegate.createElement(list);
324
325
		assertListChangeEventFired(new Runnable() {
326
			public void run() {
327
				list.removeAll(Arrays.asList(new Object[] { element }));
328
			}
329
		}, "List.removeAll(Collection)", list);
330
	}
331
332
	public void testRemoveAll_ListDiffEntry() throws Exception {
333
		final Object element = delegate.createElement(list);
334
		list.add(element);
335
336
		assertRemoveDiffEntry(new Runnable() {
337
			public void run() {
338
				list.removeAll(Arrays.asList(new Object[] { element }));
339
			}
340
		}, "List.removeAll(Collection)", list, element, 0);
341
	}
342
343
	public void testRetainAll_ListChangeEvent() throws Exception {
344
		final Object element1 = delegate.createElement(list);
345
		list.add(element1);
346
		list.add(delegate.createElement(list));
347
348
		assertListChangeEventFired(new Runnable() {
349
			public void run() {
350
				list.retainAll(Arrays.asList(new Object[] { element1 }));
351
			}
352
		}, "List.retainAll(Collection", list);
353
	}
354
355
	public void testRetainAll_ListDiffEntry() throws Exception {
356
		final Object element1 = delegate.createElement(list);
357
		list.add(element1);
358
		Object element2 = delegate.createElement(list);
359
		list.add(delegate.createElement(list));
360
361
		assertRemoveDiffEntry(new Runnable() {
362
			public void run() {
363
				list.retainAll(Arrays.asList(new Object[] { element1 }));
364
			}
365
		}, "List.retainAll(Collection)", list, element2, 1);
366
	}
367
368
	public void testClear_ListChangeEvent() throws Exception {
369
		list.add(delegate.createElement(list));
370
371
		assertListChangeEventFired(new Runnable() {
372
			public void run() {
373
				list.clear();
374
			}
375
		}, "List.clear()", list);
376
	}
377
378
	public void testClear_ListDiffEntry() throws Exception {
379
		Object element = delegate.createElement(list);
380
		list.add(element);
381
382
		assertRemoveDiffEntry(new Runnable() {
383
			public void run() {
384
				list.clear();
385
			}
386
		}, "List.clear()", list, element, 0);
387
	}
388
389
	/**
390
	 * Asserts standard behaviors of firing list change events.
391
	 * <ul>
392
	 * <li>Event fires once.</li>
393
	 * <li>Source of the event is the provided <code>list</code>.
394
	 * <li>The list change event is fired after the change event.</li>
395
	 * </ul>
396
	 * 
397
	 * @param runnable
398
	 * @param methodName
399
	 * @param list
400
	 */
401
	private void assertListChangeEventFired(Runnable runnable,
402
			String methodName, IObservableList list) {
403
		List queue = new ArrayList();
404
		ListChangeEventTracker listListener = new ListChangeEventTracker(queue);
405
		ChangeEventTracker changeListener = new ChangeEventTracker(queue);
406
407
		list.addListChangeListener(listListener);
408
		list.addChangeListener(changeListener);
409
410
		runnable.run();
411
412
		assertEquals(formatFail(methodName + " should fire one ListChangeEvent."), 1,
413
				listListener.count);
414
		assertEquals(formatFail(methodName
415
				+ "'s change event observable should be the created List."),
416
				list, listListener.event.getObservable());
417
418
		assertEquals(formatFail("Two notifications should have been received."), 2, queue
419
				.size());
420
		assertEquals("ChangeEvent of " + methodName
421
				+ " should have fired before the ListChangeEvent.",
422
				changeListener, queue.get(0));
423
		assertEquals("ListChangeEvent of " + methodName
424
				+ " should have fired after the ChangeEvent.", listListener,
425
				queue.get(1));
426
	}
427
428
	/**
429
	 * Asserts the list diff entry for a remove operation.
430
	 * 
431
	 * @param runnable
432
	 * @param methodName
433
	 * @param list
434
	 * @param element
435
	 * @param index
436
	 */
437
	private void assertRemoveDiffEntry(Runnable runnable, String methodName,
438
			IObservableList list, Object element, int index) {
439
		ListChangeEventTracker listener = new ListChangeEventTracker();
440
		list.addListChangeListener(listener);
441
442
		runnable.run();
443
444
		ListDiffEntry[] entries = listener.event.diff.getDifferences();
445
		assertEquals(methodName + " should result in one diff entry.", 1,
446
				entries.length);
447
448
		ListDiffEntry entry = entries[0];
449
		assertFalse(methodName
450
				+ " should result in a diff entry that is an removal.", entry
451
				.isAddition());
452
		assertEquals(methodName
453
				+ " remove diff entry should have removed the element.",
454
				element, entry.getElement());
455
		assertEquals(
456
				methodName
457
						+ " remove diff entry should have removed the element from the provided index.",
458
				index, entry.getPosition());
459
	}
460
461
	/**
462
	 * Asserts the list diff entry for an add operation.
463
	 * 
464
	 * @param runnable
465
	 * @param methodName
466
	 * @param list
467
	 * @param element
468
	 * @param index
469
	 */
470
	private void assertAddDiffEntry(Runnable runnable, String methodName,
471
			IObservableList list, Object element, int index) {
472
		ListChangeEventTracker listener = new ListChangeEventTracker();
473
		list.addListChangeListener(listener);
474
475
		runnable.run();
476
477
		ListDiffEntry[] entries = listener.event.diff.getDifferences();
478
		assertEquals(methodName + " should result in one diff entry.", 1,
479
				entries.length);
480
481
		ListDiffEntry entry = entries[0];
482
		assertTrue(methodName
483
				+ " should result in a diff entry that is an addition.", entry
484
				.isAddition());
485
		assertEquals(methodName
486
				+ " add diff entry should have added the element.", element,
487
				entry.getElement());
488
		assertEquals(
489
				methodName
490
						+ "add diff entry should have added the element at the provided index.",
491
				index, entry.getPosition());
492
	}
493
}
(-)src/org/eclipse/jface/databinding/conformance/swt/SWTMutableObservableValueContractTest.java (+68 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.swt;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest;
16
import org.eclipse.jface.databinding.conformance.delegate.IObservableValueContractDelegate;
17
import org.eclipse.jface.databinding.conformance.util.DelegatingRealm;
18
import org.eclipse.jface.databinding.swt.SWTObservables;
19
import org.eclipse.swt.widgets.Display;
20
21
/**
22
 * Mutability tests for IObservableValue for a SWT widget.
23
 * 
24
 * <p>
25
 * This class is experimental and can change at any time. It is recommended to
26
 * not subclass or assume the test names will not change. The only API that is
27
 * guaranteed to not change are the constructors. The tests will remain public
28
 * and not final in order to allow for consumers to turn off a test if needed by
29
 * subclassing.
30
 * </p>
31
 * 
32
 * @since 3.2
33
 */
34
public class SWTMutableObservableValueContractTest extends
35
		MutableObservableValueContractTest {
36
	private IObservableValueContractDelegate delegate;
37
38
	public SWTMutableObservableValueContractTest(
39
			IObservableValueContractDelegate delegate) {
40
		this(null, delegate);
41
	}
42
43
	/**
44
	 * @param testName
45
	 * @param delegate
46
	 */
47
	public SWTMutableObservableValueContractTest(String testName,
48
			IObservableValueContractDelegate delegate) {
49
		super(testName, delegate);
50
		this.delegate = delegate;
51
	}
52
53
	/**
54
	 * Creates a new observable passing the realm for the current display.
55
	 * @return observable
56
	 */
57
	protected IObservable doCreateObservable() {
58
		Display display = Display.getCurrent();
59
		if (display == null) {
60
			display = new Display();
61
		}
62
		DelegatingRealm delegateRealm = new DelegatingRealm(SWTObservables
63
				.getRealm(display));
64
		delegateRealm.setCurrent(true);
65
66
		return delegate.createObservable(delegateRealm);
67
	}
68
}
(-)META-INF/MANIFEST.MF (+14 lines)
Added Link Here
1
Manifest-Version: 1.0
2
Bundle-ManifestVersion: 2
3
Bundle-Name: %pluginName
4
Bundle-SymbolicName: org.eclipse.jface.tests.databinding.conformance
5
Bundle-Version: 1.0.0
6
Require-Bundle: org.junit,
7
 org.eclipse.core.databinding,
8
 org.eclipse.jface.databinding,
9
 org.eclipse.swt,
10
 org.eclipse.core.runtime
11
Bundle-Vendor: %providerName
12
Bundle-RequiredExecutionEnvironment: J2SE-1.4
13
Export-Package: org.eclipse.jface.databinding.conformance,
14
 org.eclipse.jface.databinding.conformance.util
(-)src/org/eclipse/jface/databinding/conformance/util/SetChangeEventTracker.java (+47 lines)
Added Link Here
1
package org.eclipse.jface.databinding.conformance.util;
2
3
import java.util.List;
4
5
import org.eclipse.core.databinding.observable.set.IObservableSet;
6
import org.eclipse.core.databinding.observable.set.ISetChangeListener;
7
import org.eclipse.core.databinding.observable.set.SetChangeEvent;
8
9
public class SetChangeEventTracker implements ISetChangeListener {
10
	public int count;
11
12
	public SetChangeEvent event;
13
14
	/**
15
	 * Queue that the listener will add itself too when it is notified of an
16
	 * event. Used to determine order of notifications of listeners.
17
	 */
18
	public final List listenerQueue;
19
20
	public SetChangeEventTracker() {
21
		this(null);
22
	}
23
24
	public SetChangeEventTracker(List notificationQueue) {
25
		this.listenerQueue = notificationQueue;
26
	}
27
28
	public void handleSetChange(SetChangeEvent event) {
29
		count++;
30
		this.event = event;
31
		if (listenerQueue != null) {
32
			listenerQueue.add(this);
33
		}
34
	}
35
	
36
	/**
37
	 * Convenience method to register a new listener.
38
	 * 
39
	 * @param observable
40
	 * @return tracker
41
	 */
42
	public static SetChangeEventTracker observe(IObservableSet observable) {
43
		SetChangeEventTracker tracker = new SetChangeEventTracker();
44
		observable.addSetChangeListener(tracker);
45
		return tracker;
46
	}
47
}
(-)src/org/eclipse/jface/databinding/conformance/delegate/IObservableContractDelegate.java (+64 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.delegate;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.core.databinding.observable.Realm;
16
17
/**
18
 * Delegate interface for observables.
19
 * 
20
 * <p>
21
 * This interface is not intended to be implemented by clients. Clients should
22
 * instead subclass one of the classes that implement this interface. Note that
23
 * direct implementers of this interface outside of the framework will be broken
24
 * in future releases when methods are added to this interface.
25
 * </p>
26
 * 
27
 * @since 1.1
28
 */
29
public interface IObservableContractDelegate {
30
	/**
31
	 * Notifies the delegate of the start of a test.
32
	 */
33
	public void setUp();
34
35
	/**
36
	 * Notifies the delegate of the end of a test.
37
	 */
38
	public void tearDown();
39
40
	/**
41
	 * Invokes an operation to set the stale state of the provided
42
	 * <code>observable</code>.
43
	 * 
44
	 * @param observable
45
	 * @param stale
46
	 */
47
	public void setStale(IObservable observable, boolean stale);
48
49
	/**
50
	 * Creates a new observable.
51
	 * 
52
	 * @param realm realm of the observable
53
	 * @return observable
54
	 */
55
	public IObservable createObservable(Realm realm);
56
57
	/**
58
	 * Invokes a change operation on the observable resulting in a change event
59
	 * being fired from the observable.
60
	 * 
61
	 * @param observable
62
	 */
63
	public void change(IObservable observable);
64
}
(-)src/org/eclipse/jface/databinding/conformance/MutableObservableCollectionContractTest.java (+360 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import java.util.Arrays;
15
import java.util.Collections;
16
17
import org.eclipse.core.databinding.observable.ChangeEvent;
18
import org.eclipse.core.databinding.observable.IChangeListener;
19
import org.eclipse.core.databinding.observable.IObservableCollection;
20
import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate;
21
import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker;
22
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
23
import org.eclipse.jface.databinding.conformance.util.RealmTester;
24
25
/**
26
 * Mutability tests for IObservableCollection.
27
 * <p>
28
 * This class is experimental and can change at any time. It is recommended to
29
 * not subclass or assume the test names will not change. The only API that is
30
 * guaranteed to not change are the constructors. The tests will remain public
31
 * and not final in order to allow for consumers to turn off a test if needed by
32
 * subclassing.
33
 * </p>
34
 * 
35
 * @since 3.2
36
 */
37
public class MutableObservableCollectionContractTest extends ObservableDelegateTest {
38
	private IObservableCollectionContractDelegate delegate;
39
40
	private IObservableCollection collection;
41
42
	public MutableObservableCollectionContractTest(
43
			IObservableCollectionContractDelegate delegate) {
44
		super(delegate);
45
		this.delegate = delegate;
46
	}
47
48
	public MutableObservableCollectionContractTest(String name,
49
			IObservableCollectionContractDelegate delegate) {
50
		super(name, delegate);
51
		this.delegate = delegate;
52
	}
53
54
	protected void setUp() throws Exception {
55
		super.setUp();
56
57
		collection = (IObservableCollection) super.getObservable();
58
	}
59
60
	public void testAdd_ChangeEvent() throws Exception {
61
		assertChangeEventFired(new Runnable() {
62
			public void run() {
63
				collection.add(delegate.createElement(collection));
64
			}
65
		}, "Collection.add(Object)", collection);
66
	}
67
	
68
	public void testAdd_RealmCheck() throws Exception {
69
		RealmTester.exerciseCurrent(new Runnable() {
70
			public void run() {
71
				collection.add(delegate.createElement(collection));
72
			}
73
		}, (CurrentRealm) collection.getRealm());
74
	}
75
76
	public void testAdd_ChangeEventFiredAfterElementIsAdded() throws Exception {
77
		final Object element = delegate.createElement(collection);
78
79
		assertContainsDuringChangeEvent(new Runnable() {
80
			public void run() {
81
				collection.add(element);
82
			}
83
		}, "Collection.add(Object)", collection, element);
84
	}
85
86
	public void testAddAll_ChangeEvent() throws Exception {
87
		assertChangeEventFired(new Runnable() {
88
			public void run() {
89
				collection.addAll(Arrays.asList(new Object[] { delegate
90
						.createElement(collection) }));
91
			}
92
		}, "Collection.addAll(Collection)", collection);
93
	}
94
	
95
	public void testAddAll_RealmCheck() throws Exception {
96
		RealmTester.exerciseCurrent(new Runnable() {
97
			public void run() {
98
				collection.addAll(Arrays.asList(new Object[] { delegate
99
						.createElement(collection) }));
100
			}
101
		}, (CurrentRealm) collection.getRealm());
102
	}
103
104
	public void testAddAll_ChangeEventFiredAfterElementsAreAdded()
105
			throws Exception {
106
		final Object element = delegate.createElement(collection);
107
108
		assertContainsDuringChangeEvent(new Runnable() {
109
			public void run() {
110
				collection.addAll(Arrays.asList(new Object[] { element }));
111
			}
112
		}, "Collection.addAll(Collection)", collection, element);
113
	}
114
115
	public void testRemove_ChangeEvent() throws Exception {
116
		final Object element = delegate.createElement(collection);
117
		collection.add(element);
118
119
		assertChangeEventFired(new Runnable() {
120
			public void run() {
121
				collection.remove(element);
122
			}
123
		}, "Collection.remove(Object)", collection);
124
	}
125
	
126
	public void testRemove_RealmCheck() throws Exception {
127
		RealmTester.exerciseCurrent(new Runnable() {
128
			public void run() {
129
				collection.remove(delegate.createElement(collection));
130
			}
131
		}, (CurrentRealm) collection.getRealm());
132
	}
133
134
	public void testRemove_ChangeEventFiredAfterElementIsRemoved()
135
			throws Exception {
136
		final Object element = delegate.createElement(collection);
137
		collection.add(element);
138
139
		assertDoesNotContainDuringChangeEvent(new Runnable() {
140
			public void run() {
141
				collection.remove(element);
142
			}
143
		}, "Collection.remove(Object)", collection, element);
144
	}
145
146
	public void testRemoveAll_ChangeEvent() throws Exception {
147
		final Object element = delegate.createElement(collection);
148
		collection.add(element);
149
150
		assertChangeEventFired(new Runnable() {
151
			public void run() {
152
				collection.removeAll(Arrays.asList(new Object[] { element }));
153
			}
154
		}, "Collection.removeAll(Collection)", collection);
155
	}
156
	
157
	public void testRemoveAll_RealmCheck() throws Exception {
158
		RealmTester.exerciseCurrent(new Runnable() {
159
			public void run() {
160
				collection.removeAll(Arrays.asList(new Object[] { delegate.createElement(collection) }));
161
			}
162
		}, (CurrentRealm) collection.getRealm());
163
	}
164
165
	public void testRemoveAll_ChangeEventFiredAfterElementsAreRemoved()
166
			throws Exception {
167
		final Object element = delegate.createElement(collection);
168
		collection.add(element);
169
170
		assertDoesNotContainDuringChangeEvent(new Runnable() {
171
			public void run() {
172
				collection.removeAll(Arrays.asList(new Object[] { element }));
173
			}
174
		}, "Collection.removeAll(Collection)", collection, element);
175
	}
176
177
	public void testRetainAll_ChangeEvent() throws Exception {
178
		final Object element1 = delegate.createElement(collection);
179
		collection.add(element1);
180
		Object element2 = delegate.createElement(collection);
181
		collection.add(element2);
182
183
		assertChangeEventFired(new Runnable() {
184
			public void run() {
185
				collection.retainAll(Arrays.asList(new Object[] { element1 }));
186
			}
187
188
		}, "Collection.retainAll(Collection)", collection);
189
	}
190
	
191
	public void testRetainAll_RealmCheck() throws Exception {
192
		RealmTester.exerciseCurrent(new Runnable() {
193
			public void run() {
194
				collection.retainAll(Collections.EMPTY_LIST);
195
			}
196
		}, (CurrentRealm) collection.getRealm());
197
	}
198
199
	public void testRetainAll_ChangeEventFiredAfterElementsAreRetained()
200
			throws Exception {
201
		Object element1 = delegate.createElement(collection);
202
		collection.add(element1);
203
		Object element2 = delegate.createElement(collection);
204
		collection.add(element2);
205
206
		// precondition
207
		assertTrue(collection.contains(element1));
208
		assertTrue(collection.contains(element2));
209
210
		ContainsListener listener1 = new ContainsListener(collection, element1)
211
				.init();
212
		ContainsListener listener2 = new ContainsListener(collection, element2)
213
				.init();
214
215
		// set contains the the opposite of the expected outcome to ensure they
216
		// get set
217
		listener1.contains = false;
218
		listener2.contains = true;
219
220
		collection.retainAll(Arrays.asList(new Object[] { element1 }));
221
		assertTrue(
222
				formatFail("When Collection.retainAll(...) fires the change event the element should have been retained in the Collection."),
223
				listener1.contains);
224
		assertFalse(
225
				formatFail("When Collection.retainAll(...) fires the change event the element should have been removed from the Collection."),
226
				listener2.contains);
227
	}
228
	
229
	public void testClear_ChangeEvent() throws Exception {
230
		collection.add(delegate.createElement(collection));
231
232
		assertChangeEventFired(new Runnable() {
233
			public void run() {
234
				collection.clear();
235
			}
236
		}, "List.clear()", collection);
237
	}
238
239
	public void testClear_RealmCheck() throws Exception {
240
		RealmTester.exerciseCurrent(new Runnable() {
241
			public void run() {
242
				collection.clear();
243
			}
244
		}, (CurrentRealm) collection.getRealm());
245
	}
246
247
	public void testClear_ChangeEventFiredAfterElementIsRemoved()
248
			throws Exception {
249
		Object element = delegate.createElement(collection);
250
		collection.add(element);
251
252
		assertDoesNotContainDuringChangeEvent(new Runnable() {
253
			public void run() {
254
				collection.clear();
255
			}
256
		}, "List.clear()", collection, element);
257
	}
258
259
	/**
260
	 * Asserts that a ChangeEvent is fired once when the provided
261
	 * <code>runnable</code> is invoked and the source is the provided
262
	 * <code>collection</code>.
263
	 * 
264
	 * @param runnable
265
	 * @param methodName
266
	 * @param collection
267
	 */
268
	/* package */void assertChangeEventFired(Runnable runnable,
269
			String methodName, IObservableCollection collection) {
270
		
271
		ChangeEventTracker listener = ChangeEventTracker.observe(collection);
272
		runnable.run();
273
274
		assertEquals(formatFail(methodName + " should fire one ChangeEvent."), 1,
275
				listener.count);
276
		assertEquals(
277
				formatFail(methodName
278
						+ "'s change event observable should be the created Collection."),
279
				collection, listener.event.getObservable());
280
	}
281
282
	/**
283
	 * Asserts that when the change event is fired for the action contained in
284
	 * the <code>runnable</code> the change will have been applied to the
285
	 * <code>collection</code>.
286
	 * 
287
	 * @param runnable
288
	 * @param methodName
289
	 * @param collection
290
	 * @param elementNotContained
291
	 */
292
	/* package */void assertDoesNotContainDuringChangeEvent(Runnable runnable,
293
			String methodName, IObservableCollection collection,
294
			Object elementNotContained) {
295
296
		// precondition
297
		assertTrue(collection.contains(elementNotContained));
298
299
		ContainsListener listener = new ContainsListener(collection,
300
				elementNotContained).init();
301
		listener.contains = true;
302
		collection.remove(elementNotContained);
303
		assertFalse(
304
				formatFail(new StringBuffer("When ")
305
						.append(methodName)
306
						.append(
307
								" fires a change event the element should have been removed from the Collection.")
308
						.toString()), listener.contains);
309
	}
310
311
	/**
312
	 * Asserts that when the change event is fired for the action contained in
313
	 * the <code>runnable</code> the change will have been applied to the
314
	 * <code>collection</code>.
315
	 * 
316
	 * @param runnable
317
	 * @param methodName
318
	 * @param collection
319
	 * @param elementContained
320
	 */
321
	/* package */void assertContainsDuringChangeEvent(Runnable runnable,
322
			String methodName, IObservableCollection collection,
323
			Object elementContained) {
324
		ContainsListener listener = new ContainsListener(collection,
325
				elementContained).init();
326
327
		// precondition
328
		assertFalse(collection.contains(elementContained));
329
		runnable.run();
330
331
		assertTrue(
332
				formatFail(new StringBuffer("When ")
333
						.append(methodName)
334
						.append(
335
								" fires a change event the element should have been added to the Collection.")
336
						.toString()), listener.contains);
337
	}
338
339
	/* package */static class ContainsListener implements IChangeListener {
340
		boolean contains;
341
342
		final private Object element;
343
344
		final private IObservableCollection collection;
345
346
		ContainsListener(IObservableCollection collection, Object element) {
347
			this.element = element;
348
			this.collection = collection;
349
		}
350
351
		ContainsListener init() {
352
			collection.addChangeListener(this);
353
			return this;
354
		}
355
356
		public void handleChange(ChangeEvent event) {
357
			contains = collection.contains(element);
358
		}
359
	}
360
}
(-)src/org/eclipse/jface/databinding/conformance/ObservableListContractTest.java (+109 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import org.eclipse.core.databinding.observable.list.IObservableList;
15
import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate;
16
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
17
18
/**
19
 * Tests for IObservableList that don't require mutating the collection.
20
 * <p>
21
 * This class is experimental and can change at any time. It is recommended to
22
 * not subclass or assume the test names will not change. The only API that is
23
 * guaranteed to not change are the constructors. The tests will remain public
24
 * and not final in order to allow for consumers to turn off a test if needed by
25
 * subclassing.
26
 * </p>
27
 * 
28
 * @since 3.2
29
 */
30
public class ObservableListContractTest extends
31
		ObservableCollectionContractTest {
32
	private IObservableList list;
33
34
	private IObservableCollectionContractDelegate delegate;
35
36
	/**
37
	 * @param delegate
38
	 */
39
	public ObservableListContractTest(
40
			IObservableCollectionContractDelegate delegate) {
41
		super(delegate);
42
		this.delegate = delegate;
43
	}
44
45
	public ObservableListContractTest(String testName,
46
			IObservableCollectionContractDelegate delegate) {
47
		super(testName, delegate);
48
		this.delegate = delegate;
49
	}
50
51
	protected void setUp() throws Exception {
52
		super.setUp();
53
54
		list = (IObservableList) getObservable();
55
	}
56
57
	public void testListIterator_GetterCalled() throws Exception {
58
		assertGetterCalled(new Runnable() {
59
			public void run() {
60
				list.listIterator();
61
			}
62
		}, "List.listIterator()", list);
63
	}
64
65
	public void testGet_GetterCalled() throws Exception {
66
		list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1);
67
		assertGetterCalled(new Runnable() {
68
			public void run() {
69
				list.get(0);
70
			}
71
		}, "List.get(int)", list);
72
	}
73
74
	public void testIndexOf_GetterCalled() throws Exception {
75
		assertGetterCalled(new Runnable() {
76
			public void run() {
77
				list.indexOf(delegate.createElement(list));
78
			}
79
		}, "List.indexOf(int)", list);
80
	}
81
82
	public void testLastIndexOf_GetterCalled() throws Exception {
83
		assertGetterCalled(new Runnable() {
84
			public void run() {
85
				list.lastIndexOf(delegate.createElement(list));
86
			}
87
		}, "List.lastIndexOf(Object)", list);
88
	}
89
90
	public void testListIteratorAtIndex_GetterCalled() throws Exception {
91
		// Create a new list instead of adding an item because the list might
92
		// not be mutable
93
		list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1);
94
		assertGetterCalled(new Runnable() {
95
			public void run() {
96
				list.listIterator(0);
97
			}
98
		}, "List.listIterator(int)", list);
99
	}
100
101
	public void testSubList_GetterCalled() throws Exception {
102
		list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1);
103
		assertGetterCalled(new Runnable() {
104
			public void run() {
105
				list.subList(0, 1);
106
			}
107
		}, "List.subList(int, int)", list);
108
	}
109
}
(-)src/org/eclipse/jface/databinding/conformance/ObservableStaleContractTest.java (+149 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.core.databinding.observable.IStaleListener;
16
import org.eclipse.core.databinding.observable.StaleEvent;
17
import org.eclipse.jface.databinding.conformance.delegate.IObservableContractDelegate;
18
19
/**
20
 * @since 3.3
21
 */
22
public class ObservableStaleContractTest extends ObservableDelegateTest {
23
	private IObservableContractDelegate delegate;
24
	private IObservable observable;
25
	
26
	public ObservableStaleContractTest(IObservableContractDelegate delegate) {
27
		this(null, delegate);
28
	}
29
	
30
	public ObservableStaleContractTest(String testName, IObservableContractDelegate delegate) {
31
		super(testName, delegate);
32
		this.delegate = delegate;
33
	}
34
	
35
	protected void setUp() throws Exception {
36
		super.setUp();
37
		
38
		observable = getObservable();
39
	}
40
	
41
	public void testIsStale_TrueWhenStale() throws Exception {
42
		delegate.setStale(observable, true);
43
		assertTrue(formatFail("When stale isStale() should return true."), observable.isStale());
44
	}
45
	
46
	public void testIsStale_FalseWhenNotStale() throws Exception {
47
		delegate.setStale(observable, false);
48
		assertFalse(formatFail("When not stale isStale() should return false."), observable.isStale());
49
	}
50
51
	public void testBecomingStaleFiresStaleEvent() throws Exception {
52
		StaleListener listener = new StaleListener();
53
54
		// precondition
55
		ensureStale(observable, false);
56
57
		observable.addStaleListener(listener);
58
		delegate.setStale(observable, true);
59
60
		assertEquals(formatFail("When becoming stale listeners should be notified."), 1, listener.count);
61
	}
62
63
	public void testStaleEventObservable() throws Exception {
64
		StaleListener listener = new StaleListener();
65
66
		// precondition
67
		ensureStale(observable, false);
68
69
		observable.addStaleListener(listener);
70
		delegate.setStale(observable, true);
71
72
		StaleEvent event = listener.event;
73
		assertNotNull(formatFail("stale event was null"), event);
74
		assertEquals(formatFail("When notifying listeners of becoming stale the observable should be the source of the event."), observable,
75
				event.getObservable());
76
	}
77
78
	public void testRemoveStaleListener_RemovesListener() throws Exception {
79
		StaleListener listener = new StaleListener();
80
81
		observable.addStaleListener(listener);
82
		ensureStale(observable, false);
83
		delegate.setStale(observable, true);
84
85
		// precondition check
86
		assertEquals(formatFail("set stale did not notify listeners"), 1, listener.count);
87
88
		observable.removeStaleListener(listener);
89
		ensureStale(observable, false);
90
		delegate.setStale(observable, true);
91
92
		assertEquals(formatFail("Once removed stale listeners should not be notified of becoming stale."), 1,
93
				listener.count);
94
	}
95
96
	public void testStaleListenersAreNotNotifiedWhenObservableIsNoLongerStale()
97
			throws Exception {
98
		ensureStale(observable, true);
99
100
		StaleListener listener = new StaleListener();
101
		observable.addStaleListener(listener);
102
		delegate.setStale(observable, false);
103
104
		assertEquals(formatFail("Stale listeners should not be notified when the stale state changes from true to false."), 0,
105
				listener.count);
106
	}
107
108
	public void testObservableRealmIsCurrentOnStale() throws Exception {
109
		ensureStale(observable, false);
110
111
		StaleListener listener = new StaleListener();
112
		observable.addStaleListener(listener);
113
		delegate.setStale(observable, true);
114
115
		assertTrue(formatFail("When notifying listeners of becoming stale the observable's realm should be the current realm."),
116
				listener.isCurrentRealm);
117
	}
118
	
119
	/**
120
	 * Ensures that stale is set to the provided state. Will throw an
121
	 * AssertionFailedError if setting of the state is unsuccessful.
122
	 * 
123
	 * @param observable
124
	 * @param stale
125
	 */
126
	private void ensureStale(IObservable observable, boolean stale) {
127
		if (observable.isStale() != stale) {
128
			delegate.setStale(observable, stale);
129
		}
130
131
		assertEquals(stale, observable.isStale());
132
	}
133
	
134
	/* package */static class StaleListener implements IStaleListener {
135
		int count;
136
137
		StaleEvent event;
138
139
		boolean isCurrentRealm;
140
141
		public void handleStale(StaleEvent staleEvent) {
142
			count++;
143
			this.event = staleEvent;
144
			this.isCurrentRealm = staleEvent.getObservable().getRealm()
145
					.isCurrent();
146
		}
147
	}
148
149
}
(-)src/org/eclipse/jface/databinding/conformance/util/ValueChangeEventTracker.java (+47 lines)
Added Link Here
1
package org.eclipse.jface.databinding.conformance.util;
2
3
import java.util.List;
4
5
import org.eclipse.core.databinding.observable.value.IObservableValue;
6
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
7
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
8
9
/**
10
 * Listener for tracking the firing of ValueChangeEvents.
11
 */
12
public class ValueChangeEventTracker implements IValueChangeListener {
13
	public int count;
14
15
	public ValueChangeEvent event;
16
17
	public final List queue;
18
19
	public ValueChangeEventTracker() {
20
		this(null);
21
	}
22
23
	public ValueChangeEventTracker(List queue) {
24
		this.queue = queue;
25
	}
26
27
	public void handleValueChange(ValueChangeEvent event) {
28
		count++;
29
		this.event = event;
30
31
		if (queue != null) {
32
			queue.add(this);
33
		}
34
	}
35
36
	/**
37
	 * Convenience method to register a new listener.
38
	 * 
39
	 * @param observable
40
	 * @return tracker
41
	 */
42
	public static ValueChangeEventTracker observe(IObservableValue observable) {
43
		ValueChangeEventTracker tracker = new ValueChangeEventTracker();
44
		observable.addValueChangeListener(tracker);
45
		return tracker;
46
	}
47
}
(-)src/org/eclipse/jface/databinding/conformance/util/CurrentRealm.java (+42 lines)
Added Link Here
1
package org.eclipse.jface.databinding.conformance.util;
2
3
import org.eclipse.core.databinding.observable.Realm;
4
5
/**
6
 * Allows for the toggling of the current status of the realm. The
7
 * asyncExec(...) implementations do nothing.
8
 * 
9
 * @since 3.2
10
 */
11
public class CurrentRealm extends Realm {
12
	private boolean current;
13
14
	public CurrentRealm() {
15
		this(false);
16
	}
17
18
	public CurrentRealm(boolean current) {
19
		this.current = current;
20
	}
21
22
	public boolean isCurrent() {
23
		return current;
24
	}
25
26
	public void setCurrent(boolean current) {
27
		this.current = current;
28
	}
29
30
	protected void syncExec(Runnable runnable) {
31
		super.syncExec(runnable);
32
	}
33
34
	public void asyncExec(Runnable runnable) {
35
		throw new UnsupportedOperationException(
36
				"CurrentRealm does not support asyncExec(Runnable)."); //$NON-NLS-1$
37
	}
38
39
	protected static Realm setDefault(Realm realm) {
40
		return Realm.setDefault(realm);
41
	}
42
}
(-)src/org/eclipse/jface/databinding/conformance/ObservableDelegateTest.java (+107 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import junit.framework.TestCase;
15
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.jface.databinding.conformance.delegate.IObservableContractDelegate;
19
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
20
import org.eclipse.jface.databinding.conformance.util.RealmTester;
21
22
/**
23
 * TestCase that provides the standard behavior expected for delegating test cases.
24
 * 
25
 * @since 3.2
26
 */
27
public class ObservableDelegateTest extends TestCase {
28
	private IObservableContractDelegate delegate;
29
30
	private Realm previousRealm;
31
32
	private IObservable observable;
33
	private String debugInfo;
34
35
	public ObservableDelegateTest(IObservableContractDelegate delegate) {
36
		this(null, delegate);
37
	}
38
	
39
	public ObservableDelegateTest(String testName, IObservableContractDelegate delegate) {
40
		super(testName);
41
		this.delegate = delegate;
42
	}
43
44
	protected void setUp() throws Exception {
45
		super.setUp();
46
		previousRealm = Realm.getDefault();
47
48
		delegate.setUp();
49
		observable = doCreateObservable();
50
	}
51
52
	protected void tearDown() throws Exception {
53
		super.tearDown();
54
55
		delegate.tearDown();
56
		observable.dispose();
57
		observable = null;
58
		
59
		RealmTester.setDefault(previousRealm);
60
61
		observable = null;
62
		previousRealm = null;
63
	}
64
	
65
	/**
66
	 * Creates a new observable with a default realm. Invoked from
67
	 * {@link #setUp()}. Override to customize the creation of observables
68
	 * (e.g. specifying a different Realm).
69
	 * 
70
	 * @return observable
71
	 */
72
	protected IObservable doCreateObservable() {
73
		return delegate.createObservable(new CurrentRealm(true));
74
	}
75
76
	/**
77
	 * Returns the created observable. The observable is created in
78
	 * {@link #setUp()}. If invoked before {@link #setUp()} will be
79
	 * <code>null</code>.
80
	 * 
81
	 * @return observable
82
	 */
83
	protected IObservable getObservable() {
84
		return observable;
85
	}	
86
	
87
	/**
88
	 * Returns the delegate in use.
89
	 * 
90
	 * @return delegate
91
	 */
92
	protected IObservableContractDelegate getObservableContractDelegate() {
93
		return delegate;
94
	}
95
	
96
	protected String formatFail(String message) {
97
		return message + getDebugString();
98
	}
99
	
100
	private String getDebugString() {
101
		if (debugInfo == null) {
102
			debugInfo = "(Test: " + this.getClass().getName() + ", Delegate: " + delegate.getClass().getName() + ")";
103
		}
104
		
105
		return debugInfo;
106
	}
107
}
(-)src/org/eclipse/jface/databinding/conformance/ObservableCollectionContractTest.java (+208 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import java.util.Arrays;
15
16
import org.eclipse.core.databinding.observable.IObservableCollection;
17
import org.eclipse.jface.databinding.conformance.delegate.IObservableCollectionContractDelegate;
18
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
19
import org.eclipse.jface.databinding.conformance.util.RealmTester;
20
21
/**
22
 * Tests for IObservableCollection that don't mutate the collection.
23
 * <p>
24
 * This class is experimental and can change at any time. It is recommended to
25
 * not subclass or assume the test names will not change. The only API that is
26
 * guaranteed to not change are the constructors. The tests will remain public
27
 * and not final in order to allow for consumers to turn off a test if needed by
28
 * subclassing.
29
 * </p>
30
 * 
31
 * @since 3.2
32
 */
33
public class ObservableCollectionContractTest extends ObservableContractTest {
34
	private IObservableCollectionContractDelegate delegate;
35
36
	private IObservableCollection collection;
37
38
	public ObservableCollectionContractTest(
39
			IObservableCollectionContractDelegate delegate) {
40
		super(delegate);
41
		this.delegate = delegate;
42
	}
43
44
	public ObservableCollectionContractTest(String testName,
45
			IObservableCollectionContractDelegate delegate) {
46
		super(testName, delegate);
47
		this.delegate = delegate;
48
	}
49
50
	protected void setUp() throws Exception {
51
		super.setUp();
52
		
53
		collection = (IObservableCollection) getObservable();
54
	}
55
56
	public void testIterator_GetterCalled() throws Exception {
57
		assertGetterCalled(new Runnable() {
58
			public void run() {
59
				collection.iterator();
60
			}
61
		}, "Collection.iterator()", collection);
62
	}
63
	
64
	public void testIterator_RealmCheck() throws Exception {
65
		RealmTester.exerciseCurrent(new Runnable() {
66
			public void run() {
67
				collection.iterator();
68
			}
69
		}, (CurrentRealm) collection.getRealm());
70
	}
71
72
	public void testSize_GetterCalled() throws Exception {
73
		assertGetterCalled(new Runnable() {
74
			public void run() {
75
				collection.size();
76
			}
77
		}, "Collection.size()", collection);
78
	}
79
	
80
	public void testSize_RealmCheck() throws Exception {
81
		RealmTester.exerciseCurrent(new Runnable() {
82
			public void run() {
83
				collection.size();
84
			}
85
		}, (CurrentRealm) collection.getRealm());
86
	}
87
88
	public void testIsEmpty_GetterCalled() throws Exception {
89
		assertGetterCalled(new Runnable() {
90
			public void run() {
91
				collection.isEmpty();
92
			}
93
		}, "Collection.isEmpty()", collection);
94
	}
95
	
96
	public void testIsEmpty_RealmCheck() throws Exception {
97
		RealmTester.exerciseCurrent(new Runnable() {
98
			public void run() {
99
				collection.isEmpty();
100
			}
101
		}, (CurrentRealm) collection.getRealm());
102
	}
103
104
	public void testContains_GetterCalled() throws Exception {
105
		assertGetterCalled(new Runnable() {
106
			public void run() {
107
				collection.contains(delegate.createElement(collection));
108
			}
109
		}, "Collection.contains(...)", collection);
110
	}
111
	
112
	public void testContains_RealmCheck() throws Exception {
113
		RealmTester.exerciseCurrent(new Runnable() {
114
			public void run() {
115
				collection.contains(delegate.createElement(collection));
116
			}
117
		}, (CurrentRealm) collection.getRealm());
118
	}
119
120
	public void testContainsAll_GetterCalled() throws Exception {
121
		assertGetterCalled(new Runnable() {
122
			public void run() {
123
				collection.containsAll(Arrays.asList(new Object[] { delegate
124
						.createElement(collection) }));
125
			}
126
		}, "Collection.containsAll(Collection)", collection);
127
	}
128
129
	public void testContainsAll_RealmCheck() throws Exception {
130
		RealmTester.exerciseCurrent(new Runnable() {
131
			public void run() {
132
				collection.containsAll(Arrays.asList(new Object[] { delegate
133
						.createElement(collection) }));
134
			}
135
		}, (CurrentRealm) collection.getRealm());
136
	}
137
	
138
	public void testToArray_GetterCalled() throws Exception {
139
		assertGetterCalled(new Runnable() {
140
			public void run() {
141
				collection.toArray();
142
			}
143
		}, "Collection.toArray()", collection);
144
	}
145
	
146
	public void testToArray_RealmCheck() throws Exception {
147
		RealmTester.exerciseCurrent(new Runnable() {
148
			public void run() {
149
				collection.toArray();
150
			}
151
		}, (CurrentRealm) collection.getRealm());
152
	}
153
154
	public void testToArrayWithObjectArray_GetterCalled() throws Exception {
155
		assertGetterCalled(new Runnable() {
156
			public void run() {
157
				collection.toArray(new Object[collection.size()]);
158
			}
159
		}, "Collection.toArray(Object[])", collection);
160
	}
161
	
162
	public void testToArrayWithObjectArray_RealmCheck() throws Exception {
163
		RealmTester.exerciseCurrent(new Runnable() {
164
			public void run() {
165
				collection.toArray(new Object[collection.size()]);
166
			}
167
		}, (CurrentRealm) collection.getRealm());
168
	}
169
170
	public void testEquals_GetterCalled() throws Exception {
171
		assertGetterCalled(new Runnable() {
172
			public void run() {
173
				collection.equals(collection);
174
			}
175
		}, "Collection.equals(Object)", collection);
176
	}
177
	
178
	public void testEquals_RealmCheck() throws Exception {
179
		RealmTester.exerciseCurrent(new Runnable() {
180
			public void run() {
181
				collection.equals(collection);
182
			}
183
		}, (CurrentRealm) collection.getRealm());
184
	}
185
186
	public void testHashCode_GetterCalled() throws Exception {
187
		assertGetterCalled(new Runnable() {
188
			public void run() {
189
				collection.hashCode();
190
			}
191
		}, "Collection.hashCode()", collection);
192
	}
193
	
194
	public void testHashCode_RealmCheck() throws Exception {
195
		RealmTester.exerciseCurrent(new Runnable() {
196
			public void run() {
197
				collection.hashCode();
198
			}
199
		}, (CurrentRealm) collection.getRealm());
200
	}
201
202
	public void testGetElementType_ReturnsType() throws Exception {
203
		assertEquals(
204
				"Element type of the collection should be returned from IObservableCollection.getElementType()",
205
				delegate.getElementType(collection), collection
206
						.getElementType());
207
	}
208
}
(-)src/org/eclipse/jface/databinding/conformance/swt/SWTObservableValueContractTest.java (+65 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.swt;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.jface.databinding.conformance.ObservableValueContractTest;
16
import org.eclipse.jface.databinding.conformance.delegate.IObservableValueContractDelegate;
17
import org.eclipse.jface.databinding.conformance.util.DelegatingRealm;
18
import org.eclipse.jface.databinding.swt.SWTObservables;
19
import org.eclipse.swt.widgets.Display;
20
21
/**
22
 * Tests for IObservableValue that don't mutate the value.
23
 * <p>
24
 * This class is experimental and can change at any time. It is recommended to
25
 * not subclass or assume the test names will not change. The only API that is
26
 * guaranteed to not change are the constructors. The tests will remain public
27
 * and not final in order to allow for consumers to turn off a test if needed by
28
 * subclassing.
29
 * </p>
30
 * 
31
 * @since 3.2
32
 */
33
public class SWTObservableValueContractTest extends ObservableValueContractTest {
34
	private IObservableValueContractDelegate delegate;
35
36
	/**
37
	 * @param delegate
38
	 */
39
	public SWTObservableValueContractTest(
40
			IObservableValueContractDelegate delegate) {
41
		this(null, delegate);
42
	}
43
44
	public SWTObservableValueContractTest(String testName,
45
			IObservableValueContractDelegate delegate) {
46
		super(testName, delegate);
47
		this.delegate = delegate;
48
	}
49
50
	/**
51
	 * Creates a new observable passing the realm for the current display.
52
	 * @return observable
53
	 */
54
	protected IObservable doCreateObservable() {
55
		Display display = Display.getCurrent();
56
		if (display == null) {
57
			display = new Display();
58
		}
59
		DelegatingRealm delegateRealm = new DelegatingRealm(SWTObservables
60
				.getRealm(display));
61
		delegateRealm.setCurrent(true);
62
63
		return delegate.createObservable(delegateRealm);
64
	}
65
}
(-)src/org/eclipse/jface/databinding/conformance/ObservableValueContractTest.java (+170 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.core.databinding.observable.ChangeEvent;
18
import org.eclipse.core.databinding.observable.IChangeListener;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
21
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
22
import org.eclipse.jface.databinding.conformance.delegate.IObservableValueContractDelegate;
23
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
24
import org.eclipse.jface.databinding.conformance.util.RealmTester;
25
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
26
27
/**
28
 * @since 3.2
29
 */
30
public class ObservableValueContractTest extends ObservableContractTest {
31
	private IObservableValueContractDelegate delegate;
32
	private IObservableValue observable;
33
34
	public ObservableValueContractTest(IObservableValueContractDelegate delegate) {
35
		super(delegate);
36
		this.delegate = delegate;			
37
	}
38
39
	/**
40
	 * @param testName
41
	 * @param delegate
42
	 */
43
	public ObservableValueContractTest(String testName,
44
			IObservableValueContractDelegate delegate) {
45
		super(testName, delegate);
46
		this.delegate = delegate;
47
	}
48
49
	/*
50
	 * (non-Javadoc)
51
	 * 
52
	 * @see org.eclipse.jface.databinding.conformance.ObservableContractTest#setUp()
53
	 */
54
	protected void setUp() throws Exception {
55
		super.setUp();
56
		observable = (IObservableValue) getObservable();
57
	}
58
59
	public void testChange_ValueChangeEvent() throws Exception {
60
		ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable);
61
62
		delegate.change(observable);
63
		assertEquals(formatFail("On change value change listeners should be notified."), 1,
64
				listener.count);
65
	}
66
67
	public void testGetValueType_ExpectedType() throws Exception {
68
		assertEquals(formatFail("Type of the value should be returned from getType()."),
69
				delegate.getValueType(observable), observable.getValueType());
70
	}
71
72
	public void testChange_OrderOfNotifications() throws Exception {
73
		final List listeners = new ArrayList();
74
		IChangeListener changeListener = new IChangeListener() {
75
			public void handleChange(ChangeEvent event) {
76
				listeners.add(this);
77
			}
78
		};
79
80
		IValueChangeListener valueChangeListener = new IValueChangeListener() {
81
			public void handleValueChange(ValueChangeEvent event) {
82
				listeners.add(this);
83
			}
84
		};
85
86
		observable.addChangeListener(changeListener);
87
		observable.addValueChangeListener(valueChangeListener);
88
89
		delegate.change(observable);
90
		
91
		assertTrue(formatFail("Change Listeners were not notified on change."), listeners.size() > 0);
92
		
93
		// not asserting the fact that both are notified as this is asserted in
94
		// other tests
95
		assertEquals(
96
				formatFail("Change listeners should be notified before value change listeners."),
97
				changeListener, listeners.get(0));
98
		assertEquals(
99
				formatFail("Value change listeners should be notified after change listeners."),
100
				valueChangeListener, listeners.get(1));
101
	}
102
103
	public void testChange_ValueChangeEventDiff() throws Exception {
104
		ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable);
105
		Object oldValue = observable.getValue();
106
107
		delegate.change(observable);
108
109
		ValueChangeEvent event = listener.event;
110
		
111
		assertTrue(formatFail("Change Listeners were not notified on change."), listener.count > 0);
112
		
113
		assertEquals(
114
				formatFail("When a value change event is fired the old value should be the previous value of the observable value."),
115
				oldValue, event.diff.getOldValue());
116
		assertEquals(
117
				formatFail("When a value change event is fired the new value should be the same as the current value of the observable value."),
118
				observable.getValue(), event.diff.getNewValue());
119
	}
120
121
	public void testChange_ValueChangeEventFiredAfterValueIsSet()
122
			throws Exception {
123
		class ValueChangeListener implements IValueChangeListener {
124
			Object value;
125
126
			public void handleValueChange(ValueChangeEvent event) {
127
				this.value = event.getObservableValue().getValue();
128
			}
129
		}
130
		
131
		ValueChangeListener listener = new ValueChangeListener();
132
		observable.addValueChangeListener(listener);
133
		delegate.change(observable);
134
		assertEquals(
135
				formatFail("When a value change event is fired the new value should be applied before firing the change event."),
136
				listener.value, observable.getValue());
137
	}
138
139
	public void testRemoveValueChangeListener_RemovesListener() throws Exception {
140
		ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable);
141
		delegate.change(observable);
142
143
		// precondition
144
		assertEquals(formatFail("Value change listeners should be notified on change."), 1,
145
				listener.count);
146
147
		observable.removeValueChangeListener(listener);
148
		delegate.change(observable);
149
150
		assertEquals(
151
				formatFail("Value change listeners should not be notified after they've been removed from the observable."),
152
				1, listener.count);
153
	}
154
155
	public void testGetValue_GetterCalled() throws Exception {
156
		assertGetterCalled(new Runnable() {
157
			public void run() {
158
				observable.getValue();
159
			}
160
		}, formatFail("IObservableValue.getValue()"), observable);
161
	}
162
163
	public void testGetValue_RealmCheck() throws Exception {
164
		RealmTester.exerciseCurrent(new Runnable() {
165
			public void run() {
166
				observable.getValue();
167
			}
168
		}, (CurrentRealm) observable.getRealm());
169
	}
170
}
(-)src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableValueContractDelegate.java (+55 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.delegate;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.value.IObservableValue;
17
18
/**
19
 * Abstract implementation of {@link IObservableValueContractDelegate}.
20
 * 
21
 * @since 1.1
22
 */
23
public abstract class AbstractObservableValueContractDelegate extends
24
		AbstractObservableContractDelegate implements
25
		IObservableValueContractDelegate {
26
27
	/**
28
	 * Invokes {@link #createObservableValue(Realm)}.
29
	 * @param realm 
30
	 * @return observable
31
	 */
32
	public final IObservable createObservable(Realm realm) {
33
		return createObservableValue(realm);
34
	}
35
36
	/**
37
	 * Default implementation returns <code>null</code>.
38
	 * @param observable 
39
	 * @return value type
40
	 */
41
	public Object getValueType(IObservableValue observable) {
42
		// no op
43
		return null;
44
	}
45
	
46
	/**
47
	 * Default implementation returns <code>null</code>.
48
	 * @param observable 
49
	 * @return value
50
	 */
51
	public Object createValue(IObservableValue observable) {
52
		//no op
53
		return null;
54
	}
55
}
(-)src/org/eclipse/jface/databinding/conformance/util/RealmTester.java (+106 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.util;
13
14
import junit.framework.Assert;
15
16
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.runtime.AssertionFailedException;
18
19
/**
20
 * Aids in the testing of Realms.
21
 * 
22
 * @since 3.2
23
 */
24
public class RealmTester {
25
26
	/**
27
	 * Sets the default realm without using Realm.runWithDefault() for testing
28
	 * purposes.
29
	 * 
30
	 * @param realm
31
	 */
32
	public static void setDefault(Realm realm) {
33
		CurrentRealm.setDefault(realm);
34
	}
35
36
	/**
37
	 * Runs the provided <code>runnable</code> when the realm is both current
38
	 * and not current. It checks for AssertionFailedExceptions and if an
39
	 * exception occurs or doesn't occur as expected the test fails. The realm
40
	 * of an observable created before the method was invoked must be of type
41
	 * {@link CurrentRealm}. The default realm during the runnable invocation
42
	 * is set to an instance of {@link CurrentRealm} when the runnable is
43
	 * invoked.
44
	 * 
45
	 * @param runnable
46
	 */
47
	public static void exerciseCurrent(Runnable runnable) {
48
		CurrentRealm previousRealm = (CurrentRealm) Realm.getDefault();
49
		CurrentRealm realm = new CurrentRealm();
50
		setDefault(realm);
51
52
		try {
53
			realm.setCurrent(true);
54
			if (previousRealm != null) {
55
				previousRealm.setCurrent(true);
56
			}
57
58
			try {
59
				runnable.run();
60
			} catch (AssertionFailedException e) {
61
				Assert
62
						.fail("Correct realm, exception should not have been thrown");
63
			}
64
65
			realm.setCurrent(false);
66
			if (previousRealm != null) {
67
				previousRealm.setCurrent(false);
68
			}
69
70
			try {
71
				runnable.run();
72
				Assert
73
						.fail("Incorrect realm, exception should have been thrown");
74
			} catch (AssertionFailedException e) {
75
			}
76
		} finally {
77
			setDefault(previousRealm);
78
		}
79
	}
80
81
	/**
82
	 * Runs the provided <code>runnable</code> when the realm is both current
83
	 * and not current. It checks for AssertionFailedExceptions and if an
84
	 * exception occurs or doesn't occur as expected the test fails.
85
	 * 
86
	 * @param runnable
87
	 * @param realm
88
	 */
89
	public static void exerciseCurrent(Runnable runnable, CurrentRealm realm) {
90
		realm.setCurrent(true);
91
92
		try {
93
			runnable.run();
94
		} catch (AssertionFailedException e) {
95
			Assert.fail("Correct realm, exception should not have been thrown");
96
		}
97
98
		realm.setCurrent(false);
99
100
		try {
101
			runnable.run();
102
			Assert.fail("Incorrect realm, exception should have been thrown");
103
		} catch (AssertionFailedException e) {
104
		}
105
	}
106
}
(-)src/org/eclipse/jface/databinding/conformance/util/ListChangeEventTracker.java (+50 lines)
Added Link Here
1
package org.eclipse.jface.databinding.conformance.util;
2
3
import java.util.List;
4
5
import org.eclipse.core.databinding.observable.list.IListChangeListener;
6
import org.eclipse.core.databinding.observable.list.IObservableList;
7
import org.eclipse.core.databinding.observable.list.ListChangeEvent;
8
9
/**
10
 * Listener for tracking the firing of ListChangeEvents.
11
 */
12
public class ListChangeEventTracker implements IListChangeListener {
13
	public int count;
14
15
	public ListChangeEvent event;
16
17
	/**
18
	 * Queue that the listener will add itself too when it is notified of an
19
	 * event. Used to determine order of notifications of listeners.
20
	 */
21
	public final List listenerQueue;
22
23
	public ListChangeEventTracker() {
24
		this(null);
25
	}
26
27
	public ListChangeEventTracker(List listenerQueue) {
28
		this.listenerQueue = listenerQueue;
29
	}
30
31
	public void handleListChange(ListChangeEvent event) {
32
		count++;
33
		this.event = event;
34
		if (listenerQueue != null) {
35
			listenerQueue.add(this);
36
		}
37
	}
38
	
39
	/**
40
	 * Convenience method to register a new listener.
41
	 * 
42
	 * @param observable
43
	 * @return tracker
44
	 */
45
	public static ListChangeEventTracker observe(IObservableList observable) {
46
		ListChangeEventTracker tracker = new ListChangeEventTracker();
47
		observable.addListChangeListener(tracker);
48
		return tracker;
49
	}
50
}
(-)src/org/eclipse/jface/databinding/conformance/delegate/IObservableValueContractDelegate.java (+56 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.delegate;
13
14
import org.eclipse.core.databinding.observable.Realm;
15
import org.eclipse.core.databinding.observable.value.IObservableValue;
16
17
/**
18
 * Delegate interface for an observable value.
19
 * 
20
 * <p>
21
 * This interface is not intended to be implemented by clients. Clients should
22
 * instead subclass one of the classes that implement this interface. Note that
23
 * direct implementers of this interface outside of the framework will be broken
24
 * in future releases when methods are added to this interface.
25
 * </p>
26
 * 
27
 * @since 1.1
28
 */
29
public interface IObservableValueContractDelegate extends
30
		IObservableContractDelegate {
31
32
	/**
33
	 * Creates a new observable value.
34
	 * 
35
	 * @param realm
36
	 *            realm of the observable
37
	 * @return observable value
38
	 */
39
	public IObservableValue createObservableValue(Realm realm);
40
41
	/**
42
	 * Returns the expected type of the observable.
43
	 * 
44
	 * @param observable
45
	 * @return type
46
	 */
47
	public Object getValueType(IObservableValue observable);
48
	
49
	/**
50
	 * Returns a valid value that is not the current value of the observable.
51
	 * 
52
	 * @param observable
53
	 * @return value
54
	 */
55
	public Object createValue(IObservableValue observable);
56
}
(-)src/org/eclipse/jface/databinding/conformance/ObservableContractTest.java (+175 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import org.eclipse.core.databinding.observable.ChangeEvent;
15
import org.eclipse.core.databinding.observable.IChangeListener;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.ObservableTracker;
18
import org.eclipse.jface.databinding.conformance.delegate.IObservableContractDelegate;
19
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
20
import org.eclipse.jface.databinding.conformance.util.RealmTester;
21
22
/**
23
 * Tests for IObservable that don't require mutating the observable.
24
 * <p>
25
 * This class is experimental and can change at any time. It is recommended to
26
 * not subclass or assume the test names will not change. The only API that is
27
 * guaranteed to not change are the constructors. The tests will remain public
28
 * and not final in order to allow for consumers to turn off a test if needed by
29
 * subclassing.
30
 * </p>
31
 * 
32
 * @since 3.2
33
 */
34
public class ObservableContractTest extends ObservableDelegateTest {
35
	private IObservable observable;
36
37
	private IObservableContractDelegate delegate;
38
39
	public ObservableContractTest(IObservableContractDelegate delegate) {
40
		this(null, delegate);
41
	}
42
43
	public ObservableContractTest(String testName,
44
			IObservableContractDelegate delegate) {
45
		super(testName, delegate);
46
		
47
		this.delegate = delegate;
48
	}
49
50
	protected void setUp() throws Exception {
51
		super.setUp();
52
		observable = getObservable();
53
	}
54
55
	public void testGetRealm_NotNull() throws Exception {
56
		assertNotNull(formatFail("The observable's realm should not be null."), observable
57
				.getRealm());
58
	}
59
60
	public void testChange_ChangeEvent() throws Exception {
61
		ChangeListener listener = new ChangeListener();
62
63
		observable.addChangeListener(listener);
64
		delegate.change(observable);
65
66
		assertEquals(
67
				formatFail("A change in the observable should notify change listeners."),
68
				listener.count, 1);
69
	}
70
71
	public void testChange_EventObservable() throws Exception {
72
		ChangeListener listener = new ChangeListener();
73
74
		observable.addChangeListener(listener);
75
		delegate.change(observable);
76
77
		ChangeEvent event = listener.event;
78
		assertNotNull(formatFail("change event was null"), event);
79
80
		assertSame(
81
				formatFail("In the change event the source of the change should be the observable."),
82
				observable, event.getObservable());
83
	}
84
85
	public void testChange_RealmCheck() throws Exception {
86
		RealmTester.exerciseCurrent(new Runnable() {
87
			public void run() {
88
				delegate.change(observable);
89
			}			
90
		}, (CurrentRealm) observable.getRealm());
91
	}
92
	
93
	public void testChange_ObservableRealmIsTheCurrentRealm() throws Exception {
94
		ChangeListener listener = new ChangeListener();
95
		observable.addChangeListener(listener);
96
97
		delegate.change(observable);
98
		assertTrue(
99
				formatFail("On change the current realm should be the realm of the observable."),
100
				listener.isCurrentRealm);
101
	}
102
103
	public void testRemoveChangeListener_RemovesListener() throws Exception {
104
		ChangeListener listener = new ChangeListener();
105
106
		observable.addChangeListener(listener);
107
		delegate.change(observable);
108
109
		// precondition check
110
		assertEquals(formatFail("change did not notify listeners"), 1, listener.count);
111
112
		observable.removeChangeListener(listener);
113
		delegate.change(observable);
114
115
		assertEquals(
116
				formatFail("When a change listener is removed it should not still receive change events."),
117
				1, listener.count);
118
	}
119
120
	public void testIsStale_NotStale() throws Exception {
121
		delegate.setStale(observable, false);
122
		assertFalse(
123
				formatFail("When an observable is not stale isStale() should return false."),
124
				observable.isStale());
125
	}
126
	
127
	public void testIsStale_RealmChecks() throws Exception {
128
		RealmTester.exerciseCurrent(new Runnable() {
129
			public void run() {
130
				delegate.change(observable);
131
			}			
132
		}, (CurrentRealm) observable.getRealm());
133
	}
134
135
	/**
136
	 * Asserts that ObservableTracker.getterCalled(...) is invoked when the
137
	 * provided <code>runnable</code> is invoked.
138
	 * 
139
	 * @param runnable
140
	 * @param methodName
141
	 *            method name to display when displaying a message
142
	 * @param observable
143
	 *            observable that should be collected by ObservableTracker
144
	 */
145
	protected void assertGetterCalled(Runnable runnable,
146
			String methodName, IObservable observable) {
147
		IObservable[] observables = ObservableTracker.runAndMonitor(runnable,
148
				null, null);
149
150
		int count = 0;
151
		for (int i = 0; i < observables.length; i++) {
152
			if (observables[i] == observable) {
153
				count++;
154
			}
155
		}
156
		
157
		assertEquals(formatFail(methodName
158
				+ " should invoke ObservableTracker.getterCalled() once."), 1,
159
				count);
160
	}
161
	
162
	/* package */static class ChangeListener implements IChangeListener {
163
		int count;
164
165
		ChangeEvent event;
166
167
		boolean isCurrentRealm;
168
169
		public void handleChange(ChangeEvent event) {
170
			count++;
171
			this.event = event;
172
			this.isCurrentRealm = event.getObservable().getRealm().isCurrent();
173
		}
174
	}
175
}
(-)src/org/eclipse/jface/databinding/conformance/delegate/IObservableCollectionContractDelegate.java (+60 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.delegate;
13
14
import org.eclipse.core.databinding.observable.IObservableCollection;
15
import org.eclipse.core.databinding.observable.Realm;
16
17
/**
18
 * Delegate interface for an IObservableCollection.
19
 * 
20
 * <p>
21
 * This interface is not intended to be implemented by clients. Clients should
22
 * instead subclass one of the classes that implement this interface. Note that
23
 * direct implementers of this interface outside of the framework will be broken
24
 * in future releases when methods are added to this interface.
25
 * </p>
26
 * 
27
 * @since 1.1
28
 */
29
public interface IObservableCollectionContractDelegate extends
30
		IObservableContractDelegate {
31
	/**
32
	 * Creates a new observable collection with the provided
33
	 * <code>elementCount</code>.
34
	 * 
35
	 * @param realm realm of the collection
36
	 * @param elementCount
37
	 *            number of elements to initialize the collection with
38
	 * 
39
	 * @return new observable collection
40
	 */
41
	public IObservableCollection createObservableCollection(Realm realm, int elementCount);
42
43
	/**
44
	 * Creates a new element of the appropriate type for the provided
45
	 * <code>collection</code>. This element will be employed to assert the
46
	 * addition and removal of elements in the collection.
47
	 * 
48
	 * @param collection
49
	 * @return valid element for the collection
50
	 */
51
	public Object createElement(IObservableCollection collection);
52
53
	/**
54
	 * Returns the expected type of the elements in the collection.
55
	 * 
56
	 * @param collection
57
	 * @return element type
58
	 */
59
	public Object getElementType(IObservableCollection collection);
60
}
(-).settings/org.eclipse.jdt.core.prefs (+66 lines)
Added Link Here
1
#Sat Sep 15 18:25:36 MDT 2007
2
eclipse.preferences.version=1
3
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=disabled
4
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.2
5
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
6
org.eclipse.jdt.core.compiler.compliance=1.4
7
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
8
org.eclipse.jdt.core.compiler.debug.localVariable=generate
9
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
10
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
11
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
12
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
13
org.eclipse.jdt.core.compiler.problem.deprecation=warning
14
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
15
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
16
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
17
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
18
org.eclipse.jdt.core.compiler.problem.enumIdentifier=warning
19
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
20
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
21
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
22
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
23
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
24
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
25
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
26
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
27
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
28
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
29
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
30
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
31
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
32
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
33
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
34
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
35
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
36
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
37
org.eclipse.jdt.core.compiler.problem.nullReference=ignore
38
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
39
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
40
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
41
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
42
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
43
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
44
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
45
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
46
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
47
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
48
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
49
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
50
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
51
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
52
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
53
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
54
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
55
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
56
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
57
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
58
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
59
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
60
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
61
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
62
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
63
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
64
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
65
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
66
org.eclipse.jdt.core.compiler.source=1.3
(-)src/org/eclipse/jface/databinding/conformance/util/ChangeEventTracker.java (+49 lines)
Added Link Here
1
package org.eclipse.jface.databinding.conformance.util;
2
3
import java.util.List;
4
5
import org.eclipse.core.databinding.observable.ChangeEvent;
6
import org.eclipse.core.databinding.observable.IChangeListener;
7
import org.eclipse.core.databinding.observable.IObservable;
8
9
/**
10
 * Listener for tracking the firing of ChangeEvents.
11
 */
12
public class ChangeEventTracker implements IChangeListener {
13
	public int count;
14
	public ChangeEvent event;
15
16
	/**
17
	 * Queue that the listener will add itself too when it is notified of an
18
	 * event. Used to determine order of notifications of listeners.  Can be null.
19
	 */
20
	public final List queue;
21
22
	public ChangeEventTracker() {
23
		queue = null;
24
	}
25
26
	public ChangeEventTracker(List notificationQueue) {
27
		this.queue = notificationQueue;
28
	}
29
30
	public void handleChange(ChangeEvent event) {
31
		count++;
32
		this.event = event;
33
		if (queue != null) {
34
			queue.add(this);
35
		}
36
	}
37
38
	/**
39
	 * Convenience method to register a new listener.
40
	 * 
41
	 * @param observable
42
	 * @return tracker
43
	 */
44
	public static ChangeEventTracker observe(IObservable observable) {
45
		ChangeEventTracker tracker = new ChangeEventTracker();
46
		observable.addChangeListener(tracker);
47
		return tracker;
48
	}
49
}
(-)src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableCollectionContractDelegate.java (+45 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.delegate;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.core.databinding.observable.IObservableCollection;
16
import org.eclipse.core.databinding.observable.Realm;
17
18
/**
19
 * Abstract implementation of {@link IObservableCollectionContractDelegate}.
20
 * 
21
 * @since 3.2
22
 */
23
public abstract class AbstractObservableCollectionContractDelegate extends
24
		AbstractObservableContractDelegate implements
25
		IObservableCollectionContractDelegate {
26
27
	/**
28
	 * Invokes {@link IObservableCollectionContractDelegate#createObservableCollection(Realm, int)}.
29
	 * @param realm 
30
	 * @return observable
31
	 */
32
	public final IObservable createObservable(Realm realm) {
33
		return createObservableCollection(realm, 0);
34
	}
35
	
36
	public Object createElement(IObservableCollection collection) {
37
		//no op
38
		return null;
39
	}
40
41
	public Object getElementType(IObservableCollection collection) {
42
		//no op
43
		return null;
44
	}
45
}
(-)src/org/eclipse/jface/databinding/conformance/util/SuiteBuilder.java (+181 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.util;
13
14
import java.lang.reflect.Constructor;
15
import java.lang.reflect.Method;
16
import java.util.Iterator;
17
import java.util.LinkedHashSet;
18
19
import org.eclipse.jface.databinding.conformance.delegate.IObservableContractDelegate;
20
21
import junit.framework.Test;
22
import junit.framework.TestSuite;
23
24
/**
25
 * Builds a test suite.
26
 * 
27
 * @since 1.1
28
 */
29
public class SuiteBuilder {
30
	private LinkedHashSet content;
31
32
	public SuiteBuilder() {
33
		content = new LinkedHashSet();
34
	}
35
36
	/**
37
	 * Adds all test methods from the provided <code>testCase</code> to the
38
	 * suite.
39
	 * 
40
	 * @param testCase
41
	 * @return builder
42
	 */
43
	public SuiteBuilder addTests(Class testCase) {
44
		content.add(testCase);
45
		return this;
46
	}
47
48
	/**
49
	 * Adds all test methods from the provided <code>testCase</code> with the
50
	 * provided <code>parameters</code>. A constructor must exist in the
51
	 * testCase that accepts a String as the first parameter followed by
52
	 * parameters matching the provided parameters. If an appropriate
53
	 * constructor is not found an exception will be thrown.
54
	 * 
55
	 * @param testCase
56
	 * @param parameters
57
	 * @return builder
58
	 */
59
	public SuiteBuilder addParameterizedTests(Class testCase,
60
			Object[] parameters) {
61
62
		Constructor constructor = findConstructor(testCase, parameters);
63
		if (constructor == null) {
64
			throw new IllegalArgumentException(
65
					"The parameters provided don't match a constructor found in ["
66
							+ testCase.getName() + "]");
67
		}
68
69
		content.add(new ParameterizedTest(testCase, constructor, parameters));
70
71
		return this;
72
	}
73
74
	/**
75
	 * Convenience method for invoking
76
	 * {@link #addParameterizedTests(Class, Object[])} with a delegate.
77
	 * 
78
	 * @param testCase
79
	 * @param delegate
80
	 * @return builder
81
	 */
82
	public SuiteBuilder addObservableContractTest(Class testCase,
83
			IObservableContractDelegate delegate) {
84
85
		addParameterizedTests(testCase, new Object[] {delegate});
86
		return this;
87
	}
88
89
	/**
90
	 * Builds a new TestSuite out of the tests.
91
	 * 
92
	 * @return suite
93
	 */
94
	public TestSuite build() {
95
		TestSuite suite = new TestSuite();
96
97
		for (Iterator it = content.iterator(); it.hasNext();) {
98
			Object o = it.next();
99
			if (o instanceof Class) {
100
				suite.addTestSuite((Class) o);
101
			} else if (o instanceof ParameterizedTest) {
102
				ParameterizedTest test = (ParameterizedTest) o;
103
104
				Method[] methods = test.testClass.getMethods();
105
				for (int i = 0; i < methods.length; i++) {
106
					String name = methods[i].getName();
107
					if (name.startsWith("test")) {
108
						try {
109
							suite.addTest((Test) test.constructor
110
									.newInstance(toParamArray(name,
111
											test.parameters)));
112
						} catch (Exception e) {
113
							throw new RuntimeException(e);
114
						}
115
					}
116
				}
117
			}
118
		}
119
120
		return suite;
121
	}
122
123
	private Object[] toParamArray(String testName, Object[] parameters) {
124
		Object[] result = new Object[parameters.length + 1];
125
		result[0] = testName;
126
		System.arraycopy(parameters, 0, result, 1, parameters.length);
127
		return result;
128
	}
129
130
	/**
131
	 * Returns the constructor that has a String as the first parameters and
132
	 * then matches the type of the parameters.
133
	 * @param clazz 
134
	 * @param parameters
135
	 * @return constructor
136
	 */
137
	private static Constructor findConstructor(Class clazz, Object[] parameters) {
138
		Constructor[] constructors = clazz.getConstructors();
139
		int expectedParametersLength = parameters.length + 1;
140
141
		for (int i = 0; i < constructors.length; i++) {
142
			Constructor constructor = constructors[i];
143
			Class[] types = constructor.getParameterTypes();
144
145
			if (types.length != expectedParametersLength
146
					|| !String.class.equals(types[0])) {
147
				continue;
148
			}
149
150
			boolean skip = false;
151
			for (int j = 1; j < types.length; j++) {
152
				Class type = types[j];
153
				if (!type.isInstance(parameters[j - 1])) {
154
					skip = true;
155
					break;
156
				}
157
			}
158
159
			if (!skip) {
160
				return constructor;
161
			}
162
		}
163
164
		return null;
165
	}
166
167
	/* package */static class ParameterizedTest {
168
		final Constructor constructor;
169
170
		final Object[] parameters;
171
172
		private Class testClass;
173
174
		ParameterizedTest(Class testClass, Constructor constructor,
175
				Object[] parameterss) {
176
			this.testClass = testClass;
177
			this.constructor = constructor;
178
			this.parameters = parameterss;
179
		}
180
	}
181
}
(-)src/org/eclipse/jface/databinding/conformance/MutableObservableValueContractTest.java (+104 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance;
13
14
import org.eclipse.core.databinding.observable.value.IObservableValue;
15
import org.eclipse.jface.databinding.conformance.delegate.IObservableValueContractDelegate;
16
import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker;
17
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
18
import org.eclipse.jface.databinding.conformance.util.RealmTester;
19
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
20
21
/**
22
 * Mutability tests for IObservableValue.
23
 * 
24
 * <p>
25
 * This class is experimental and can change at any time. It is recommended to
26
 * not subclass or assume the test names will not change. The only API that is
27
 * guaranteed to not change are the constructors. The tests will remain public
28
 * and not final in order to allow for consumers to turn off a test if needed by
29
 * subclassing.
30
 * </p>
31
 * 
32
 * @since 3.2
33
 */
34
public class MutableObservableValueContractTest extends
35
		ObservableDelegateTest {
36
	private IObservableValueContractDelegate delegate;
37
38
	private IObservableValue observable;
39
40
	/**
41
	 * @param delegate
42
	 */
43
	public MutableObservableValueContractTest(
44
			IObservableValueContractDelegate delegate) {
45
		this(null, delegate);
46
	}
47
48
	public MutableObservableValueContractTest(String testName,
49
			IObservableValueContractDelegate delegate) {
50
		super(testName, delegate);
51
		this.delegate = delegate;
52
	}
53
54
	protected void setUp() throws Exception {
55
		super.setUp();
56
57
		this.observable = (IObservableValue) getObservable();
58
	}
59
60
	public void testSetValue_SetsValue() throws Exception {
61
		Object value = delegate.createValue(observable);
62
		
63
		observable.setValue(value);
64
		assertEquals(formatFail("IObservableValue.setValue(Object) should set the value of the observable."), value, observable.getValue());
65
	}
66
	
67
	public void testSetValue_ChangeEvent() throws Exception {
68
		ChangeEventTracker listener = ChangeEventTracker.observe(observable);
69
		
70
		observable.setValue(delegate.createValue(observable));
71
		
72
		assertEquals(formatFail("Change event listeners were not notified"), 1, listener.count);
73
		assertEquals(formatFail("IObservableValue.setValue(Object) should fire one ChangeEvent."), 1,
74
				listener.count);
75
		assertEquals(
76
				formatFail("IObservableValue.setValue(Object)'s change event observable should be the created observable."),
77
				observable, listener.event.getObservable());
78
	}
79
	
80
	public void testSetValue_SameValue() throws Exception {
81
		// invoke change to ensure observable has a value
82
		delegate.change(observable);
83
84
		ValueChangeEventTracker valueChangeListener = ValueChangeEventTracker.observe(observable);
85
		ChangeEventTracker changeListener = ChangeEventTracker.observe(observable);
86
		Object value = observable.getValue();
87
		observable.setValue(value);
88
89
		assertEquals(
90
				formatFail("IObservableValue.setValue() should not fire a value change event when the value has not change."),
91
				0, valueChangeListener.count);
92
		assertEquals(
93
				formatFail("IObservableValue.setValue() should not fire a change event when the value has not change."),
94
				0, changeListener.count);
95
	}
96
	
97
	public void testSetValue_RealmChecks() throws Exception {
98
		RealmTester.exerciseCurrent(new Runnable() {
99
			public void run() {
100
				observable.setValue(delegate.createValue(observable));
101
			}
102
		}, (CurrentRealm) observable.getRealm());
103
	}
104
}
(-)src/org/eclipse/jface/databinding/conformance/delegate/AbstractObservableContractDelegate.java (+39 lines)
Added Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.databinding.conformance.delegate;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
16
/**
17
 * Abstract implementation of {@link IObservableContractDelegate}.
18
 * 
19
 * @since 1.1
20
 */
21
public abstract class AbstractObservableContractDelegate implements
22
		IObservableContractDelegate {
23
24
	public void setUp() {
25
		// no op
26
	}
27
28
	public void tearDown() {
29
		// no op
30
	}
31
32
	public void change(IObservable observable) {
33
		// no op
34
	}
35
36
	public void setStale(IObservable observable, boolean stale) {
37
		// no op
38
	}
39
}
(-)build.properties (+17 lines)
Added Link Here
1
###############################################################################
2
# Copyright (c) 2007 IBM Corporation and others.
3
# All rights reserved. This program and the accompanying materials
4
# are made available under the terms of the Eclipse Public License v1.0
5
# which accompanies this distribution, and is available at
6
# http://www.eclipse.org/legal/epl-v10.html
7
#
8
# Contributors:
9
# IBM Corporation - initial API and implementation
10
###############################################################################
11
bin.includes = .,\
12
               META-INF/,\
13
               plugin.properties,\
14
               about.html
15
output.databinding.jar = bin/
16
src.includes = about.html
17
source.. = src/
(-).classpath (+7 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<classpath>
3
	<classpathentry kind="src" path="src"/>
4
	<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.4"/>
5
	<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
6
	<classpathentry kind="output" path="bin"/>
7
</classpath>
(-)src/org/eclipse/jface/databinding/conformance/util/MapChangeEventTracker.java (+47 lines)
Added Link Here
1
package org.eclipse.jface.databinding.conformance.util;
2
3
import java.util.List;
4
5
import org.eclipse.core.databinding.observable.map.IMapChangeListener;
6
import org.eclipse.core.databinding.observable.map.IObservableMap;
7
import org.eclipse.core.databinding.observable.map.MapChangeEvent;
8
9
/**
10
 * Listener for tracking the firing of ChangeEvents.
11
 */
12
public class MapChangeEventTracker implements IMapChangeListener {
13
	public int count;
14
15
	public MapChangeEvent event;
16
17
	public List queue;
18
	
19
	public MapChangeEventTracker() {
20
		this(null);
21
	}
22
	
23
	public MapChangeEventTracker(List queue) {
24
		this.queue = queue;
25
	}
26
27
	public void handleMapChange(MapChangeEvent event) {
28
		count++;
29
		this.event = event;
30
		
31
		if (queue != null) {
32
			queue.add(this);
33
		}
34
	}
35
	
36
	/**
37
	 * Convenience method to register a new listener.
38
	 * 
39
	 * @param observable
40
	 * @return tracker
41
	 */
42
	public static MapChangeEventTracker observe(IObservableMap observable) {
43
		MapChangeEventTracker tracker = new MapChangeEventTracker();
44
		observable.addMapChangeListener(tracker);
45
		return tracker;
46
	}
47
}
(-)src/org/eclipse/jface/databinding/conformance/util/DelegatingRealm.java (+26 lines)
Added Link Here
1
package org.eclipse.jface.databinding.conformance.util;
2
3
import org.eclipse.core.databinding.observable.Realm;
4
5
/**
6
 * Realm that will delegate to another for all operations except calls to
7
 * {@link #isCurrent()}. The current status can be set by the consumer to
8
 * enable testing of realm checks.
9
 * 
10
 * @since 3.2
11
 */
12
public class DelegatingRealm extends CurrentRealm {
13
	private Realm realm;
14
15
	public DelegatingRealm(Realm realm) {
16
		this.realm = realm;
17
	}
18
19
	protected void syncExec(Runnable runnable) {
20
		realm.exec(runnable);
21
	}
22
23
	public void asyncExec(Runnable runnable) {
24
		realm.asyncExec(runnable);
25
	}
26
}
(-).project (+28 lines)
Added Link Here
1
<?xml version="1.0" encoding="UTF-8"?>
2
<projectDescription>
3
	<name>org.eclipse.jface.tests.databinding.conformance</name>
4
	<comment></comment>
5
	<projects>
6
	</projects>
7
	<buildSpec>
8
		<buildCommand>
9
			<name>org.eclipse.jdt.core.javabuilder</name>
10
			<arguments>
11
			</arguments>
12
		</buildCommand>
13
		<buildCommand>
14
			<name>org.eclipse.pde.ManifestBuilder</name>
15
			<arguments>
16
			</arguments>
17
		</buildCommand>
18
		<buildCommand>
19
			<name>org.eclipse.pde.SchemaBuilder</name>
20
			<arguments>
21
			</arguments>
22
		</buildCommand>
23
	</buildSpec>
24
	<natures>
25
		<nature>org.eclipse.pde.PluginNature</nature>
26
		<nature>org.eclipse.jdt.core.javanature</nature>
27
	</natures>
28
</projectDescription>
(-)src/org/eclipse/jface/conformance/databinding/AbstractObservableValueContractDelegate.java (-49 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.value.IObservableValue;
17
18
/**
19
 * Abstract implementation of {@link IObservableValueContractDelegate}.
20
 * 
21
 * @since 1.1
22
 */
23
public abstract class AbstractObservableValueContractDelegate extends
24
		AbstractObservableContractDelegate implements
25
		IObservableValueContractDelegate {
26
27
	/**
28
	 * Invokes {@link #createObservableValue(Realm)}.
29
	 */
30
	public final IObservable createObservable(Realm realm) {
31
		return createObservableValue(realm);
32
	}
33
34
	/**
35
	 * Default implementation returns <code>null</code>.
36
	 */
37
	public Object getValueType(IObservableValue observable) {
38
		// no op
39
		return null;
40
	}
41
	
42
	/**
43
	 * Default implementation returns <code>null</code>.
44
	 */
45
	public Object createValue(IObservableValue observable) {
46
		//no op
47
		return null;
48
	}
49
}
(-)src/org/eclipse/jface/conformance/databinding/ObservableListContractTest.java (-108 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.list.IObservableList;
15
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
16
17
/**
18
 * Tests for IObservableList that don't require mutating the collection.
19
 * <p>
20
 * This class is experimental and can change at any time. It is recommended to
21
 * not subclass or assume the test names will not change. The only API that is
22
 * guaranteed to not change are the constructors. The tests will remain public
23
 * and not final in order to allow for consumers to turn off a test if needed by
24
 * subclassing.
25
 * </p>
26
 * 
27
 * @since 3.2
28
 */
29
public class ObservableListContractTest extends
30
		ObservableCollectionContractTest {
31
	private IObservableList list;
32
33
	private IObservableCollectionContractDelegate delegate;
34
35
	/**
36
	 * @param delegate
37
	 */
38
	public ObservableListContractTest(
39
			IObservableCollectionContractDelegate delegate) {
40
		super(delegate);
41
		this.delegate = delegate;
42
	}
43
44
	public ObservableListContractTest(String testName,
45
			IObservableCollectionContractDelegate delegate) {
46
		super(testName, delegate);
47
		this.delegate = delegate;
48
	}
49
50
	protected void setUp() throws Exception {
51
		super.setUp();
52
53
		list = (IObservableList) getObservable();
54
	}
55
56
	public void testListIterator_GetterCalled() throws Exception {
57
		assertGetterCalled(new Runnable() {
58
			public void run() {
59
				list.listIterator();
60
			}
61
		}, "List.listIterator()", list);
62
	}
63
64
	public void testGet_GetterCalled() throws Exception {
65
		list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1);
66
		assertGetterCalled(new Runnable() {
67
			public void run() {
68
				list.get(0);
69
			}
70
		}, "List.get(int)", list);
71
	}
72
73
	public void testIndexOf_GetterCalled() throws Exception {
74
		assertGetterCalled(new Runnable() {
75
			public void run() {
76
				list.indexOf(delegate.createElement(list));
77
			}
78
		}, "List.indexOf(int)", list);
79
	}
80
81
	public void testLastIndexOf_GetterCalled() throws Exception {
82
		assertGetterCalled(new Runnable() {
83
			public void run() {
84
				list.lastIndexOf(delegate.createElement(list));
85
			}
86
		}, "List.lastIndexOf(Object)", list);
87
	}
88
89
	public void testListIteratorAtIndex_GetterCalled() throws Exception {
90
		// Create a new list instead of adding an item because the list might
91
		// not be mutable
92
		list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1);
93
		assertGetterCalled(new Runnable() {
94
			public void run() {
95
				list.listIterator(0);
96
			}
97
		}, "List.listIterator(int)", list);
98
	}
99
100
	public void testSubList_GetterCalled() throws Exception {
101
		list = (IObservableList) delegate.createObservableCollection(new CurrentRealm(true), 1);
102
		assertGetterCalled(new Runnable() {
103
			public void run() {
104
				list.subList(0, 1);
105
			}
106
		}, "List.subList(int, int)", list);
107
	}
108
}
(-)src/org/eclipse/jface/conformance/databinding/MutableObservableValueContractTest.java (-104 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.value.IObservableValue;
15
import org.eclipse.jface.tests.databinding.RealmTester;
16
import org.eclipse.jface.tests.databinding.EventTrackers.ChangeEventTracker;
17
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
18
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
19
20
/**
21
 * Mutability tests for IObservableValue.
22
 * 
23
 * <p>
24
 * This class is experimental and can change at any time. It is recommended to
25
 * not subclass or assume the test names will not change. The only API that is
26
 * guaranteed to not change are the constructors. The tests will remain public
27
 * and not final in order to allow for consumers to turn off a test if needed by
28
 * subclassing.
29
 * </p>
30
 * 
31
 * @since 3.2
32
 */
33
public class MutableObservableValueContractTest extends
34
		ObservableDelegateTest {
35
	private IObservableValueContractDelegate delegate;
36
37
	private IObservableValue observable;
38
39
	/**
40
	 * @param delegate
41
	 */
42
	public MutableObservableValueContractTest(
43
			IObservableValueContractDelegate delegate) {
44
		this(null, delegate);
45
	}
46
47
	public MutableObservableValueContractTest(String testName,
48
			IObservableValueContractDelegate delegate) {
49
		super(testName, delegate);
50
		this.delegate = delegate;
51
	}
52
53
	protected void setUp() throws Exception {
54
		super.setUp();
55
56
		this.observable = (IObservableValue) getObservable();
57
	}
58
59
	public void testSetValue_SetsValue() throws Exception {
60
		Object value = delegate.createValue(observable);
61
		
62
		observable.setValue(value);
63
		assertEquals(formatFail("IObservableValue.setValue(Object) should set the value of the observable."), value, observable.getValue());
64
	}
65
	
66
	public void testSetValue_ChangeEvent() throws Exception {
67
		ChangeEventTracker listener = new ChangeEventTracker().register(observable);
68
		
69
		observable.setValue(delegate.createValue(observable));
70
		
71
		assertEquals(formatFail("Change event listeners were not notified"), 1, listener.count);
72
		assertEquals(formatFail("IObservableValue.setValue(Object) should fire one ChangeEvent."), 1,
73
				listener.count);
74
		assertEquals(
75
				formatFail("IObservableValue.setValue(Object)'s change event observable should be the created observable."),
76
				observable, listener.event.getObservable());
77
	}
78
	
79
	public void testSetValue_SameValue() throws Exception {
80
		// invoke change to ensure observable has a value
81
		delegate.change(observable);
82
83
		ValueChangeEventTracker valueChangeListener = new ValueChangeEventTracker()
84
				.register(observable);
85
		ChangeEventTracker changeListener = new ChangeEventTracker().register(observable);
86
		Object value = observable.getValue();
87
		observable.setValue(value);
88
89
		assertEquals(
90
				formatFail("IObservableValue.setValue() should not fire a value change event when the value has not change."),
91
				0, valueChangeListener.count);
92
		assertEquals(
93
				formatFail("IObservableValue.setValue() should not fire a change event when the value has not change."),
94
				0, changeListener.count);
95
	}
96
	
97
	public void testSetValue_RealmChecks() throws Exception {
98
		RealmTester.exerciseCurrent(new Runnable() {
99
			public void run() {
100
				observable.setValue(delegate.createValue(observable));
101
			}
102
		}, (CurrentRealm) observable.getRealm());
103
	}
104
}
(-)src/org/eclipse/jface/conformance/databinding/MutableObservableListContractTest.java (-492 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.List;
17
18
import org.eclipse.core.databinding.observable.list.IObservableList;
19
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
20
import org.eclipse.jface.tests.databinding.EventTrackers.ChangeEventTracker;
21
import org.eclipse.jface.tests.databinding.EventTrackers.ListChangeEventTracker;
22
23
/**
24
 * Mutability tests for IObservableList.
25
 * 
26
 * <p>
27
 * This class is experimental and can change at any time. It is recommended to
28
 * not subclass or assume the test names will not change. The only API that is
29
 * guaranteed to not change are the constructors. The tests will remain public
30
 * and not final in order to allow for consumers to turn off a test if needed by
31
 * subclassing.
32
 * </p>
33
 * 
34
 * @since 3.2
35
 */
36
public class MutableObservableListContractTest extends
37
		MutableObservableCollectionContractTest {
38
	private IObservableCollectionContractDelegate delegate;
39
40
	private IObservableList list;
41
42
	/**
43
	 * @param delegate
44
	 */
45
	public MutableObservableListContractTest(
46
			IObservableCollectionContractDelegate delegate) {
47
		super(delegate);
48
		this.delegate = delegate;
49
	}
50
51
	public MutableObservableListContractTest(String testName,
52
			IObservableCollectionContractDelegate delegate) {
53
		super(testName, delegate);
54
		this.delegate = delegate;
55
	}
56
57
	protected void setUp() throws Exception {
58
		super.setUp();
59
		list = (IObservableList) getObservable();
60
	}
61
62
	public void testAdd_ListChangeEvent() throws Exception {
63
		assertListChangeEventFired(new Runnable() {
64
			public void run() {
65
				list.add(delegate.createElement(list));
66
			}
67
		}, "List.add(Object)", list);
68
	}
69
70
	public void testAdd_ListDiffEntry() throws Exception {
71
		list.add(delegate.createElement(list));
72
		final Object element = delegate.createElement(list);
73
74
		assertAddDiffEntry(new Runnable() {
75
			public void run() {
76
				list.add(element);
77
			}
78
		}, "List.add(Object)", list, element, 1);
79
	}
80
81
	public void testAddAtIndex_ChangeEvent() throws Exception {
82
		assertChangeEventFired(new Runnable() {
83
			public void run() {
84
				list.add(0, delegate.createElement(list));
85
			}
86
		}, "List.add(int, Object)", list);
87
	}
88
89
	public void testAddAtIndex_ListChangeEvent() throws Exception {
90
		assertListChangeEventFired(new Runnable() {
91
			public void run() {
92
				list.add(0, delegate.createElement(list));
93
			}
94
		}, "List.add(int, Object)", list);
95
	}
96
97
	public void testAddAtIndex_ChangeEventFiredAfterElementIsAdded()
98
			throws Exception {
99
		final Object element = delegate.createElement(list);
100
101
		assertContainsDuringChangeEvent(new Runnable() {
102
			public void run() {
103
				list.add(0, element);
104
			}
105
		}, "List.add(int, Collection)", list, element);
106
	}
107
108
	public void testAddAtIndex_ListDiffEntry() throws Exception {
109
		list.add(delegate.createElement(list));
110
		final Object element = delegate.createElement(list);
111
112
		assertAddDiffEntry(new Runnable() {
113
			public void run() {
114
				list.add(1, element);
115
			}
116
		}, "List.add(int, Object)", list, element, 1);
117
	}
118
119
	public void testAddAll_ListChangeEvent() throws Exception {
120
		assertListChangeEventFired(new Runnable() {
121
			public void run() {
122
				list.addAll(Arrays.asList(new Object[] { delegate
123
						.createElement(list) }));
124
			}
125
		}, "List.addAll(Collection", list);
126
	}
127
128
	public void testAddAll_ListDiffEntry() throws Exception {
129
		final Object element = delegate.createElement(list);
130
131
		assertAddDiffEntry(new Runnable() {
132
			public void run() {
133
				list.addAll(Arrays.asList(new Object[] { element }));
134
			}
135
		}, "List.addAll(Collection)", list, element, 0);
136
	}
137
138
	public void testAddAllAtIndex_ChangeEvent() throws Exception {
139
		assertChangeEventFired(new Runnable() {
140
			public void run() {
141
				list.addAll(0, Arrays.asList(new Object[] { delegate
142
						.createElement(list) }));
143
			}
144
		}, "List.addAll(int, Collection)", list);
145
	}
146
147
	public void testAddAllAtIndex_ListChangeEvent() throws Exception {
148
		assertListChangeEventFired(new Runnable() {
149
			public void run() {
150
				list.addAll(0, Arrays.asList(new Object[] { delegate
151
						.createElement(list) }));
152
			}
153
		}, "List.addAll(int, Collection)", list);
154
	}
155
156
	public void testAddAllAtIndex_ChangeEventFiredAfterElementIsAdded()
157
			throws Exception {
158
		final Object element = delegate.createElement(list);
159
160
		assertContainsDuringChangeEvent(new Runnable() {
161
			public void run() {
162
				list.addAll(0, Arrays.asList(new Object[] { element }));
163
			}
164
		}, "List.addAll(int, Collection)", list, element);
165
	}
166
167
	public void testAddAllAtIndex_ListDiffEntry() throws Exception {
168
		list.add(delegate.createElement(list));
169
		final Object element = delegate.createElement(list);
170
171
		assertAddDiffEntry(new Runnable() {
172
			public void run() {
173
				list.addAll(1, Arrays.asList(new Object[] { element }));
174
			}
175
		}, "List.addAll(int, Collection)", list, element, 1);
176
	}
177
178
	public void testSet_ChangeEvent() throws Exception {
179
		list.add(delegate.createElement(list));
180
181
		assertChangeEventFired(new Runnable() {
182
			public void run() {
183
				list.set(0, delegate.createElement(list));
184
			}
185
		}, "List.set(int, Object)", list);
186
	}
187
188
	public void testSet_ListChangeEvent() throws Exception {
189
		list.add(delegate.createElement(list));
190
191
		assertListChangeEventFired(new Runnable() {
192
			public void run() {
193
				list.set(0, delegate.createElement(list));
194
			}
195
		}, "List.set(int, Object)", list);
196
	}
197
198
	public void testSet_ChangeEventFiredAfterElementIsSet() throws Exception {
199
		Object element1 = delegate.createElement(list);
200
		list.add(element1);
201
		final Object element2 = delegate.createElement(list);
202
203
		assertContainsDuringChangeEvent(new Runnable() {
204
			public void run() {
205
				list.set(0, element2);
206
			}
207
		}, "List.set(int, Object)", list, element2);
208
	}
209
210
	public void testSet_ListDiffEntry() throws Exception {
211
		list.add(delegate.createElement(list));
212
		Object oldElement = delegate.createElement(list);
213
		list.add(oldElement);
214
215
		ListChangeEventTracker listener = new ListChangeEventTracker();
216
		list.addListChangeListener(listener);
217
218
		Object newElement = delegate.createElement(list);
219
		list.set(1, newElement);
220
221
		ListDiffEntry[] entries = listener.event.diff.getDifferences();
222
		assertEquals(
223
				"List.set(int, Object) should result in 2 list diff entries.",
224
				2, entries.length);
225
226
		ListDiffEntry add = null;
227
		ListDiffEntry remove = null;
228
229
		if (entries[0].isAddition() && !entries[1].isAddition()) {
230
			add = entries[0];
231
			remove = entries[1];
232
		} else if (!entries[0].isAddition() && entries[1].isAddition()) {
233
			add = entries[1];
234
			remove = entries[0];
235
		} else {
236
			fail("List.set(int, Object) should result in an add and a remove entry.");
237
		}
238
239
		assertEquals(
240
				"List.set(int, Object) removed element should be the old element.",
241
				oldElement, remove.getElement());
242
		assertEquals(
243
				"List.set(int, Object) removed index should be the index the new element was set at.",
244
				1, remove.getPosition());
245
246
		assertEquals(
247
				"List.set(int, Object) added element should be the set element.",
248
				newElement, add.getElement());
249
		assertEquals(
250
				"List.set(int, Object) add index should be the index the new element was set at.",
251
				1, add.getPosition());
252
	}
253
254
	public void testRemove_ListChangeEvent() throws Exception {
255
		final Object element = delegate.createElement(list);
256
		list.add(element);
257
258
		assertListChangeEventFired(new Runnable() {
259
			public void run() {
260
				list.remove(element);
261
			}
262
		}, "List.remove(Object)", list);
263
	}
264
265
	public void testRemove_ListDiffEntry() throws Exception {
266
		list.add(delegate.createElement(list));
267
		final Object element = delegate.createElement(list);
268
		list.add(element);
269
270
		assertRemoveDiffEntry(new Runnable() {
271
			public void run() {
272
				list.remove(element);
273
			}
274
		}, "List.remove(Object)", list, element, 1);
275
	}
276
277
	public void testRemoveAtIndex_ChangeEvent() throws Exception {
278
		list.add(delegate.createElement(list));
279
280
		assertChangeEventFired(new Runnable() {
281
			public void run() {
282
				list.remove(0);
283
			}
284
		}, "List.remove(int)", list);
285
	}
286
287
	public void testRemoveAtIndex_ListChangeEvent() throws Exception {
288
		list.add(delegate.createElement(list));
289
290
		assertListChangeEventFired(new Runnable() {
291
			public void run() {
292
				list.remove(0);
293
			}
294
		}, "List.remove(int)", list);
295
	}
296
297
	public void testRemoveAtIndex_ChangeEventFiredAfterElementIsRemoved()
298
			throws Exception {
299
		final Object element = delegate.createElement(list);
300
		list.add(element);
301
302
		assertDoesNotContainDuringChangeEvent(new Runnable() {
303
			public void run() {
304
				list.remove(0);
305
			}
306
		}, "List.remove(int)", list, element);
307
	}
308
309
	public void testRemoveAtIndex_ListDiffEntry() throws Exception {
310
		list.add(delegate.createElement(list));
311
		Object element = delegate.createElement(list);
312
		list.add(element);
313
314
		assertRemoveDiffEntry(new Runnable() {
315
			public void run() {
316
				list.remove(1);
317
			}
318
		}, "List.remove(int)", list, element, 1);
319
	}
320
321
	public void testRemoveAll_ListChangeEvent() throws Exception {
322
		final Object element = delegate.createElement(list);
323
324
		assertListChangeEventFired(new Runnable() {
325
			public void run() {
326
				list.removeAll(Arrays.asList(new Object[] { element }));
327
			}
328
		}, "List.removeAll(Collection)", list);
329
	}
330
331
	public void testRemoveAll_ListDiffEntry() throws Exception {
332
		final Object element = delegate.createElement(list);
333
		list.add(element);
334
335
		assertRemoveDiffEntry(new Runnable() {
336
			public void run() {
337
				list.removeAll(Arrays.asList(new Object[] { element }));
338
			}
339
		}, "List.removeAll(Collection)", list, element, 0);
340
	}
341
342
	public void testRetainAll_ListChangeEvent() throws Exception {
343
		final Object element1 = delegate.createElement(list);
344
		list.add(element1);
345
		list.add(delegate.createElement(list));
346
347
		assertListChangeEventFired(new Runnable() {
348
			public void run() {
349
				list.retainAll(Arrays.asList(new Object[] { element1 }));
350
			}
351
		}, "List.retainAll(Collection", list);
352
	}
353
354
	public void testRetainAll_ListDiffEntry() throws Exception {
355
		final Object element1 = delegate.createElement(list);
356
		list.add(element1);
357
		Object element2 = delegate.createElement(list);
358
		list.add(delegate.createElement(list));
359
360
		assertRemoveDiffEntry(new Runnable() {
361
			public void run() {
362
				list.retainAll(Arrays.asList(new Object[] { element1 }));
363
			}
364
		}, "List.retainAll(Collection)", list, element2, 1);
365
	}
366
367
	public void testClear_ListChangeEvent() throws Exception {
368
		list.add(delegate.createElement(list));
369
370
		assertListChangeEventFired(new Runnable() {
371
			public void run() {
372
				list.clear();
373
			}
374
		}, "List.clear()", list);
375
	}
376
377
	public void testClear_ListDiffEntry() throws Exception {
378
		Object element = delegate.createElement(list);
379
		list.add(element);
380
381
		assertRemoveDiffEntry(new Runnable() {
382
			public void run() {
383
				list.clear();
384
			}
385
		}, "List.clear()", list, element, 0);
386
	}
387
388
	/**
389
	 * Asserts standard behaviors of firing list change events.
390
	 * <ul>
391
	 * <li>Event fires once.</li>
392
	 * <li>Source of the event is the provided <code>list</code>.
393
	 * <li>The list change event is fired after the change event.</li>
394
	 * </ul>
395
	 * 
396
	 * @param runnable
397
	 * @param methodName
398
	 * @param list
399
	 */
400
	private void assertListChangeEventFired(Runnable runnable,
401
			String methodName, IObservableList list) {
402
		List queue = new ArrayList();
403
		ListChangeEventTracker listListener = new ListChangeEventTracker(queue);
404
		ChangeEventTracker changeListener = new ChangeEventTracker(queue);
405
406
		list.addListChangeListener(listListener);
407
		list.addChangeListener(changeListener);
408
409
		runnable.run();
410
411
		assertEquals(formatFail(methodName + " should fire one ListChangeEvent."), 1,
412
				listListener.count);
413
		assertEquals(formatFail(methodName
414
				+ "'s change event observable should be the created List."),
415
				list, listListener.event.getObservable());
416
417
		assertEquals(formatFail("Two notifications should have been received."), 2, queue
418
				.size());
419
		assertEquals("ChangeEvent of " + methodName
420
				+ " should have fired before the ListChangeEvent.",
421
				changeListener, queue.get(0));
422
		assertEquals("ListChangeEvent of " + methodName
423
				+ " should have fired after the ChangeEvent.", listListener,
424
				queue.get(1));
425
	}
426
427
	/**
428
	 * Asserts the list diff entry for a remove operation.
429
	 * 
430
	 * @param runnable
431
	 * @param methodName
432
	 * @param list
433
	 * @param element
434
	 * @param index
435
	 */
436
	private void assertRemoveDiffEntry(Runnable runnable, String methodName,
437
			IObservableList list, Object element, int index) {
438
		ListChangeEventTracker listener = new ListChangeEventTracker();
439
		list.addListChangeListener(listener);
440
441
		runnable.run();
442
443
		ListDiffEntry[] entries = listener.event.diff.getDifferences();
444
		assertEquals(methodName + " should result in one diff entry.", 1,
445
				entries.length);
446
447
		ListDiffEntry entry = entries[0];
448
		assertFalse(methodName
449
				+ " should result in a diff entry that is an removal.", entry
450
				.isAddition());
451
		assertEquals(methodName
452
				+ " remove diff entry should have removed the element.",
453
				element, entry.getElement());
454
		assertEquals(
455
				methodName
456
						+ " remove diff entry should have removed the element from the provided index.",
457
				index, entry.getPosition());
458
	}
459
460
	/**
461
	 * Asserts the list diff entry for an add operation.
462
	 * 
463
	 * @param runnable
464
	 * @param methodName
465
	 * @param list
466
	 * @param element
467
	 * @param index
468
	 */
469
	private void assertAddDiffEntry(Runnable runnable, String methodName,
470
			IObservableList list, Object element, int index) {
471
		ListChangeEventTracker listener = new ListChangeEventTracker();
472
		list.addListChangeListener(listener);
473
474
		runnable.run();
475
476
		ListDiffEntry[] entries = listener.event.diff.getDifferences();
477
		assertEquals(methodName + " should result in one diff entry.", 1,
478
				entries.length);
479
480
		ListDiffEntry entry = entries[0];
481
		assertTrue(methodName
482
				+ " should result in a diff entry that is an addition.", entry
483
				.isAddition());
484
		assertEquals(methodName
485
				+ " add diff entry should have added the element.", element,
486
				entry.getElement());
487
		assertEquals(
488
				methodName
489
						+ "add diff entry should have added the element at the provided index.",
490
				index, entry.getPosition());
491
	}
492
}
(-)src/org/eclipse/jface/conformance/databinding/IObservableValueContractDelegate.java (-56 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.Realm;
15
import org.eclipse.core.databinding.observable.value.IObservableValue;
16
17
/**
18
 * Delegate interface for an observable value.
19
 * 
20
 * <p>
21
 * This interface is not intended to be implemented by clients. Clients should
22
 * instead subclass one of the classes that implement this interface. Note that
23
 * direct implementers of this interface outside of the framework will be broken
24
 * in future releases when methods are added to this interface.
25
 * </p>
26
 * 
27
 * @since 1.1
28
 */
29
public interface IObservableValueContractDelegate extends
30
		IObservableContractDelegate {
31
32
	/**
33
	 * Creates a new observable value.
34
	 * 
35
	 * @param realm
36
	 *            realm of the observable
37
	 * @return observable value
38
	 */
39
	public IObservableValue createObservableValue(Realm realm);
40
41
	/**
42
	 * Returns the expected type of the observable.
43
	 * 
44
	 * @param observable
45
	 * @return type
46
	 */
47
	public Object getValueType(IObservableValue observable);
48
	
49
	/**
50
	 * Returns a valid value that is not the current value of the observable.
51
	 * 
52
	 * @param observable
53
	 * @return value
54
	 */
55
	public Object createValue(IObservableValue observable);
56
}
(-)src/org/eclipse/jface/conformance/databinding/ObservableDelegateTest.java (-106 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import junit.framework.TestCase;
15
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.jface.tests.databinding.RealmTester;
19
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
20
21
/**
22
 * TestCase that provides the standard behavior expected for delegating test cases.
23
 * 
24
 * @since 3.2
25
 */
26
public class ObservableDelegateTest extends TestCase {
27
	private IObservableContractDelegate delegate;
28
29
	private Realm previousRealm;
30
31
	private IObservable observable;
32
	private String debugInfo;
33
34
	public ObservableDelegateTest(IObservableContractDelegate delegate) {
35
		this(null, delegate);
36
	}
37
	
38
	public ObservableDelegateTest(String testName, IObservableContractDelegate delegate) {
39
		super(testName);
40
		this.delegate = delegate;
41
	}
42
43
	protected void setUp() throws Exception {
44
		super.setUp();
45
		previousRealm = Realm.getDefault();
46
47
		delegate.setUp();
48
		observable = doCreateObservable();
49
	}
50
51
	protected void tearDown() throws Exception {
52
		super.tearDown();
53
54
		delegate.tearDown();
55
		observable.dispose();
56
		observable = null;
57
		
58
		RealmTester.setDefault(previousRealm);
59
60
		observable = null;
61
		previousRealm = null;
62
	}
63
	
64
	/**
65
	 * Creates a new observable with a default realm. Invoked from
66
	 * {@link #setUp()}. Override to customize the creation of observables
67
	 * (e.g. specifying a different Realm).
68
	 * 
69
	 * @return observable
70
	 */
71
	protected IObservable doCreateObservable() {
72
		return delegate.createObservable(new CurrentRealm(true));
73
	}
74
75
	/**
76
	 * Returns the created observable. The observable is created in
77
	 * {@link #setUp()}. If invoked before {@link #setUp()} will be
78
	 * <code>null</code>.
79
	 * 
80
	 * @return observable
81
	 */
82
	protected IObservable getObservable() {
83
		return observable;
84
	}	
85
	
86
	/**
87
	 * Returns the delegate in use.
88
	 * 
89
	 * @return delegate
90
	 */
91
	protected IObservableContractDelegate getObservableContractDelegate() {
92
		return delegate;
93
	}
94
	
95
	protected String formatFail(String message) {
96
		return message + getDebugString();
97
	}
98
	
99
	private String getDebugString() {
100
		if (debugInfo == null) {
101
			debugInfo = "(Test: " + this.getClass().getName() + ", Delegate: " + delegate.getClass().getName() + ")";
102
		}
103
		
104
		return debugInfo;
105
	}
106
}
(-)src/org/eclipse/jface/conformance/databinding/ObservableValueContractTest.java (-171 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import java.util.ArrayList;
15
import java.util.List;
16
17
import org.eclipse.core.databinding.observable.ChangeEvent;
18
import org.eclipse.core.databinding.observable.IChangeListener;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
21
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
22
import org.eclipse.jface.tests.databinding.RealmTester;
23
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
24
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
25
26
/**
27
 * @since 3.2
28
 */
29
public class ObservableValueContractTest extends ObservableContractTest {
30
	private IObservableValueContractDelegate delegate;
31
	private IObservableValue observable;
32
33
	public ObservableValueContractTest(IObservableValueContractDelegate delegate) {
34
		super(delegate);
35
		this.delegate = delegate;			
36
	}
37
38
	/**
39
	 * @param testName
40
	 * @param delegate
41
	 */
42
	public ObservableValueContractTest(String testName,
43
			IObservableValueContractDelegate delegate) {
44
		super(testName, delegate);
45
		this.delegate = delegate;
46
	}
47
48
	/*
49
	 * (non-Javadoc)
50
	 * 
51
	 * @see org.eclipse.jface.conformance.databinding.ObservableContractTest#setUp()
52
	 */
53
	protected void setUp() throws Exception {
54
		super.setUp();
55
		observable = (IObservableValue) getObservable();
56
	}
57
58
	public void testChange_ValueChangeEvent() throws Exception {
59
		ValueChangeEventTracker listener = new ValueChangeEventTracker().register(observable);
60
61
		delegate.change(observable);
62
		assertEquals(formatFail("On change value change listeners should be notified."), 1,
63
				listener.count);
64
	}
65
66
	public void testGetValueType_ExpectedType() throws Exception {
67
		assertEquals(formatFail("Type of the value should be returned from getType()."),
68
				delegate.getValueType(observable), observable.getValueType());
69
	}
70
71
	public void testChange_OrderOfNotifications() throws Exception {
72
		final List listeners = new ArrayList();
73
		IChangeListener changeListener = new IChangeListener() {
74
			public void handleChange(ChangeEvent event) {
75
				listeners.add(this);
76
			}
77
		};
78
79
		IValueChangeListener valueChangeListener = new IValueChangeListener() {
80
			public void handleValueChange(ValueChangeEvent event) {
81
				listeners.add(this);
82
			}
83
		};
84
85
		observable.addChangeListener(changeListener);
86
		observable.addValueChangeListener(valueChangeListener);
87
88
		delegate.change(observable);
89
		
90
		assertTrue(formatFail("Change Listeners were not notified on change."), listeners.size() > 0);
91
		
92
		// not asserting the fact that both are notified as this is asserted in
93
		// other tests
94
		assertEquals(
95
				formatFail("Change listeners should be notified before value change listeners."),
96
				changeListener, listeners.get(0));
97
		assertEquals(
98
				formatFail("Value change listeners should be notified after change listeners."),
99
				valueChangeListener, listeners.get(1));
100
	}
101
102
	public void testChange_ValueChangeEventDiff() throws Exception {
103
		ValueChangeEventTracker listener = new ValueChangeEventTracker().register(observable);
104
		Object oldValue = observable.getValue();
105
106
		delegate.change(observable);
107
108
		ValueChangeEvent event = listener.event;
109
		
110
		assertTrue(formatFail("Change Listeners were not notified on change."), listener.count > 0);
111
		
112
		assertEquals(
113
				formatFail("When a value change event is fired the old value should be the previous value of the observable value."),
114
				oldValue, event.diff.getOldValue());
115
		assertEquals(
116
				formatFail("When a value change event is fired the new value should be the same as the current value of the observable value."),
117
				observable.getValue(), event.diff.getNewValue());
118
	}
119
120
	public void testChange_ValueChangeEventFiredAfterValueIsSet()
121
			throws Exception {
122
		class ValueChangeListener extends ValueChangeEventTracker {
123
			Object value;
124
125
			public void handleValueChange(ValueChangeEvent event) {
126
				super.handleValueChange(event);
127
128
				this.value = event.getObservableValue().getValue();
129
			}
130
		}
131
132
		ValueChangeListener listener = (ValueChangeListener) new ValueChangeListener()
133
				.register(observable);
134
		delegate.change(observable);
135
		assertEquals(
136
				formatFail("When a value change event is fired the new value should be applied before firing the change event."),
137
				listener.value, observable.getValue());
138
	}
139
140
	public void testRemoveValueChangeListener_RemovesListener() throws Exception {
141
		ValueChangeEventTracker listener = new ValueChangeEventTracker().register(observable);
142
		delegate.change(observable);
143
144
		// precondition
145
		assertEquals(formatFail("Value change listeners should be notified on change."), 1,
146
				listener.count);
147
148
		observable.removeValueChangeListener(listener);
149
		delegate.change(observable);
150
151
		assertEquals(
152
				formatFail("Value change listeners should not be notified after they've been removed from the observable."),
153
				1, listener.count);
154
	}
155
156
	public void testGetValue_GetterCalled() throws Exception {
157
		assertGetterCalled(new Runnable() {
158
			public void run() {
159
				observable.getValue();
160
			}
161
		}, formatFail("IObservableValue.getValue()"), observable);
162
	}
163
164
	public void testGetValue_RealmCheck() throws Exception {
165
		RealmTester.exerciseCurrent(new Runnable() {
166
			public void run() {
167
				observable.getValue();
168
			}
169
		}, (CurrentRealm) observable.getRealm());
170
	}
171
}
(-)src/org/eclipse/jface/conformance/databinding/MutableObservableSetContractTest.java (-265 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import java.util.ArrayList;
15
import java.util.Arrays;
16
import java.util.List;
17
import java.util.Set;
18
19
import org.eclipse.core.databinding.observable.set.IObservableSet;
20
import org.eclipse.jface.tests.databinding.EventTrackers.ChangeEventTracker;
21
import org.eclipse.jface.tests.databinding.EventTrackers.SetChangeEventTracker;
22
23
/**
24
 */
25
public class MutableObservableSetContractTest extends
26
		MutableObservableCollectionContractTest {
27
	private IObservableCollectionContractDelegate delegate;
28
29
	private IObservableSet set;
30
31
	public MutableObservableSetContractTest(String testName,
32
			IObservableCollectionContractDelegate delegate) {
33
		super(testName, delegate);
34
		this.delegate = delegate;
35
	}
36
37
	/**
38
	 * @param delegate
39
	 */
40
	public MutableObservableSetContractTest(
41
			IObservableCollectionContractDelegate delegate) {
42
		super(delegate);
43
	}
44
45
	protected void setUp() throws Exception {
46
		super.setUp();
47
		set = (IObservableSet) getObservable();
48
	}
49
50
	public void testAdd_SetChangeEvent() throws Exception {
51
		assertSetChangeEventFired(new Runnable() {
52
			public void run() {
53
				set.add(delegate.createElement(set));
54
			}
55
		}, "Set.add(Object)", set);
56
	}
57
58
	public void testAdd_SetDiffEntry() throws Exception {
59
		set.add(delegate.createElement(set));
60
		final Object element = delegate.createElement(set);
61
62
		assertAddDiffEntry(new Runnable() {
63
			public void run() {
64
				set.add(element);
65
			}
66
		}, "Set.add(Object)", set, element);
67
	}
68
69
	public void testAddAll_SetChangeEvent() throws Exception {
70
		assertSetChangeEventFired(new Runnable() {
71
			public void run() {
72
				set.addAll(Arrays.asList(new Object[] { delegate
73
						.createElement(set) }));
74
			}
75
		}, "Set.addAll(Collection", set);
76
	}
77
78
	public void testAddAll_SetDiffEntry() throws Exception {
79
		final Object element = delegate.createElement(set);
80
81
		assertAddDiffEntry(new Runnable() {
82
			public void run() {
83
				set.addAll(Arrays.asList(new Object[] { element }));
84
			}
85
		}, "Set.addAll(Collection)", set, element);
86
	}
87
88
	public void testRemove_SetChangeEvent() throws Exception {
89
		final Object element = delegate.createElement(set);
90
		set.add(element);
91
92
		assertSetChangeEventFired(new Runnable() {
93
			public void run() {
94
				set.remove(element);
95
			}
96
		}, "Set.remove(Object)", set);
97
	}
98
99
	public void testRemove_SetDiffEntry() throws Exception {
100
		set.add(delegate.createElement(set));
101
		final Object element = delegate.createElement(set);
102
		set.add(element);
103
104
		assertRemoveDiffEntry(new Runnable() {
105
			public void run() {
106
				set.remove(element);
107
			}
108
		}, "Set.remove(Object)", set, element);
109
	}
110
111
	public void testRemoveAll_SetChangeEvent() throws Exception {
112
		final Object element = delegate.createElement(set);
113
		set.add(element);
114
115
		assertSetChangeEventFired(new Runnable() {
116
			public void run() {
117
				set.removeAll(Arrays.asList(new Object[] { element }));
118
			}
119
		}, "Set.removeAll(Collection)", set);
120
	}
121
122
	public void testRemoveAll_SetDiffEntry() throws Exception {
123
		final Object element = delegate.createElement(set);
124
		set.add(element);
125
126
		assertRemoveDiffEntry(new Runnable() {
127
			public void run() {
128
				set.removeAll(Arrays.asList(new Object[] { element }));
129
			}
130
		}, "Set.removeAll(Collection)", set, element);
131
	}
132
133
	public void testRetainAll_SetChangeEvent() throws Exception {
134
		final Object element1 = delegate.createElement(set);
135
		set.add(element1);
136
		set.add(delegate.createElement(set));
137
138
		assertSetChangeEventFired(new Runnable() {
139
			public void run() {
140
				set.retainAll(Arrays.asList(new Object[] { element1 }));
141
			}
142
		}, "Set.retainAll(Collection", set);
143
	}
144
145
	public void testRetainAll_SetDiffEntry() throws Exception {
146
		final Object element1 = delegate.createElement(set);
147
		set.add(element1);
148
		Object element2 = delegate.createElement(set);
149
		set.add(delegate.createElement(set));
150
151
		assertRemoveDiffEntry(new Runnable() {
152
			public void run() {
153
				set.retainAll(Arrays.asList(new Object[] { element1 }));
154
			}
155
		}, "Set.retainAll(Collection)", set, element2);
156
	}
157
158
	public void testClear_SetChangeEvent() throws Exception {
159
		set.add(delegate.createElement(set));
160
161
		assertSetChangeEventFired(new Runnable() {
162
			public void run() {
163
				set.clear();
164
			}
165
		}, "Set.clear()", set);
166
	}
167
168
	public void testClear_SetDiffEntry() throws Exception {
169
		Object element = delegate.createElement(set);
170
		set.add(element);
171
172
		assertRemoveDiffEntry(new Runnable() {
173
			public void run() {
174
				set.clear();
175
			}
176
		}, "Set.clear()", set, element);
177
	}
178
179
	/**
180
	 * Asserts standard behaviors of firing set change events.
181
	 * <ul>
182
	 * <li>Event fires once.</li>
183
	 * <li>Source of the event is the provided <code>set</code>.
184
	 * <li>The set change event is fired after the change event.</li>
185
	 * </ul>
186
	 * 
187
	 * @param runnable
188
	 * @param methodName
189
	 * @param set
190
	 */
191
	private void assertSetChangeEventFired(Runnable runnable,
192
			String methodName, IObservableSet set) {
193
		List queue = new ArrayList();
194
		SetChangeEventTracker setListener = new SetChangeEventTracker(queue);
195
		ChangeEventTracker changeListener = new ChangeEventTracker(queue);
196
197
		set.addSetChangeListener(setListener);
198
		set.addChangeListener(changeListener);
199
200
		runnable.run();
201
202
		assertEquals(formatFail(methodName + " should fire one SetChangeEvent."), 1,
203
				setListener.count);
204
		assertEquals(formatFail(methodName
205
				+ "'s change event observable should be the created Set."), set,
206
				setListener.event.getObservable());
207
208
		assertEquals(formatFail("Two notifications should have been received."), 2, queue
209
				.size());
210
		assertEquals(formatFail("ChangeEvent of " + methodName
211
				+ " should have fired before the SetChangeEvent."),
212
				changeListener, queue.get(0));
213
		assertEquals(formatFail("SetChangeEvent of " + methodName
214
				+ " should have fired after the ChangeEvent."), setListener,
215
				queue.get(1));
216
	}
217
218
	/**
219
	 * Asserts the set diff entry for an add operation.
220
	 * 
221
	 * @param runnable
222
	 * @param methodName
223
	 * @param set
224
	 * @param element
225
	 */
226
	private void assertAddDiffEntry(Runnable runnable, String methodName,
227
			IObservableSet set, Object element) {
228
		SetChangeEventTracker listener = new SetChangeEventTracker();
229
		set.addSetChangeListener(listener);
230
231
		runnable.run();
232
233
		Set entries = listener.event.diff.getAdditions();
234
		assertEquals(formatFail(methodName + " should result in one diff entry."), 1,
235
				entries.size());
236
237
		assertTrue(formatFail(methodName
238
				+ " should result in a diff entry that is an addition."),
239
				entries.contains(element));
240
	}
241
242
	/**
243
	 * Asserts the set diff entry for a remove operation.
244
	 * 
245
	 * @param runnable
246
	 * @param methodName
247
	 * @param set
248
	 * @param element
249
	 */
250
	private void assertRemoveDiffEntry(Runnable runnable, String methodName,
251
			IObservableSet set, Object element) {
252
		SetChangeEventTracker listener = new SetChangeEventTracker();
253
		set.addSetChangeListener(listener);
254
255
		runnable.run();
256
257
		Set entries = listener.event.diff.getRemovals();
258
		assertEquals(formatFail(methodName + " should result in one diff entry."), 1,
259
				entries.size());
260
261
		assertTrue(formatFail(methodName
262
				+ " should result in a diff entry that is an addition."),
263
				entries.contains(element));
264
	}
265
}
(-)src/org/eclipse/jface/conformance/databinding/SWTMutableObservableValueContractTest.java (-65 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.jface.databinding.swt.SWTObservables;
16
import org.eclipse.jface.tests.databinding.RealmTester.DelegatingRealm;
17
import org.eclipse.swt.widgets.Display;
18
19
/**
20
 * Mutability tests for IObservableValue for a SWT widget.
21
 * 
22
 * <p>
23
 * This class is experimental and can change at any time. It is recommended to
24
 * not subclass or assume the test names will not change. The only API that is
25
 * guaranteed to not change are the constructors. The tests will remain public
26
 * and not final in order to allow for consumers to turn off a test if needed by
27
 * subclassing.
28
 * </p>
29
 * 
30
 * @since 3.2
31
 */
32
public class SWTMutableObservableValueContractTest extends
33
		MutableObservableValueContractTest {
34
	private IObservableValueContractDelegate delegate;
35
36
	public SWTMutableObservableValueContractTest(
37
			IObservableValueContractDelegate delegate) {
38
		this(null, delegate);
39
	}
40
41
	/**
42
	 * @param testName
43
	 * @param delegate
44
	 */
45
	public SWTMutableObservableValueContractTest(String testName,
46
			IObservableValueContractDelegate delegate) {
47
		super(testName, delegate);
48
		this.delegate = delegate;
49
	}
50
51
	/**
52
	 * Creates a new observable passing the realm for the current display.
53
	 */
54
	protected IObservable doCreateObservable() {
55
		Display display = Display.getCurrent();
56
		if (display == null) {
57
			display = new Display();
58
		}
59
		DelegatingRealm delegateRealm = new DelegatingRealm(SWTObservables
60
				.getRealm(display));
61
		delegateRealm.setCurrent(true);
62
63
		return delegate.createObservable(delegateRealm);
64
	}
65
}
(-)src/org/eclipse/jface/conformance/databinding/ObservableCollectionContractTest.java (-207 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import java.util.Arrays;
15
16
import org.eclipse.core.databinding.observable.IObservableCollection;
17
import org.eclipse.jface.tests.databinding.RealmTester;
18
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
19
20
/**
21
 * Tests for IObservableCollection that don't mutate the collection.
22
 * <p>
23
 * This class is experimental and can change at any time. It is recommended to
24
 * not subclass or assume the test names will not change. The only API that is
25
 * guaranteed to not change are the constructors. The tests will remain public
26
 * and not final in order to allow for consumers to turn off a test if needed by
27
 * subclassing.
28
 * </p>
29
 * 
30
 * @since 3.2
31
 */
32
public class ObservableCollectionContractTest extends ObservableContractTest {
33
	private IObservableCollectionContractDelegate delegate;
34
35
	private IObservableCollection collection;
36
37
	public ObservableCollectionContractTest(
38
			IObservableCollectionContractDelegate delegate) {
39
		super(delegate);
40
		this.delegate = delegate;
41
	}
42
43
	public ObservableCollectionContractTest(String testName,
44
			IObservableCollectionContractDelegate delegate) {
45
		super(testName, delegate);
46
		this.delegate = delegate;
47
	}
48
49
	protected void setUp() throws Exception {
50
		super.setUp();
51
		
52
		collection = (IObservableCollection) getObservable();
53
	}
54
55
	public void testIterator_GetterCalled() throws Exception {
56
		assertGetterCalled(new Runnable() {
57
			public void run() {
58
				collection.iterator();
59
			}
60
		}, "Collection.iterator()", collection);
61
	}
62
	
63
	public void testIterator_RealmCheck() throws Exception {
64
		RealmTester.exerciseCurrent(new Runnable() {
65
			public void run() {
66
				collection.iterator();
67
			}
68
		}, (CurrentRealm) collection.getRealm());
69
	}
70
71
	public void testSize_GetterCalled() throws Exception {
72
		assertGetterCalled(new Runnable() {
73
			public void run() {
74
				collection.size();
75
			}
76
		}, "Collection.size()", collection);
77
	}
78
	
79
	public void testSize_RealmCheck() throws Exception {
80
		RealmTester.exerciseCurrent(new Runnable() {
81
			public void run() {
82
				collection.size();
83
			}
84
		}, (CurrentRealm) collection.getRealm());
85
	}
86
87
	public void testIsEmpty_GetterCalled() throws Exception {
88
		assertGetterCalled(new Runnable() {
89
			public void run() {
90
				collection.isEmpty();
91
			}
92
		}, "Collection.isEmpty()", collection);
93
	}
94
	
95
	public void testIsEmpty_RealmCheck() throws Exception {
96
		RealmTester.exerciseCurrent(new Runnable() {
97
			public void run() {
98
				collection.isEmpty();
99
			}
100
		}, (CurrentRealm) collection.getRealm());
101
	}
102
103
	public void testContains_GetterCalled() throws Exception {
104
		assertGetterCalled(new Runnable() {
105
			public void run() {
106
				collection.contains(delegate.createElement(collection));
107
			}
108
		}, "Collection.contains(...)", collection);
109
	}
110
	
111
	public void testContains_RealmCheck() throws Exception {
112
		RealmTester.exerciseCurrent(new Runnable() {
113
			public void run() {
114
				collection.contains(delegate.createElement(collection));
115
			}
116
		}, (CurrentRealm) collection.getRealm());
117
	}
118
119
	public void testContainsAll_GetterCalled() throws Exception {
120
		assertGetterCalled(new Runnable() {
121
			public void run() {
122
				collection.containsAll(Arrays.asList(new Object[] { delegate
123
						.createElement(collection) }));
124
			}
125
		}, "Collection.containsAll(Collection)", collection);
126
	}
127
128
	public void testContainsAll_RealmCheck() throws Exception {
129
		RealmTester.exerciseCurrent(new Runnable() {
130
			public void run() {
131
				collection.containsAll(Arrays.asList(new Object[] { delegate
132
						.createElement(collection) }));
133
			}
134
		}, (CurrentRealm) collection.getRealm());
135
	}
136
	
137
	public void testToArray_GetterCalled() throws Exception {
138
		assertGetterCalled(new Runnable() {
139
			public void run() {
140
				collection.toArray();
141
			}
142
		}, "Collection.toArray()", collection);
143
	}
144
	
145
	public void testToArray_RealmCheck() throws Exception {
146
		RealmTester.exerciseCurrent(new Runnable() {
147
			public void run() {
148
				collection.toArray();
149
			}
150
		}, (CurrentRealm) collection.getRealm());
151
	}
152
153
	public void testToArrayWithObjectArray_GetterCalled() throws Exception {
154
		assertGetterCalled(new Runnable() {
155
			public void run() {
156
				collection.toArray(new Object[collection.size()]);
157
			}
158
		}, "Collection.toArray(Object[])", collection);
159
	}
160
	
161
	public void testToArrayWithObjectArray_RealmCheck() throws Exception {
162
		RealmTester.exerciseCurrent(new Runnable() {
163
			public void run() {
164
				collection.toArray(new Object[collection.size()]);
165
			}
166
		}, (CurrentRealm) collection.getRealm());
167
	}
168
169
	public void testEquals_GetterCalled() throws Exception {
170
		assertGetterCalled(new Runnable() {
171
			public void run() {
172
				collection.equals(collection);
173
			}
174
		}, "Collection.equals(Object)", collection);
175
	}
176
	
177
	public void testEquals_RealmCheck() throws Exception {
178
		RealmTester.exerciseCurrent(new Runnable() {
179
			public void run() {
180
				collection.equals(collection);
181
			}
182
		}, (CurrentRealm) collection.getRealm());
183
	}
184
185
	public void testHashCode_GetterCalled() throws Exception {
186
		assertGetterCalled(new Runnable() {
187
			public void run() {
188
				collection.hashCode();
189
			}
190
		}, "Collection.hashCode()", collection);
191
	}
192
	
193
	public void testHashCode_RealmCheck() throws Exception {
194
		RealmTester.exerciseCurrent(new Runnable() {
195
			public void run() {
196
				collection.hashCode();
197
			}
198
		}, (CurrentRealm) collection.getRealm());
199
	}
200
201
	public void testGetElementType_ReturnsType() throws Exception {
202
		assertEquals(
203
				"Element type of the collection should be returned from IObservableCollection.getElementType()",
204
				delegate.getElementType(collection), collection
205
						.getElementType());
206
	}
207
}
(-)src/org/eclipse/jface/conformance/databinding/AbstractObservableCollectionContractDelegate.java (-43 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.core.databinding.observable.IObservableCollection;
16
import org.eclipse.core.databinding.observable.Realm;
17
18
/**
19
 * Abstract implementation of {@link IObservableCollectionContractDelegate}.
20
 * 
21
 * @since 3.2
22
 */
23
public abstract class AbstractObservableCollectionContractDelegate extends
24
		AbstractObservableContractDelegate implements
25
		IObservableCollectionContractDelegate {
26
27
	/**
28
	 * Invokes {@link #createObservableCollection(Realm, elementCount)}.
29
	 */
30
	public final IObservable createObservable(Realm realm) {
31
		return createObservableCollection(realm, 0);
32
	}
33
	
34
	public Object createElement(IObservableCollection collection) {
35
		//no op
36
		return null;
37
	}
38
39
	public Object getElementType(IObservableCollection collection) {
40
		//no op
41
		return null;
42
	}
43
}
(-)src/org/eclipse/jface/conformance/databinding/ObservableContractTest.java (-174 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.ChangeEvent;
15
import org.eclipse.core.databinding.observable.IChangeListener;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.ObservableTracker;
18
import org.eclipse.jface.tests.databinding.RealmTester;
19
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
20
21
/**
22
 * Tests for IObservable that don't require mutating the observable.
23
 * <p>
24
 * This class is experimental and can change at any time. It is recommended to
25
 * not subclass or assume the test names will not change. The only API that is
26
 * guaranteed to not change are the constructors. The tests will remain public
27
 * and not final in order to allow for consumers to turn off a test if needed by
28
 * subclassing.
29
 * </p>
30
 * 
31
 * @since 3.2
32
 */
33
public class ObservableContractTest extends ObservableDelegateTest {
34
	private IObservable observable;
35
36
	private IObservableContractDelegate delegate;
37
38
	public ObservableContractTest(IObservableContractDelegate delegate) {
39
		this(null, delegate);
40
	}
41
42
	public ObservableContractTest(String testName,
43
			IObservableContractDelegate delegate) {
44
		super(testName, delegate);
45
		
46
		this.delegate = delegate;
47
	}
48
49
	protected void setUp() throws Exception {
50
		super.setUp();
51
		observable = getObservable();
52
	}
53
54
	public void testGetRealm_NotNull() throws Exception {
55
		assertNotNull(formatFail("The observable's realm should not be null."), observable
56
				.getRealm());
57
	}
58
59
	public void testChange_ChangeEvent() throws Exception {
60
		ChangeListener listener = new ChangeListener();
61
62
		observable.addChangeListener(listener);
63
		delegate.change(observable);
64
65
		assertEquals(
66
				formatFail("A change in the observable should notify change listeners."),
67
				listener.count, 1);
68
	}
69
70
	public void testChange_EventObservable() throws Exception {
71
		ChangeListener listener = new ChangeListener();
72
73
		observable.addChangeListener(listener);
74
		delegate.change(observable);
75
76
		ChangeEvent event = listener.event;
77
		assertNotNull(formatFail("change event was null"), event);
78
79
		assertSame(
80
				formatFail("In the change event the source of the change should be the observable."),
81
				observable, event.getObservable());
82
	}
83
84
	public void testChange_RealmCheck() throws Exception {
85
		RealmTester.exerciseCurrent(new Runnable() {
86
			public void run() {
87
				delegate.change(observable);
88
			}			
89
		}, (CurrentRealm) observable.getRealm());
90
	}
91
	
92
	public void testChange_ObservableRealmIsTheCurrentRealm() throws Exception {
93
		ChangeListener listener = new ChangeListener();
94
		observable.addChangeListener(listener);
95
96
		delegate.change(observable);
97
		assertTrue(
98
				formatFail("On change the current realm should be the realm of the observable."),
99
				listener.isCurrentRealm);
100
	}
101
102
	public void testRemoveChangeListener_RemovesListener() throws Exception {
103
		ChangeListener listener = new ChangeListener();
104
105
		observable.addChangeListener(listener);
106
		delegate.change(observable);
107
108
		// precondition check
109
		assertEquals(formatFail("change did not notify listeners"), 1, listener.count);
110
111
		observable.removeChangeListener(listener);
112
		delegate.change(observable);
113
114
		assertEquals(
115
				formatFail("When a change listener is removed it should not still receive change events."),
116
				1, listener.count);
117
	}
118
119
	public void testIsStale_NotStale() throws Exception {
120
		delegate.setStale(observable, false);
121
		assertFalse(
122
				formatFail("When an observable is not stale isStale() should return false."),
123
				observable.isStale());
124
	}
125
	
126
	public void testIsStale_RealmChecks() throws Exception {
127
		RealmTester.exerciseCurrent(new Runnable() {
128
			public void run() {
129
				delegate.change(observable);
130
			}			
131
		}, (CurrentRealm) observable.getRealm());
132
	}
133
134
	/**
135
	 * Asserts that ObservableTracker.getterCalled(...) is invoked when the
136
	 * provided <code>runnable</code> is invoked.
137
	 * 
138
	 * @param runnable
139
	 * @param methodName
140
	 *            method name to display when displaying a message
141
	 * @param observable
142
	 *            observable that should be collected by ObservableTracker
143
	 */
144
	protected void assertGetterCalled(Runnable runnable,
145
			String methodName, IObservable observable) {
146
		IObservable[] observables = ObservableTracker.runAndMonitor(runnable,
147
				null, null);
148
149
		int count = 0;
150
		for (int i = 0; i < observables.length; i++) {
151
			if (observables[i] == observable) {
152
				count++;
153
			}
154
		}
155
		
156
		assertEquals(formatFail(methodName
157
				+ " should invoke ObservableTracker.getterCalled() once."), 1,
158
				count);
159
	}
160
	
161
	/* package */static class ChangeListener implements IChangeListener {
162
		int count;
163
164
		ChangeEvent event;
165
166
		boolean isCurrentRealm;
167
168
		public void handleChange(ChangeEvent event) {
169
			count++;
170
			this.event = event;
171
			this.isCurrentRealm = event.getObservable().getRealm().isCurrent();
172
		}
173
	}
174
}
(-)src/org/eclipse/jface/conformance/databinding/MutableObservableCollectionContractTest.java (-359 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import java.util.Arrays;
15
import java.util.Collections;
16
17
import org.eclipse.core.databinding.observable.ChangeEvent;
18
import org.eclipse.core.databinding.observable.IChangeListener;
19
import org.eclipse.core.databinding.observable.IObservableCollection;
20
import org.eclipse.jface.tests.databinding.RealmTester;
21
import org.eclipse.jface.tests.databinding.EventTrackers.ChangeEventTracker;
22
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
23
24
/**
25
 * Mutability tests for IObservableCollection.
26
 * <p>
27
 * This class is experimental and can change at any time. It is recommended to
28
 * not subclass or assume the test names will not change. The only API that is
29
 * guaranteed to not change are the constructors. The tests will remain public
30
 * and not final in order to allow for consumers to turn off a test if needed by
31
 * subclassing.
32
 * </p>
33
 * 
34
 * @since 3.2
35
 */
36
public class MutableObservableCollectionContractTest extends ObservableDelegateTest {
37
	private IObservableCollectionContractDelegate delegate;
38
39
	private IObservableCollection collection;
40
41
	public MutableObservableCollectionContractTest(
42
			IObservableCollectionContractDelegate delegate) {
43
		super(delegate);
44
		this.delegate = delegate;
45
	}
46
47
	public MutableObservableCollectionContractTest(String name,
48
			IObservableCollectionContractDelegate delegate) {
49
		super(name, delegate);
50
		this.delegate = delegate;
51
	}
52
53
	protected void setUp() throws Exception {
54
		super.setUp();
55
56
		collection = (IObservableCollection) super.getObservable();
57
	}
58
59
	public void testAdd_ChangeEvent() throws Exception {
60
		assertChangeEventFired(new Runnable() {
61
			public void run() {
62
				collection.add(delegate.createElement(collection));
63
			}
64
		}, "Collection.add(Object)", collection);
65
	}
66
	
67
	public void testAdd_RealmCheck() throws Exception {
68
		RealmTester.exerciseCurrent(new Runnable() {
69
			public void run() {
70
				collection.add(delegate.createElement(collection));
71
			}
72
		}, (CurrentRealm) collection.getRealm());
73
	}
74
75
	public void testAdd_ChangeEventFiredAfterElementIsAdded() throws Exception {
76
		final Object element = delegate.createElement(collection);
77
78
		assertContainsDuringChangeEvent(new Runnable() {
79
			public void run() {
80
				collection.add(element);
81
			}
82
		}, "Collection.add(Object)", collection, element);
83
	}
84
85
	public void testAddAll_ChangeEvent() throws Exception {
86
		assertChangeEventFired(new Runnable() {
87
			public void run() {
88
				collection.addAll(Arrays.asList(new Object[] { delegate
89
						.createElement(collection) }));
90
			}
91
		}, "Collection.addAll(Collection)", collection);
92
	}
93
	
94
	public void testAddAll_RealmCheck() throws Exception {
95
		RealmTester.exerciseCurrent(new Runnable() {
96
			public void run() {
97
				collection.addAll(Arrays.asList(new Object[] { delegate
98
						.createElement(collection) }));
99
			}
100
		}, (CurrentRealm) collection.getRealm());
101
	}
102
103
	public void testAddAll_ChangeEventFiredAfterElementsAreAdded()
104
			throws Exception {
105
		final Object element = delegate.createElement(collection);
106
107
		assertContainsDuringChangeEvent(new Runnable() {
108
			public void run() {
109
				collection.addAll(Arrays.asList(new Object[] { element }));
110
			}
111
		}, "Collection.addAll(Collection)", collection, element);
112
	}
113
114
	public void testRemove_ChangeEvent() throws Exception {
115
		final Object element = delegate.createElement(collection);
116
		collection.add(element);
117
118
		assertChangeEventFired(new Runnable() {
119
			public void run() {
120
				collection.remove(element);
121
			}
122
		}, "Collection.remove(Object)", collection);
123
	}
124
	
125
	public void testRemove_RealmCheck() throws Exception {
126
		RealmTester.exerciseCurrent(new Runnable() {
127
			public void run() {
128
				collection.remove(delegate.createElement(collection));
129
			}
130
		}, (CurrentRealm) collection.getRealm());
131
	}
132
133
	public void testRemove_ChangeEventFiredAfterElementIsRemoved()
134
			throws Exception {
135
		final Object element = delegate.createElement(collection);
136
		collection.add(element);
137
138
		assertDoesNotContainDuringChangeEvent(new Runnable() {
139
			public void run() {
140
				collection.remove(element);
141
			}
142
		}, "Collection.remove(Object)", collection, element);
143
	}
144
145
	public void testRemoveAll_ChangeEvent() throws Exception {
146
		final Object element = delegate.createElement(collection);
147
		collection.add(element);
148
149
		assertChangeEventFired(new Runnable() {
150
			public void run() {
151
				collection.removeAll(Arrays.asList(new Object[] { element }));
152
			}
153
		}, "Collection.removeAll(Collection)", collection);
154
	}
155
	
156
	public void testRemoveAll_RealmCheck() throws Exception {
157
		RealmTester.exerciseCurrent(new Runnable() {
158
			public void run() {
159
				collection.removeAll(Arrays.asList(new Object[] { delegate.createElement(collection) }));
160
			}
161
		}, (CurrentRealm) collection.getRealm());
162
	}
163
164
	public void testRemoveAll_ChangeEventFiredAfterElementsAreRemoved()
165
			throws Exception {
166
		final Object element = delegate.createElement(collection);
167
		collection.add(element);
168
169
		assertDoesNotContainDuringChangeEvent(new Runnable() {
170
			public void run() {
171
				collection.removeAll(Arrays.asList(new Object[] { element }));
172
			}
173
		}, "Collection.removeAll(Collection)", collection, element);
174
	}
175
176
	public void testRetainAll_ChangeEvent() throws Exception {
177
		final Object element1 = delegate.createElement(collection);
178
		collection.add(element1);
179
		Object element2 = delegate.createElement(collection);
180
		collection.add(element2);
181
182
		assertChangeEventFired(new Runnable() {
183
			public void run() {
184
				collection.retainAll(Arrays.asList(new Object[] { element1 }));
185
			}
186
187
		}, "Collection.retainAll(Collection)", collection);
188
	}
189
	
190
	public void testRetainAll_RealmCheck() throws Exception {
191
		RealmTester.exerciseCurrent(new Runnable() {
192
			public void run() {
193
				collection.retainAll(Collections.EMPTY_LIST);
194
			}
195
		}, (CurrentRealm) collection.getRealm());
196
	}
197
198
	public void testRetainAll_ChangeEventFiredAfterElementsAreRetained()
199
			throws Exception {
200
		Object element1 = delegate.createElement(collection);
201
		collection.add(element1);
202
		Object element2 = delegate.createElement(collection);
203
		collection.add(element2);
204
205
		// precondition
206
		assertTrue(collection.contains(element1));
207
		assertTrue(collection.contains(element2));
208
209
		ContainsListener listener1 = new ContainsListener(collection, element1)
210
				.init();
211
		ContainsListener listener2 = new ContainsListener(collection, element2)
212
				.init();
213
214
		// set contains the the opposite of the expected outcome to ensure they
215
		// get set
216
		listener1.contains = false;
217
		listener2.contains = true;
218
219
		collection.retainAll(Arrays.asList(new Object[] { element1 }));
220
		assertTrue(
221
				formatFail("When Collection.retainAll(...) fires the change event the element should have been retained in the Collection."),
222
				listener1.contains);
223
		assertFalse(
224
				formatFail("When Collection.retainAll(...) fires the change event the element should have been removed from the Collection."),
225
				listener2.contains);
226
	}
227
	
228
	public void testClear_ChangeEvent() throws Exception {
229
		collection.add(delegate.createElement(collection));
230
231
		assertChangeEventFired(new Runnable() {
232
			public void run() {
233
				collection.clear();
234
			}
235
		}, "List.clear()", collection);
236
	}
237
238
	public void testClear_RealmCheck() throws Exception {
239
		RealmTester.exerciseCurrent(new Runnable() {
240
			public void run() {
241
				collection.clear();
242
			}
243
		}, (CurrentRealm) collection.getRealm());
244
	}
245
246
	public void testClear_ChangeEventFiredAfterElementIsRemoved()
247
			throws Exception {
248
		Object element = delegate.createElement(collection);
249
		collection.add(element);
250
251
		assertDoesNotContainDuringChangeEvent(new Runnable() {
252
			public void run() {
253
				collection.clear();
254
			}
255
		}, "List.clear()", collection, element);
256
	}
257
258
	/**
259
	 * Asserts that a ChangeEvent is fired once when the provided
260
	 * <code>runnable</code> is invoked and the source is the provided
261
	 * <code>collection</code>.
262
	 * 
263
	 * @param runnable
264
	 * @param methodName
265
	 * @param collection
266
	 */
267
	/* package */void assertChangeEventFired(Runnable runnable,
268
			String methodName, IObservableCollection collection) {
269
		ChangeEventTracker listener = new ChangeEventTracker();
270
		collection.addChangeListener(listener);
271
		runnable.run();
272
273
		assertEquals(formatFail(methodName + " should fire one ChangeEvent."), 1,
274
				listener.count);
275
		assertEquals(
276
				formatFail(methodName
277
						+ "'s change event observable should be the created Collection."),
278
				collection, listener.event.getObservable());
279
	}
280
281
	/**
282
	 * Asserts that when the change event is fired for the action contained in
283
	 * the <code>runnable</code> the change will have been applied to the
284
	 * <code>collection</code>.
285
	 * 
286
	 * @param runnable
287
	 * @param methodName
288
	 * @param collection
289
	 * @param elementContained
290
	 */
291
	/* package */void assertDoesNotContainDuringChangeEvent(Runnable runnable,
292
			String methodName, IObservableCollection collection,
293
			Object elementNotContained) {
294
295
		// precondition
296
		assertTrue(collection.contains(elementNotContained));
297
298
		ContainsListener listener = new ContainsListener(collection,
299
				elementNotContained).init();
300
		listener.contains = true;
301
		collection.remove(elementNotContained);
302
		assertFalse(
303
				formatFail(new StringBuffer("When ")
304
						.append(methodName)
305
						.append(
306
								" fires a change event the element should have been removed from the Collection.")
307
						.toString()), listener.contains);
308
	}
309
310
	/**
311
	 * Asserts that when the change event is fired for the action contained in
312
	 * the <code>runnable</code> the change will have been applied to the
313
	 * <code>collection</code>.
314
	 * 
315
	 * @param runnable
316
	 * @param methodName
317
	 * @param collection
318
	 * @param elementContained
319
	 */
320
	/* package */void assertContainsDuringChangeEvent(Runnable runnable,
321
			String methodName, IObservableCollection collection,
322
			Object elementContained) {
323
		ContainsListener listener = new ContainsListener(collection,
324
				elementContained).init();
325
326
		// precondition
327
		assertFalse(collection.contains(elementContained));
328
		runnable.run();
329
330
		assertTrue(
331
				formatFail(new StringBuffer("When ")
332
						.append(methodName)
333
						.append(
334
								" fires a change event the element should have been added to the Collection.")
335
						.toString()), listener.contains);
336
	}
337
338
	/* package */static class ContainsListener implements IChangeListener {
339
		boolean contains;
340
341
		final private Object element;
342
343
		final private IObservableCollection collection;
344
345
		ContainsListener(IObservableCollection collection, Object element) {
346
			this.element = element;
347
			this.collection = collection;
348
		}
349
350
		ContainsListener init() {
351
			collection.addChangeListener(this);
352
			return this;
353
		}
354
355
		public void handleChange(ChangeEvent event) {
356
			contains = collection.contains(element);
357
		}
358
	}
359
}
(-)src/org/eclipse/jface/conformance/databinding/IObservableCollectionContractDelegate.java (-60 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.IObservableCollection;
15
import org.eclipse.core.databinding.observable.Realm;
16
17
/**
18
 * Delegate interface for an IObservableCollection.
19
 * 
20
 * <p>
21
 * This interface is not intended to be implemented by clients. Clients should
22
 * instead subclass one of the classes that implement this interface. Note that
23
 * direct implementers of this interface outside of the framework will be broken
24
 * in future releases when methods are added to this interface.
25
 * </p>
26
 * 
27
 * @since 1.1
28
 */
29
public interface IObservableCollectionContractDelegate extends
30
		IObservableContractDelegate {
31
	/**
32
	 * Creates a new observable collection with the provided
33
	 * <code>elementCount</code>.
34
	 * 
35
	 * @param realm realm of the collection
36
	 * @param elementCount
37
	 *            number of elements to initialize the collection with
38
	 * 
39
	 * @return new observable collection
40
	 */
41
	public IObservableCollection createObservableCollection(Realm realm, int elementCount);
42
43
	/**
44
	 * Creates a new element of the appropriate type for the provided
45
	 * <code>collection</code>. This element will be employed to assert the
46
	 * addition and removal of elements in the collection.
47
	 * 
48
	 * @param collection
49
	 * @return valid element for the collection
50
	 */
51
	public Object createElement(IObservableCollection collection);
52
53
	/**
54
	 * Returns the expected type of the elements in the collection.
55
	 * 
56
	 * @param collection
57
	 * @return element type
58
	 */
59
	public Object getElementType(IObservableCollection collection);
60
}
(-)src/org/eclipse/jface/conformance/databinding/IObservableContractDelegate.java (-64 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.core.databinding.observable.Realm;
16
17
/**
18
 * Delegate interface for observables.
19
 * 
20
 * <p>
21
 * This interface is not intended to be implemented by clients. Clients should
22
 * instead subclass one of the classes that implement this interface. Note that
23
 * direct implementers of this interface outside of the framework will be broken
24
 * in future releases when methods are added to this interface.
25
 * </p>
26
 * 
27
 * @since 1.1
28
 */
29
public interface IObservableContractDelegate {
30
	/**
31
	 * Notifies the delegate of the start of a test.
32
	 */
33
	public void setUp();
34
35
	/**
36
	 * Notifies the delegate of the end of a test.
37
	 */
38
	public void tearDown();
39
40
	/**
41
	 * Invokes an operation to set the stale state of the provided
42
	 * <code>observable</code>.
43
	 * 
44
	 * @param observable
45
	 * @param stale
46
	 */
47
	public void setStale(IObservable observable, boolean stale);
48
49
	/**
50
	 * Creates a new observable.
51
	 * 
52
	 * @param realm realm of the observable
53
	 * @return observable
54
	 */
55
	public IObservable createObservable(Realm realm);
56
57
	/**
58
	 * Invokes a change operation on the observable resulting in a change event
59
	 * being fired from the observable.
60
	 * 
61
	 * @param observable
62
	 */
63
	public void change(IObservable observable);
64
}
(-)src/org/eclipse/jface/conformance/databinding/SWTObservableValueContractTest.java (-62 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.jface.databinding.swt.SWTObservables;
16
import org.eclipse.jface.tests.databinding.RealmTester.DelegatingRealm;
17
import org.eclipse.swt.widgets.Display;
18
19
/**
20
 * Tests for IObservableValue that don't mutate the value.
21
 * <p>
22
 * This class is experimental and can change at any time. It is recommended to
23
 * not subclass or assume the test names will not change. The only API that is
24
 * guaranteed to not change are the constructors. The tests will remain public
25
 * and not final in order to allow for consumers to turn off a test if needed by
26
 * subclassing.
27
 * </p>
28
 * 
29
 * @since 3.2
30
 */
31
public class SWTObservableValueContractTest extends ObservableValueContractTest {
32
	private IObservableValueContractDelegate delegate;
33
34
	/**
35
	 * @param delegate
36
	 */
37
	public SWTObservableValueContractTest(
38
			IObservableValueContractDelegate delegate) {
39
		this(null, delegate);
40
	}
41
42
	public SWTObservableValueContractTest(String testName,
43
			IObservableValueContractDelegate delegate) {
44
		super(testName, delegate);
45
		this.delegate = delegate;
46
	}
47
48
	/**
49
	 * Creates a new observable passing the realm for the current display.
50
	 */
51
	protected IObservable doCreateObservable() {
52
		Display display = Display.getCurrent();
53
		if (display == null) {
54
			display = new Display();
55
		}
56
		DelegatingRealm delegateRealm = new DelegatingRealm(SWTObservables
57
				.getRealm(display));
58
		delegateRealm.setCurrent(true);
59
60
		return delegate.createObservable(delegateRealm);
61
	}
62
}
(-)src/org/eclipse/jface/conformance/databinding/AbstractObservableContractDelegate.java (-39 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
16
/**
17
 * Abstract implementation of {@link IObservableContractDelegate}.
18
 * 
19
 * @since 1.1
20
 */
21
public abstract class AbstractObservableContractDelegate implements
22
		IObservableContractDelegate {
23
24
	public void setUp() {
25
		// no op
26
	}
27
28
	public void tearDown() {
29
		// no op
30
	}
31
32
	public void change(IObservable observable) {
33
		// no op
34
	}
35
36
	public void setStale(IObservable observable, boolean stale) {
37
		// no op
38
	}
39
}
(-)src/org/eclipse/jface/conformance/databinding/ObservableStaleContractTest.java (-148 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import org.eclipse.core.databinding.observable.IObservable;
15
import org.eclipse.core.databinding.observable.IStaleListener;
16
import org.eclipse.core.databinding.observable.StaleEvent;
17
18
/**
19
 * @since 3.3
20
 */
21
public class ObservableStaleContractTest extends ObservableDelegateTest {
22
	private IObservableContractDelegate delegate;
23
	private IObservable observable;
24
	
25
	public ObservableStaleContractTest(IObservableContractDelegate delegate) {
26
		this(null, delegate);
27
	}
28
	
29
	public ObservableStaleContractTest(String testName, IObservableContractDelegate delegate) {
30
		super(testName, delegate);
31
		this.delegate = delegate;
32
	}
33
	
34
	protected void setUp() throws Exception {
35
		super.setUp();
36
		
37
		observable = getObservable();
38
	}
39
	
40
	public void testIsStale_TrueWhenStale() throws Exception {
41
		delegate.setStale(observable, true);
42
		assertTrue(formatFail("When stale isStale() should return true."), observable.isStale());
43
	}
44
	
45
	public void testIsStale_FalseWhenNotStale() throws Exception {
46
		delegate.setStale(observable, false);
47
		assertFalse(formatFail("When not stale isStale() should return false."), observable.isStale());
48
	}
49
50
	public void testBecomingStaleFiresStaleEvent() throws Exception {
51
		StaleListener listener = new StaleListener();
52
53
		// precondition
54
		ensureStale(observable, false);
55
56
		observable.addStaleListener(listener);
57
		delegate.setStale(observable, true);
58
59
		assertEquals(formatFail("When becoming stale listeners should be notified."), 1, listener.count);
60
	}
61
62
	public void testStaleEventObservable() throws Exception {
63
		StaleListener listener = new StaleListener();
64
65
		// precondition
66
		ensureStale(observable, false);
67
68
		observable.addStaleListener(listener);
69
		delegate.setStale(observable, true);
70
71
		StaleEvent event = listener.event;
72
		assertNotNull(formatFail("stale event was null"), event);
73
		assertEquals(formatFail("When notifying listeners of becoming stale the observable should be the source of the event."), observable,
74
				event.getObservable());
75
	}
76
77
	public void testRemoveStaleListener_RemovesListener() throws Exception {
78
		StaleListener listener = new StaleListener();
79
80
		observable.addStaleListener(listener);
81
		ensureStale(observable, false);
82
		delegate.setStale(observable, true);
83
84
		// precondition check
85
		assertEquals(formatFail("set stale did not notify listeners"), 1, listener.count);
86
87
		observable.removeStaleListener(listener);
88
		ensureStale(observable, false);
89
		delegate.setStale(observable, true);
90
91
		assertEquals(formatFail("Once removed stale listeners should not be notified of becoming stale."), 1,
92
				listener.count);
93
	}
94
95
	public void testStaleListenersAreNotNotifiedWhenObservableIsNoLongerStale()
96
			throws Exception {
97
		ensureStale(observable, true);
98
99
		StaleListener listener = new StaleListener();
100
		observable.addStaleListener(listener);
101
		delegate.setStale(observable, false);
102
103
		assertEquals(formatFail("Stale listeners should not be notified when the stale state changes from true to false."), 0,
104
				listener.count);
105
	}
106
107
	public void testObservableRealmIsCurrentOnStale() throws Exception {
108
		ensureStale(observable, false);
109
110
		StaleListener listener = new StaleListener();
111
		observable.addStaleListener(listener);
112
		delegate.setStale(observable, true);
113
114
		assertTrue(formatFail("When notifying listeners of becoming stale the observable's realm should be the current realm."),
115
				listener.isCurrentRealm);
116
	}
117
	
118
	/**
119
	 * Ensures that stale is set to the provided state. Will throw an
120
	 * AssertionFailedError if setting of the state is unsuccessful.
121
	 * 
122
	 * @param observable
123
	 * @param stale
124
	 */
125
	private void ensureStale(IObservable observable, boolean stale) {
126
		if (observable.isStale() != stale) {
127
			delegate.setStale(observable, stale);
128
		}
129
130
		assertEquals(stale, observable.isStale());
131
	}
132
	
133
	/* package */static class StaleListener implements IStaleListener {
134
		int count;
135
136
		StaleEvent event;
137
138
		boolean isCurrentRealm;
139
140
		public void handleStale(StaleEvent staleEvent) {
141
			count++;
142
			this.event = staleEvent;
143
			this.isCurrentRealm = staleEvent.getObservable().getRealm()
144
					.isCurrent();
145
		}
146
	}
147
148
}
(-)src/org/eclipse/jface/conformance/databinding/SuiteBuilder.java (-179 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.conformance.databinding;
13
14
import java.lang.reflect.Constructor;
15
import java.lang.reflect.Method;
16
import java.util.Iterator;
17
import java.util.LinkedHashSet;
18
19
import junit.framework.Test;
20
import junit.framework.TestSuite;
21
22
/**
23
 * Builds a test suite.
24
 * 
25
 * @since 1.1
26
 */
27
public class SuiteBuilder {
28
	private LinkedHashSet content;
29
30
	public SuiteBuilder() {
31
		content = new LinkedHashSet();
32
	}
33
34
	/**
35
	 * Adds all test methods from the provided <code>testCase</code> to the
36
	 * suite.
37
	 * 
38
	 * @param testCase
39
	 * @return builder
40
	 */
41
	public SuiteBuilder addTests(Class testCase) {
42
		content.add(testCase);
43
		return this;
44
	}
45
46
	/**
47
	 * Adds all test methods from the provided <code>testCase</code> with the
48
	 * provided <code>parameters</code>. A constructor must exist in the
49
	 * testCase that accepts a String as the first parameter followed by
50
	 * parameters matching the provided parameters. If an appropriate
51
	 * constructor is not found an exception will be thrown.
52
	 * 
53
	 * @param testCase
54
	 * @param parameters
55
	 * @return builder
56
	 */
57
	public SuiteBuilder addParameterizedTests(Class testCase,
58
			Object[] parameters) {
59
60
		Constructor constructor = findConstructor(testCase, parameters);
61
		if (constructor == null) {
62
			throw new IllegalArgumentException(
63
					"The parameters provided don't match a constructor found in ["
64
							+ testCase.getName() + "]");
65
		}
66
67
		content.add(new ParameterizedTest(testCase, constructor, parameters));
68
69
		return this;
70
	}
71
72
	/**
73
	 * Convenience method for invoking
74
	 * {@link #addParameterizedTests(Class, Object[])} with a delegate.
75
	 * 
76
	 * @param testCase
77
	 * @param delegate
78
	 * @return
79
	 */
80
	public SuiteBuilder addObservableContractTest(Class testCase,
81
			IObservableContractDelegate delegate) {
82
83
		addParameterizedTests(testCase, new Object[] {delegate});
84
		return this;
85
	}
86
87
	/**
88
	 * Builds a new TestSuite out of the tests.
89
	 * 
90
	 * @return suite
91
	 */
92
	public TestSuite build() {
93
		TestSuite suite = new TestSuite();
94
95
		for (Iterator it = content.iterator(); it.hasNext();) {
96
			Object o = it.next();
97
			if (o instanceof Class) {
98
				suite.addTestSuite((Class) o);
99
			} else if (o instanceof ParameterizedTest) {
100
				ParameterizedTest test = (ParameterizedTest) o;
101
102
				Method[] methods = test.testClass.getMethods();
103
				for (int i = 0; i < methods.length; i++) {
104
					String name = methods[i].getName();
105
					if (name.startsWith("test")) {
106
						try {
107
							suite.addTest((Test) test.constructor
108
									.newInstance(toParamArray(name,
109
											test.parameters)));
110
						} catch (Exception e) {
111
							throw new RuntimeException(e);
112
						}
113
					}
114
				}
115
			}
116
		}
117
118
		return suite;
119
	}
120
121
	private Object[] toParamArray(String testName, Object[] parameters) {
122
		Object[] result = new Object[parameters.length + 1];
123
		result[0] = testName;
124
		System.arraycopy(parameters, 0, result, 1, parameters.length);
125
		return result;
126
	}
127
128
	/**
129
	 * Returns the constructor that has a String as the first parameters and
130
	 * then matches the type of the parameters.
131
	 * 
132
	 * @param parameters
133
	 * @return
134
	 */
135
	private static Constructor findConstructor(Class clazz, Object[] parameters) {
136
		Constructor[] constructors = clazz.getConstructors();
137
		int expectedParametersLength = parameters.length + 1;
138
139
		for (int i = 0; i < constructors.length; i++) {
140
			Constructor constructor = constructors[i];
141
			Class[] types = constructor.getParameterTypes();
142
143
			if (types.length != expectedParametersLength
144
					|| !String.class.equals(types[0])) {
145
				continue;
146
			}
147
148
			boolean skip = false;
149
			for (int j = 1; j < types.length; j++) {
150
				Class type = types[j];
151
				if (!type.isInstance(parameters[j - 1])) {
152
					skip = true;
153
					break;
154
				}
155
			}
156
157
			if (!skip) {
158
				return constructor;
159
			}
160
		}
161
162
		return null;
163
	}
164
165
	/* package */static class ParameterizedTest {
166
		final Constructor constructor;
167
168
		final Object[] parameters;
169
170
		private Class testClass;
171
172
		ParameterizedTest(Class testClass, Constructor constructor,
173
				Object[] parameterss) {
174
			this.testClass = testClass;
175
			this.constructor = constructor;
176
			this.parameters = parameterss;
177
		}
178
	}
179
}
(-)src/org/eclipse/core/tests/databinding/observable/list/AbstractObservableListTest.java (-5 / +5 lines)
Lines 25-35 Link Here
25
import org.eclipse.core.databinding.observable.Realm;
25
import org.eclipse.core.databinding.observable.Realm;
26
import org.eclipse.core.databinding.observable.list.AbstractObservableList;
26
import org.eclipse.core.databinding.observable.list.AbstractObservableList;
27
import org.eclipse.core.databinding.observable.list.ListDiff;
27
import org.eclipse.core.databinding.observable.list.ListDiff;
28
import org.eclipse.jface.conformance.databinding.AbstractObservableCollectionContractDelegate;
28
import org.eclipse.jface.databinding.conformance.ObservableListContractTest;
29
import org.eclipse.jface.conformance.databinding.ObservableListContractTest;
29
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate;
30
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
30
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
31
import org.eclipse.jface.tests.databinding.RealmTester;
31
import org.eclipse.jface.databinding.conformance.util.RealmTester;
32
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
32
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
33
33
34
/**
34
/**
35
 * @since 3.2
35
 * @since 3.2
(-)src/org/eclipse/core/tests/databinding/observable/list/ObservableListTest.java (-5 / +5 lines)
Lines 24-34 Link Here
24
import org.eclipse.core.databinding.observable.Realm;
24
import org.eclipse.core.databinding.observable.Realm;
25
import org.eclipse.core.databinding.observable.list.ListDiff;
25
import org.eclipse.core.databinding.observable.list.ListDiff;
26
import org.eclipse.core.databinding.observable.list.ObservableList;
26
import org.eclipse.core.databinding.observable.list.ObservableList;
27
import org.eclipse.jface.conformance.databinding.AbstractObservableCollectionContractDelegate;
27
import org.eclipse.jface.databinding.conformance.ObservableListContractTest;
28
import org.eclipse.jface.conformance.databinding.ObservableListContractTest;
28
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate;
29
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
29
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
30
import org.eclipse.jface.tests.databinding.RealmTester;
30
import org.eclipse.jface.databinding.conformance.util.RealmTester;
31
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
31
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
32
32
33
/**
33
/**
34
 * @since 3.2
34
 * @since 3.2
(-)src/org/eclipse/core/tests/databinding/observable/list/WritableListTest.java (-6 / +6 lines)
Lines 22-34 Link Here
22
import org.eclipse.core.databinding.observable.IObservableCollection;
22
import org.eclipse.core.databinding.observable.IObservableCollection;
23
import org.eclipse.core.databinding.observable.Realm;
23
import org.eclipse.core.databinding.observable.Realm;
24
import org.eclipse.core.databinding.observable.list.WritableList;
24
import org.eclipse.core.databinding.observable.list.WritableList;
25
import org.eclipse.jface.conformance.databinding.AbstractObservableCollectionContractDelegate;
25
import org.eclipse.jface.databinding.conformance.MutableObservableListContractTest;
26
import org.eclipse.jface.conformance.databinding.MutableObservableListContractTest;
26
import org.eclipse.jface.databinding.conformance.ObservableListContractTest;
27
import org.eclipse.jface.conformance.databinding.ObservableListContractTest;
27
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate;
28
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
28
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
29
import org.eclipse.jface.databinding.conformance.util.RealmTester;
30
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
29
import org.eclipse.jface.databinding.swt.SWTObservables;
31
import org.eclipse.jface.databinding.swt.SWTObservables;
30
import org.eclipse.jface.tests.databinding.RealmTester;
31
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
32
import org.eclipse.swt.widgets.Display;
32
import org.eclipse.swt.widgets.Display;
33
33
34
/**
34
/**
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ScaleObservableValueMaxTest.java (-5 / +5 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
19
import org.eclipse.jface.databinding.conformance.ObservableDelegateTest;
20
import org.eclipse.jface.conformance.databinding.ObservableDelegateTest;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
26
import org.eclipse.jface.internal.databinding.internal.swt.ScaleObservableValue;
26
import org.eclipse.jface.internal.databinding.internal.swt.ScaleObservableValue;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/SpinnerObservableValueMaxTest.java (-5 / +5 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
19
import org.eclipse.jface.databinding.conformance.ObservableDelegateTest;
20
import org.eclipse.jface.conformance.databinding.ObservableDelegateTest;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
26
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
26
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ComboObservableValueTextTest.java (-7 / +7 lines)
Lines 17-31 Link Here
17
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.IObservable;
18
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
24
import org.eclipse.jface.databinding.swt.ISWTObservable;
25
import org.eclipse.jface.databinding.swt.ISWTObservable;
25
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableValue;
27
import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableValue;
27
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
28
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
28
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
29
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.widgets.Combo;
30
import org.eclipse.swt.widgets.Combo;
31
import org.eclipse.swt.widgets.Display;
31
import org.eclipse.swt.widgets.Display;
Lines 58-65 Link Here
58
		IObservableValue observable = delegate
58
		IObservableValue observable = delegate
59
				.createObservableValue(SWTObservables.getRealm(Display
59
				.createObservableValue(SWTObservables.getRealm(Display
60
						.getDefault()));
60
						.getDefault()));
61
		ValueChangeEventTracker listener = new ValueChangeEventTracker()
61
		ValueChangeEventTracker listener = ValueChangeEventTracker
62
				.register(observable);
62
				.observe(observable);
63
63
64
		combo.setText((String) delegate.createValue(observable));
64
		combo.setText((String) delegate.createValue(observable));
65
65
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ComboObservableValueSelectionTest.java (-7 / +7 lines)
Lines 17-31 Link Here
17
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.IObservable;
18
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
24
import org.eclipse.jface.databinding.swt.ISWTObservable;
25
import org.eclipse.jface.databinding.swt.ISWTObservable;
25
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableValue;
27
import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableValue;
27
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
28
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
28
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
29
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.widgets.Combo;
30
import org.eclipse.swt.widgets.Combo;
31
import org.eclipse.swt.widgets.Display;
31
import org.eclipse.swt.widgets.Display;
Lines 58-65 Link Here
58
		IObservableValue observable = (IObservableValue) delegate
58
		IObservableValue observable = (IObservableValue) delegate
59
				.createObservable(SWTObservables.getRealm(Display.getDefault()));
59
				.createObservable(SWTObservables.getRealm(Display.getDefault()));
60
60
61
		ValueChangeEventTracker listener = new ValueChangeEventTracker()
61
		ValueChangeEventTracker listener = ValueChangeEventTracker
62
				.register(observable);
62
				.observe(observable);
63
		combo.select(0);
63
		combo.select(0);
64
		combo.notifyListeners(SWT.Selection, null);
64
		combo.notifyListeners(SWT.Selection, null);
65
65
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ComboObservableValueTest.java (-1 / +1 lines)
Lines 12-21 Link Here
12
12
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
14
14
15
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
15
import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableValue;
16
import org.eclipse.jface.internal.databinding.internal.swt.ComboObservableValue;
16
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
17
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
17
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
18
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
18
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
19
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.widgets.Combo;
20
import org.eclipse.swt.widgets.Combo;
21
21
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ScaleObservableValueSelectionTest.java (-5 / +5 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
19
import org.eclipse.jface.databinding.conformance.ObservableDelegateTest;
20
import org.eclipse.jface.conformance.databinding.ObservableDelegateTest;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
26
import org.eclipse.jface.internal.databinding.internal.swt.ScaleObservableValue;
26
import org.eclipse.jface.internal.databinding.internal.swt.ScaleObservableValue;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/LabelObservableValueTest.java (-5 / +5 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
19
import org.eclipse.jface.databinding.conformance.ObservableDelegateTest;
20
import org.eclipse.jface.conformance.databinding.ObservableDelegateTest;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.internal.databinding.internal.swt.LabelObservableValue;
25
import org.eclipse.jface.internal.databinding.internal.swt.LabelObservableValue;
26
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.SWT;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/CComboObservableValueSelectionTest.java (-7 / +6 lines)
Lines 17-31 Link Here
17
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.IObservable;
18
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
24
import org.eclipse.jface.databinding.swt.ISWTObservable;
25
import org.eclipse.jface.databinding.swt.ISWTObservable;
25
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableValue;
27
import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableValue;
27
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
28
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
28
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
29
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.custom.CCombo;
30
import org.eclipse.swt.custom.CCombo;
31
import org.eclipse.swt.widgets.Display;
31
import org.eclipse.swt.widgets.Display;
Lines 57-64 Link Here
57
		IObservableValue observable = (IObservableValue) delegate
57
		IObservableValue observable = (IObservableValue) delegate
58
				.createObservable(SWTObservables.getRealm(Display.getDefault()));
58
				.createObservable(SWTObservables.getRealm(Display.getDefault()));
59
59
60
		ValueChangeEventTracker listener = new ValueChangeEventTracker()
60
		ValueChangeEventTracker listener = ValueChangeEventTracker.observe(observable);
61
				.register(observable);
62
		combo.select(0);
61
		combo.select(0);
63
62
64
		assertEquals("Observable was not notified.", 1, listener.count);
63
		assertEquals("Observable was not notified.", 1, listener.count);
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/TableSingleSelectionObservableValueTest.java (-5 / +5 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
19
import org.eclipse.jface.databinding.conformance.ObservableDelegateTest;
20
import org.eclipse.jface.conformance.databinding.ObservableDelegateTest;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.internal.databinding.internal.swt.TableSingleSelectionObservableValue;
25
import org.eclipse.jface.internal.databinding.internal.swt.TableSingleSelectionObservableValue;
26
import org.eclipse.jface.util.Assert;
26
import org.eclipse.jface.util.Assert;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/TextEditableObservableValueTest.java (-5 / +5 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
19
import org.eclipse.jface.databinding.conformance.ObservableDelegateTest;
20
import org.eclipse.jface.conformance.databinding.ObservableDelegateTest;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.internal.databinding.internal.swt.TextEditableObservableValue;
24
import org.eclipse.jface.internal.databinding.internal.swt.TextEditableObservableValue;
25
import org.eclipse.swt.SWT;
25
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.widgets.Shell;
26
import org.eclipse.swt.widgets.Shell;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ScaleObservableValueMinTest.java (-5 / +5 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
19
import org.eclipse.jface.databinding.conformance.ObservableDelegateTest;
20
import org.eclipse.jface.conformance.databinding.ObservableDelegateTest;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
26
import org.eclipse.jface.internal.databinding.internal.swt.ScaleObservableValue;
26
import org.eclipse.jface.internal.databinding.internal.swt.ScaleObservableValue;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/SpinnerObservableValueTest.java (-1 / +1 lines)
Lines 12-21 Link Here
12
12
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
14
14
15
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
15
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
16
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
16
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
17
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
17
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
18
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
18
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
19
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.widgets.Spinner;
20
import org.eclipse.swt.widgets.Spinner;
21
21
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/ButtonObservableValueTest.java (-5 / +5 lines)
Lines 17-29 Link Here
17
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.IObservable;
18
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
24
import org.eclipse.jface.internal.databinding.internal.swt.ButtonObservableValue;
25
import org.eclipse.jface.internal.databinding.internal.swt.ButtonObservableValue;
25
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
26
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
26
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
27
import org.eclipse.swt.SWT;
27
import org.eclipse.swt.SWT;
28
import org.eclipse.swt.widgets.Button;
28
import org.eclipse.swt.widgets.Button;
29
import org.eclipse.swt.widgets.Shell;
29
import org.eclipse.swt.widgets.Shell;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/TextObservableValueTest.java (-1 / +1 lines)
Lines 14-22 Link Here
14
14
15
package org.eclipse.jface.tests.internal.databinding.internal.swt;
15
package org.eclipse.jface.tests.internal.databinding.internal.swt;
16
16
17
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
17
import org.eclipse.jface.internal.databinding.internal.swt.TextObservableValue;
18
import org.eclipse.jface.internal.databinding.internal.swt.TextObservableValue;
18
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
19
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
19
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
20
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.SWT;
21
import org.eclipse.swt.widgets.Shell;
21
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.swt.widgets.Text;
22
import org.eclipse.swt.widgets.Text;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/CComboObservableValueTextTest.java (-7 / +7 lines)
Lines 17-31 Link Here
17
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.IObservable;
18
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
24
import org.eclipse.jface.databinding.swt.ISWTObservable;
25
import org.eclipse.jface.databinding.swt.ISWTObservable;
25
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableValue;
27
import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableValue;
27
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
28
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
28
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
29
import org.eclipse.swt.SWT;
29
import org.eclipse.swt.SWT;
30
import org.eclipse.swt.custom.CCombo;
30
import org.eclipse.swt.custom.CCombo;
31
import org.eclipse.swt.widgets.Display;
31
import org.eclipse.swt.widgets.Display;
Lines 57-64 Link Here
57
		IObservableValue observable = delegate
57
		IObservableValue observable = delegate
58
				.createObservableValue(SWTObservables.getRealm(Display
58
				.createObservableValue(SWTObservables.getRealm(Display
59
						.getDefault()));
59
						.getDefault()));
60
		ValueChangeEventTracker listener = new ValueChangeEventTracker()
60
		ValueChangeEventTracker listener = ValueChangeEventTracker
61
				.register(observable);
61
				.observe(observable);
62
62
63
		combo.setText((String) delegate.createValue(observable));
63
		combo.setText((String) delegate.createValue(observable));
64
64
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/CLabelObservableValueTest.java (-4 / +4 lines)
Lines 17-26 Link Here
17
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.IObservable;
18
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.internal.databinding.internal.swt.CLabelObservableValue;
25
import org.eclipse.jface.internal.databinding.internal.swt.CLabelObservableValue;
26
import org.eclipse.swt.SWT;
26
import org.eclipse.swt.SWT;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/SpinnerObservableValueMinTest.java (-5 / +5 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
19
import org.eclipse.jface.databinding.conformance.ObservableDelegateTest;
20
import org.eclipse.jface.conformance.databinding.ObservableDelegateTest;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
26
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
26
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/CComboSingleSelectionObservableValueTest.java (-4 / +4 lines)
Lines 17-26 Link Here
17
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.IObservable;
18
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.ISWTObservable;
24
import org.eclipse.jface.databinding.swt.ISWTObservable;
25
import org.eclipse.jface.internal.databinding.internal.swt.CComboSingleSelectionObservableValue;
25
import org.eclipse.jface.internal.databinding.internal.swt.CComboSingleSelectionObservableValue;
26
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
26
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/CComboObservableValueTest.java (-1 / +1 lines)
Lines 12-21 Link Here
12
12
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
13
package org.eclipse.jface.tests.internal.databinding.internal.swt;
14
14
15
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
15
import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableValue;
16
import org.eclipse.jface.internal.databinding.internal.swt.CComboObservableValue;
16
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
17
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
17
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
18
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
18
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
19
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.SWT;
20
import org.eclipse.swt.custom.CCombo;
20
import org.eclipse.swt.custom.CCombo;
21
21
(-)src/org/eclipse/jface/tests/internal/databinding/internal/swt/SpinnerObservableValueSelectionTest.java (-5 / +5 lines)
Lines 16-26 Link Here
16
import org.eclipse.core.databinding.observable.IObservable;
16
import org.eclipse.core.databinding.observable.IObservable;
17
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
18
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
19
import org.eclipse.jface.databinding.conformance.ObservableDelegateTest;
20
import org.eclipse.jface.conformance.databinding.ObservableDelegateTest;
20
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.conformance.databinding.SWTMutableObservableValueContractTest;
21
import org.eclipse.jface.databinding.conformance.swt.SWTMutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.SWTObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.swt.SWTObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
23
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
24
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
25
import org.eclipse.jface.internal.databinding.internal.swt.SWTProperties;
26
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
26
import org.eclipse.jface.internal.databinding.internal.swt.SpinnerObservableValue;
(-)src/org/eclipse/core/tests/databinding/observable/map/WritableMapTest.java (-3 / +3 lines)
Lines 19-27 Link Here
19
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.Realm;
20
import org.eclipse.core.databinding.observable.map.MapChangeEvent;
20
import org.eclipse.core.databinding.observable.map.MapChangeEvent;
21
import org.eclipse.core.databinding.observable.map.WritableMap;
21
import org.eclipse.core.databinding.observable.map.WritableMap;
22
import org.eclipse.jface.tests.databinding.RealmTester;
22
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
23
import org.eclipse.jface.tests.databinding.EventTrackers.MapChangeEventTracker;
23
import org.eclipse.jface.databinding.conformance.util.MapChangeEventTracker;
24
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
24
import org.eclipse.jface.databinding.conformance.util.RealmTester;
25
25
26
/**
26
/**
27
 * @since 3.2
27
 * @since 3.2
(-)src/org/eclipse/core/tests/databinding/observable/map/ObservableMapTest.java (-2 / +2 lines)
Lines 20-27 Link Here
20
import org.eclipse.core.databinding.observable.map.MapChangeEvent;
20
import org.eclipse.core.databinding.observable.map.MapChangeEvent;
21
import org.eclipse.core.databinding.observable.map.MapDiff;
21
import org.eclipse.core.databinding.observable.map.MapDiff;
22
import org.eclipse.core.databinding.observable.map.ObservableMap;
22
import org.eclipse.core.databinding.observable.map.ObservableMap;
23
import org.eclipse.jface.tests.databinding.RealmTester;
23
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
24
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
24
import org.eclipse.jface.databinding.conformance.util.RealmTester;
25
25
26
/**
26
/**
27
 * @since 3.2
27
 * @since 3.2
(-)src/org/eclipse/core/tests/databinding/observable/map/AbstractObservableMapTest.java (-2 / +2 lines)
Lines 17-24 Link Here
17
17
18
import org.eclipse.core.databinding.observable.map.AbstractObservableMap;
18
import org.eclipse.core.databinding.observable.map.AbstractObservableMap;
19
import org.eclipse.core.databinding.observable.map.MapDiff;
19
import org.eclipse.core.databinding.observable.map.MapDiff;
20
import org.eclipse.jface.tests.databinding.RealmTester;
20
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
21
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
21
import org.eclipse.jface.databinding.conformance.util.RealmTester;
22
22
23
/**
23
/**
24
 * @since 3.2
24
 * @since 3.2
(-)src/org/eclipse/jface/tests/databinding/swt/SWTObservablesTest.java (-1 / +1 lines)
Lines 12-17 Link Here
12
package org.eclipse.jface.tests.databinding.swt;
12
package org.eclipse.jface.tests.databinding.swt;
13
13
14
import org.eclipse.core.databinding.observable.list.IObservableList;
14
import org.eclipse.core.databinding.observable.list.IObservableList;
15
import org.eclipse.jface.databinding.conformance.util.RealmTester;
15
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
16
import org.eclipse.jface.databinding.swt.ISWTObservableValue;
16
import org.eclipse.jface.databinding.swt.SWTObservables;
17
import org.eclipse.jface.databinding.swt.SWTObservables;
17
import org.eclipse.jface.internal.databinding.internal.swt.ButtonObservableValue;
18
import org.eclipse.jface.internal.databinding.internal.swt.ButtonObservableValue;
Lines 30-36 Link Here
30
import org.eclipse.jface.internal.databinding.internal.swt.TextEditableObservableValue;
31
import org.eclipse.jface.internal.databinding.internal.swt.TextEditableObservableValue;
31
import org.eclipse.jface.internal.databinding.internal.swt.TextObservableValue;
32
import org.eclipse.jface.internal.databinding.internal.swt.TextObservableValue;
32
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
33
import org.eclipse.jface.tests.databinding.AbstractSWTTestCase;
33
import org.eclipse.jface.tests.databinding.RealmTester;
34
import org.eclipse.swt.SWT;
34
import org.eclipse.swt.SWT;
35
import org.eclipse.swt.custom.CCombo;
35
import org.eclipse.swt.custom.CCombo;
36
import org.eclipse.swt.custom.CLabel;
36
import org.eclipse.swt.custom.CLabel;
(-)src/org/eclipse/core/tests/databinding/observable/set/UnionSetTest.java (-3 / +3 lines)
Lines 20-28 Link Here
20
import org.eclipse.core.databinding.observable.set.IObservableSet;
20
import org.eclipse.core.databinding.observable.set.IObservableSet;
21
import org.eclipse.core.databinding.observable.set.UnionSet;
21
import org.eclipse.core.databinding.observable.set.UnionSet;
22
import org.eclipse.core.databinding.observable.set.WritableSet;
22
import org.eclipse.core.databinding.observable.set.WritableSet;
23
import org.eclipse.jface.conformance.databinding.AbstractObservableCollectionContractDelegate;
23
import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest;
24
import org.eclipse.jface.conformance.databinding.ObservableCollectionContractTest;
24
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate;
25
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
25
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
26
26
27
/**
27
/**
28
 */
28
 */
(-)src/org/eclipse/core/tests/databinding/observable/set/AbstractObservableSetTest.java (-3 / +3 lines)
Lines 23-31 Link Here
23
import org.eclipse.core.databinding.observable.Realm;
23
import org.eclipse.core.databinding.observable.Realm;
24
import org.eclipse.core.databinding.observable.set.AbstractObservableSet;
24
import org.eclipse.core.databinding.observable.set.AbstractObservableSet;
25
import org.eclipse.core.databinding.observable.set.SetDiff;
25
import org.eclipse.core.databinding.observable.set.SetDiff;
26
import org.eclipse.jface.conformance.databinding.AbstractObservableCollectionContractDelegate;
26
import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest;
27
import org.eclipse.jface.conformance.databinding.ObservableCollectionContractTest;
27
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate;
28
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
28
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
29
29
30
/**
30
/**
31
 */
31
 */
(-)src/org/eclipse/core/tests/databinding/observable/set/ObservableSetTest.java (-3 / +3 lines)
Lines 24-32 Link Here
24
import org.eclipse.core.databinding.observable.set.IObservableSet;
24
import org.eclipse.core.databinding.observable.set.IObservableSet;
25
import org.eclipse.core.databinding.observable.set.ObservableSet;
25
import org.eclipse.core.databinding.observable.set.ObservableSet;
26
import org.eclipse.core.databinding.observable.set.SetDiff;
26
import org.eclipse.core.databinding.observable.set.SetDiff;
27
import org.eclipse.jface.conformance.databinding.AbstractObservableCollectionContractDelegate;
27
import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest;
28
import org.eclipse.jface.conformance.databinding.ObservableCollectionContractTest;
28
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate;
29
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
29
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
30
30
31
/**
31
/**
32
 * @since 1.1
32
 * @since 1.1
(-)src/org/eclipse/core/tests/databinding/observable/set/WritableSetTest.java (-4 / +4 lines)
Lines 19-28 Link Here
19
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.Realm;
20
import org.eclipse.core.databinding.observable.set.IObservableSet;
20
import org.eclipse.core.databinding.observable.set.IObservableSet;
21
import org.eclipse.core.databinding.observable.set.WritableSet;
21
import org.eclipse.core.databinding.observable.set.WritableSet;
22
import org.eclipse.jface.conformance.databinding.AbstractObservableCollectionContractDelegate;
22
import org.eclipse.jface.databinding.conformance.MutableObservableSetContractTest;
23
import org.eclipse.jface.conformance.databinding.MutableObservableSetContractTest;
23
import org.eclipse.jface.databinding.conformance.ObservableCollectionContractTest;
24
import org.eclipse.jface.conformance.databinding.ObservableCollectionContractTest;
24
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableCollectionContractDelegate;
25
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
25
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
26
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
26
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
27
27
28
/**
28
/**
(-)src/org/eclipse/jface/tests/internal/databinding/internal/viewers/SelectionProviderSingleSelectionObservableValueTest.java (-1 / +1 lines)
Lines 14-22 Link Here
14
14
15
import junit.framework.TestCase;
15
import junit.framework.TestCase;
16
16
17
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
17
import org.eclipse.jface.databinding.swt.SWTObservables;
18
import org.eclipse.jface.databinding.swt.SWTObservables;
18
import org.eclipse.jface.internal.databinding.internal.viewers.SelectionProviderSingleSelectionObservableValue;
19
import org.eclipse.jface.internal.databinding.internal.viewers.SelectionProviderSingleSelectionObservableValue;
19
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
20
import org.eclipse.jface.viewers.ISelectionProvider;
20
import org.eclipse.jface.viewers.ISelectionProvider;
21
import org.eclipse.jface.viewers.IStructuredContentProvider;
21
import org.eclipse.jface.viewers.IStructuredContentProvider;
22
import org.eclipse.jface.viewers.StructuredSelection;
22
import org.eclipse.jface.viewers.StructuredSelection;
(-)src/org/eclipse/jface/tests/internal/databinding/internal/viewers/SelectionProviderMultiSelectionObservableListTest.java (-1 / +1 lines)
Lines 14-22 Link Here
14
import junit.framework.TestCase;
14
import junit.framework.TestCase;
15
15
16
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
16
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
17
import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker;
17
import org.eclipse.jface.databinding.swt.SWTObservables;
18
import org.eclipse.jface.databinding.swt.SWTObservables;
18
import org.eclipse.jface.internal.databinding.internal.viewers.SelectionProviderMultipleSelectionObservableList;
19
import org.eclipse.jface.internal.databinding.internal.viewers.SelectionProviderMultipleSelectionObservableList;
19
import org.eclipse.jface.tests.databinding.EventTrackers.ListChangeEventTracker;
20
import org.eclipse.jface.viewers.ISelectionProvider;
20
import org.eclipse.jface.viewers.ISelectionProvider;
21
import org.eclipse.jface.viewers.IStructuredContentProvider;
21
import org.eclipse.jface.viewers.IStructuredContentProvider;
22
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.jface.viewers.IStructuredSelection;
(-)src/org/eclipse/core/tests/databinding/observable/AbstractObservableTest.java (-7 / +7 lines)
Lines 19-32 Link Here
19
import org.eclipse.core.databinding.observable.IStaleListener;
19
import org.eclipse.core.databinding.observable.IStaleListener;
20
import org.eclipse.core.databinding.observable.Realm;
20
import org.eclipse.core.databinding.observable.Realm;
21
import org.eclipse.core.databinding.observable.StaleEvent;
21
import org.eclipse.core.databinding.observable.StaleEvent;
22
import org.eclipse.jface.conformance.databinding.AbstractObservableContractDelegate;
22
import org.eclipse.jface.databinding.conformance.ObservableContractTest;
23
import org.eclipse.jface.conformance.databinding.ObservableContractTest;
23
import org.eclipse.jface.databinding.conformance.ObservableStaleContractTest;
24
import org.eclipse.jface.conformance.databinding.ObservableStaleContractTest;
24
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableContractDelegate;
25
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
25
import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker;
26
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
27
import org.eclipse.jface.databinding.conformance.util.RealmTester;
28
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
26
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
29
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
27
import org.eclipse.jface.tests.databinding.RealmTester;
28
import org.eclipse.jface.tests.databinding.EventTrackers.ChangeEventTracker;
29
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
30
30
31
/**
31
/**
32
 * Tests for AbstractObservable.
32
 * Tests for AbstractObservable.
(-)src/org/eclipse/core/tests/databinding/observable/RealmTest.java (-2 / +2 lines)
Lines 14-21 Link Here
14
import junit.framework.TestCase;
14
import junit.framework.TestCase;
15
15
16
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.jface.tests.databinding.RealmTester;
17
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
18
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
18
import org.eclipse.jface.databinding.conformance.util.RealmTester;
19
19
20
/**
20
/**
21
 * @since 3.2
21
 * @since 3.2
(-)src/org/eclipse/jface/tests/databinding/AbstractDefaultRealmTestCase.java (+1 lines)
Lines 14-19 Link Here
14
import junit.framework.TestCase;
14
import junit.framework.TestCase;
15
15
16
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.jface.databinding.conformance.util.RealmTester;
17
import org.eclipse.jface.databinding.swt.SWTObservables;
18
import org.eclipse.jface.databinding.swt.SWTObservables;
18
import org.eclipse.swt.widgets.Display;
19
import org.eclipse.swt.widgets.Display;
19
20
(-)src/org/eclipse/jface/tests/databinding/RealmTester.java (-168 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2006 Brad Reynolds and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     Brad Reynolds - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.tests.databinding;
13
14
import junit.framework.Assert;
15
16
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.runtime.AssertionFailedException;
18
19
/**
20
 * Aids in the testing of Realms.
21
 * 
22
 * @since 3.2
23
 */
24
public class RealmTester {
25
26
	/**
27
	 * Sets the default realm without using Realm.runWithDefault() for testing
28
	 * purposes.
29
	 * 
30
	 * @param realm
31
	 */
32
	public static void setDefault(Realm realm) {
33
		CurrentRealm.setDefault(realm);
34
	}
35
36
	/**
37
	 * Runs the provided <code>runnable</code> when the realm is both current
38
	 * and not current. It checks for AssertionFailedExceptions and if an
39
	 * exception occurs or doesn't occur as expected the test fails. The realm
40
	 * of an observable created before the method was invoked must be of type
41
	 * {@link CurrentRealm}. The default realm during the runnable invocation
42
	 * is set to an instance of {@link CurrentRealm} when the runnable is
43
	 * invoked.
44
	 * 
45
	 * @param runnable
46
	 */
47
	public static void exerciseCurrent(Runnable runnable) {
48
		CurrentRealm previousRealm = (CurrentRealm) Realm.getDefault();
49
		CurrentRealm realm = new CurrentRealm();
50
		setDefault(realm);
51
52
		try {
53
			realm.setCurrent(true);
54
			if (previousRealm != null) {
55
				previousRealm.setCurrent(true);
56
			}
57
58
			try {
59
				runnable.run();
60
			} catch (AssertionFailedException e) {
61
				Assert
62
						.fail("Correct realm, exception should not have been thrown");
63
			}
64
65
			realm.setCurrent(false);
66
			if (previousRealm != null) {
67
				previousRealm.setCurrent(false);
68
			}
69
70
			try {
71
				runnable.run();
72
				Assert
73
						.fail("Incorrect realm, exception should have been thrown");
74
			} catch (AssertionFailedException e) {
75
			}
76
		} finally {
77
			setDefault(previousRealm);
78
		}
79
	}
80
81
	/**
82
	 * Runs the provided <code>runnable</code> when the realm is both current
83
	 * and not current. It checks for AssertionFailedExceptions and if an
84
	 * exception occurs or doesn't occur as expected the test fails.
85
	 * 
86
	 * @param runnable
87
	 * @param realm
88
	 */
89
	public static void exerciseCurrent(Runnable runnable, CurrentRealm realm) {
90
		realm.setCurrent(true);
91
92
		try {
93
			runnable.run();
94
		} catch (AssertionFailedException e) {
95
			Assert.fail("Correct realm, exception should not have been thrown");
96
		}
97
98
		realm.setCurrent(false);
99
100
		try {
101
			runnable.run();
102
			Assert.fail("Incorrect realm, exception should have been thrown");
103
		} catch (AssertionFailedException e) {
104
		}
105
	}
106
107
	/**
108
	 * Realm that will delegate to another for all operations except calls to
109
	 * {@link #isCurrent()}. The current status can be set by the consumer to
110
	 * enable testing of realm checks.
111
	 * 
112
	 * @since 3.2
113
	 */
114
	public static class DelegatingRealm extends CurrentRealm {
115
		private Realm realm;
116
117
		public DelegatingRealm(Realm realm) {
118
			this.realm = realm;
119
		}
120
121
		protected void syncExec(Runnable runnable) {
122
			realm.exec(runnable);
123
		}
124
125
		public void asyncExec(Runnable runnable) {
126
			realm.asyncExec(runnable);
127
		}
128
	}
129
130
	/**
131
	 * Allows for the toggling of the current status of the realm. The
132
	 * asyncExec(...) implementations do nothing.
133
	 * 
134
	 * @since 3.2
135
	 */
136
	public static class CurrentRealm extends Realm {
137
		private boolean current;
138
139
		public CurrentRealm() {
140
			this(false);
141
		}
142
143
		public CurrentRealm(boolean current) {
144
			this.current = current;
145
		}
146
147
		public boolean isCurrent() {
148
			return current;
149
		}
150
151
		public void setCurrent(boolean current) {
152
			this.current = current;
153
		}
154
155
		protected void syncExec(Runnable runnable) {
156
			super.syncExec(runnable);
157
		}
158
159
		public void asyncExec(Runnable runnable) {
160
			throw new UnsupportedOperationException(
161
					"CurrentRealm does not support asyncExec(Runnable).");
162
		}
163
164
		protected static Realm setDefault(Realm realm) {
165
			return Realm.setDefault(realm);
166
		}
167
	}
168
}
(-)src/org/eclipse/jface/tests/databinding/EventTrackers.java (-175 lines)
Removed Link Here
1
/*******************************************************************************
2
 * Copyright (c) 2007 IBM Corporation and others.
3
 * All rights reserved. This program and the accompanying materials
4
 * are made available under the terms of the Eclipse Public License v1.0
5
 * which accompanies this distribution, and is available at
6
 * http://www.eclipse.org/legal/epl-v10.html
7
 *
8
 * Contributors:
9
 *     IBM Corporation - initial API and implementation
10
 ******************************************************************************/
11
12
package org.eclipse.jface.tests.databinding;
13
14
import java.util.List;
15
16
import org.eclipse.core.databinding.observable.ChangeEvent;
17
import org.eclipse.core.databinding.observable.IChangeListener;
18
import org.eclipse.core.databinding.observable.IObservable;
19
import org.eclipse.core.databinding.observable.list.IListChangeListener;
20
import org.eclipse.core.databinding.observable.list.ListChangeEvent;
21
import org.eclipse.core.databinding.observable.map.IMapChangeListener;
22
import org.eclipse.core.databinding.observable.map.MapChangeEvent;
23
import org.eclipse.core.databinding.observable.set.ISetChangeListener;
24
import org.eclipse.core.databinding.observable.set.SetChangeEvent;
25
import org.eclipse.core.databinding.observable.value.IObservableValue;
26
import org.eclipse.core.databinding.observable.value.IValueChangeListener;
27
import org.eclipse.core.databinding.observable.value.ValueChangeEvent;
28
29
/**
30
 * Implementations of change listeners that keep track of the number of times an
31
 * event fires.
32
 * 
33
 * @since 1.1
34
 */
35
public class EventTrackers {
36
	public static class ChangeEventTracker implements IChangeListener {
37
		public int count;
38
39
		public ChangeEvent event;
40
41
		/**
42
		 * Queue that the listener will add itself too when it is notified of an
43
		 * event. Used to determine order of notifications of listeners.
44
		 */
45
		public final List notificationQueue;
46
47
		public ChangeEventTracker() {
48
			notificationQueue = null;
49
		}
50
51
		public ChangeEventTracker(List notificationQueue) {
52
			this.notificationQueue = notificationQueue;
53
		}
54
55
		public void handleChange(ChangeEvent event) {
56
			count++;
57
			this.event = event;
58
			if (notificationQueue != null) {
59
				notificationQueue.add(this);
60
			}
61
		}
62
		
63
		/**
64
		 * Convenience method to register the listener on an observable allowing for one line setup.
65
		 * <pre><code>
66
		 * ChangeEventTracker listener = new ChangeEventTracker().register(observable);
67
		 * </code></pre>
68
		 * 
69
		 * @param observable
70
		 * @return
71
		 */
72
		public ChangeEventTracker register(IObservable observable) {
73
			observable.addChangeListener(this);
74
			return this;
75
		}
76
	}
77
78
	public static class ValueChangeEventTracker implements IValueChangeListener {
79
		public int count;
80
81
		public ValueChangeEvent event;
82
83
		public ValueChangeEventTracker() {
84
		}
85
86
		public void handleValueChange(ValueChangeEvent event) {
87
			count++;
88
			this.event = event;
89
		}
90
		
91
		/**
92
		 * Convenience method to register the listener on an observable allowing for one line setup.
93
		 * <pre><code>
94
		 * ValueChangeEventTracker listener = new ValueChangeEventTracker().register(observable);
95
		 * </code></pre>
96
		 * 
97
		 * @param observable
98
		 * @return
99
		 */
100
		public ValueChangeEventTracker register(IObservableValue observable) {
101
			observable.addValueChangeListener(this);
102
			return this;
103
		}
104
	}
105
106
	public static class MapChangeEventTracker implements IMapChangeListener {
107
		public int count;
108
109
		public MapChangeEvent event;
110
111
		public MapChangeEventTracker() {
112
		}
113
114
		public void handleMapChange(MapChangeEvent event) {
115
			count++;
116
			this.event = event;
117
		}
118
	}
119
120
	public static class ListChangeEventTracker implements IListChangeListener {
121
		public int count;
122
123
		public ListChangeEvent event;
124
		
125
		/**
126
		 * Queue that the listener will add itself too when it is notified of an
127
		 * event. Used to determine order of notifications of listeners.
128
		 */
129
		public final List notificationQueue;
130
131
		public ListChangeEventTracker() {
132
			notificationQueue = null;
133
		}
134
		
135
		public ListChangeEventTracker(List notificationQueue) {
136
			this.notificationQueue = notificationQueue;
137
		}
138
139
		public void handleListChange(ListChangeEvent event) {
140
			count++;
141
			this.event = event;
142
			if (notificationQueue != null) {
143
				notificationQueue.add(this);
144
			}
145
		}
146
	}
147
	
148
	public static class SetChangeEventTracker implements ISetChangeListener {
149
		public int count;
150
151
		public SetChangeEvent event;
152
		
153
		/**
154
		 * Queue that the listener will add itself too when it is notified of an
155
		 * event. Used to determine order of notifications of listeners.
156
		 */
157
		public final List notificationQueue;
158
159
		public SetChangeEventTracker() {
160
			notificationQueue = null;
161
		}
162
		
163
		public SetChangeEventTracker(List notificationQueue) {
164
			this.notificationQueue = notificationQueue;
165
		}
166
167
		public void handleSetChange(SetChangeEvent event) {
168
			count++;
169
			this.event = event;
170
			if (notificationQueue != null) {
171
				notificationQueue.add(this);
172
			}
173
		}
174
	}
175
}
(-)src/org/eclipse/core/tests/internal/databinding/internal/beans/JavaBeanObservableValueTest.java (-3 / +3 lines)
Lines 26-34 Link Here
26
import org.eclipse.core.databinding.observable.value.ComputedValue;
26
import org.eclipse.core.databinding.observable.value.ComputedValue;
27
import org.eclipse.core.databinding.observable.value.IObservableValue;
27
import org.eclipse.core.databinding.observable.value.IObservableValue;
28
import org.eclipse.core.internal.databinding.internal.beans.JavaBeanObservableValue;
28
import org.eclipse.core.internal.databinding.internal.beans.JavaBeanObservableValue;
29
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
29
import org.eclipse.jface.databinding.conformance.ObservableValueContractTest;
30
import org.eclipse.jface.conformance.databinding.ObservableValueContractTest;
30
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
31
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
31
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
32
import org.eclipse.jface.examples.databinding.model.SimplePerson;
32
import org.eclipse.jface.examples.databinding.model.SimplePerson;
33
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
33
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
34
34
(-)src/org/eclipse/core/tests/internal/databinding/internal/beans/JavaBeanObservableArrayBasedListTest.java (-1 / +1 lines)
Lines 22-30 Link Here
22
import org.eclipse.core.databinding.observable.list.ListChangeEvent;
22
import org.eclipse.core.databinding.observable.list.ListChangeEvent;
23
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
23
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
24
import org.eclipse.core.internal.databinding.internal.beans.JavaBeanObservableList;
24
import org.eclipse.core.internal.databinding.internal.beans.JavaBeanObservableList;
25
import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker;
25
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
27
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
27
import org.eclipse.jface.tests.databinding.EventTrackers.ListChangeEventTracker;
28
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.swt.widgets.Display;
29
29
30
/**
30
/**
(-)src/org/eclipse/core/tests/internal/databinding/internal/beans/JavaBeanObservableListTest.java (-1 / +1 lines)
Lines 22-30 Link Here
22
import org.eclipse.core.databinding.observable.list.ListChangeEvent;
22
import org.eclipse.core.databinding.observable.list.ListChangeEvent;
23
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
23
import org.eclipse.core.databinding.observable.list.ListDiffEntry;
24
import org.eclipse.core.internal.databinding.internal.beans.JavaBeanObservableList;
24
import org.eclipse.core.internal.databinding.internal.beans.JavaBeanObservableList;
25
import org.eclipse.jface.databinding.conformance.util.ListChangeEventTracker;
25
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
27
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
27
import org.eclipse.jface.tests.databinding.EventTrackers.ListChangeEventTracker;
28
import org.eclipse.swt.widgets.Display;
28
import org.eclipse.swt.widgets.Display;
29
29
30
/**
30
/**
(-)src/org/eclipse/core/tests/databinding/DatabindingContextTest.java (-2 / +2 lines)
Lines 29-37 Link Here
29
import org.eclipse.core.databinding.validation.IValidator;
29
import org.eclipse.core.databinding.validation.IValidator;
30
import org.eclipse.core.databinding.validation.ValidationStatus;
30
import org.eclipse.core.databinding.validation.ValidationStatus;
31
import org.eclipse.core.runtime.IStatus;
31
import org.eclipse.core.runtime.IStatus;
32
import org.eclipse.jface.databinding.conformance.util.ChangeEventTracker;
33
import org.eclipse.jface.databinding.conformance.util.ValueChangeEventTracker;
32
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
34
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
33
import org.eclipse.jface.tests.databinding.EventTrackers.ChangeEventTracker;
34
import org.eclipse.jface.tests.databinding.EventTrackers.ValueChangeEventTracker;
35
35
36
public class DatabindingContextTest extends AbstractDefaultRealmTestCase {
36
public class DatabindingContextTest extends AbstractDefaultRealmTestCase {
37
	private DataBindingContext dbc;
37
	private DataBindingContext dbc;
(-)src/org/eclipse/core/tests/databinding/observable/value/AbstractObservableValueTest.java (-2 / +2 lines)
Lines 16-23 Link Here
16
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
17
import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
18
import org.eclipse.core.databinding.observable.value.ValueDiff;
18
import org.eclipse.core.databinding.observable.value.ValueDiff;
19
import org.eclipse.jface.tests.databinding.RealmTester;
19
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
20
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
20
import org.eclipse.jface.databinding.conformance.util.RealmTester;
21
21
22
/**
22
/**
23
 * @since 3.2
23
 * @since 3.2
(-)src/org/eclipse/core/tests/databinding/observable/value/WritableValueTest.java (-4 / +4 lines)
Lines 18-27 Link Here
18
import org.eclipse.core.databinding.observable.Realm;
18
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
19
import org.eclipse.core.databinding.observable.value.IObservableValue;
20
import org.eclipse.core.databinding.observable.value.WritableValue;
20
import org.eclipse.core.databinding.observable.value.WritableValue;
21
import org.eclipse.jface.conformance.databinding.AbstractObservableValueContractDelegate;
21
import org.eclipse.jface.databinding.conformance.MutableObservableValueContractTest;
22
import org.eclipse.jface.conformance.databinding.MutableObservableValueContractTest;
22
import org.eclipse.jface.databinding.conformance.ObservableValueContractTest;
23
import org.eclipse.jface.conformance.databinding.ObservableValueContractTest;
23
import org.eclipse.jface.databinding.conformance.delegate.AbstractObservableValueContractDelegate;
24
import org.eclipse.jface.conformance.databinding.SuiteBuilder;
24
import org.eclipse.jface.databinding.conformance.util.SuiteBuilder;
25
import org.eclipse.jface.databinding.swt.SWTObservables;
25
import org.eclipse.jface.databinding.swt.SWTObservables;
26
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
26
import org.eclipse.jface.tests.databinding.AbstractDefaultRealmTestCase;
27
import org.eclipse.swt.widgets.Display;
27
import org.eclipse.swt.widgets.Display;
(-)src/org/eclipse/core/tests/databinding/observable/value/AbstractVetoableValueTest.java (-2 / +2 lines)
Lines 16-23 Link Here
16
import org.eclipse.core.databinding.observable.Realm;
16
import org.eclipse.core.databinding.observable.Realm;
17
import org.eclipse.core.databinding.observable.value.AbstractVetoableValue;
17
import org.eclipse.core.databinding.observable.value.AbstractVetoableValue;
18
import org.eclipse.core.databinding.observable.value.ValueDiff;
18
import org.eclipse.core.databinding.observable.value.ValueDiff;
19
import org.eclipse.jface.tests.databinding.RealmTester;
19
import org.eclipse.jface.databinding.conformance.util.CurrentRealm;
20
import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
20
import org.eclipse.jface.databinding.conformance.util.RealmTester;
21
21
22
/**
22
/**
23
 * @since 3.2
23
 * @since 3.2
(-)META-INF/MANIFEST.MF (-1 / +2 lines)
Lines 14-19 Link Here
14
 org.eclipse.core.runtime,
14
 org.eclipse.core.runtime,
15
 org.eclipse.jface.examples.databinding,
15
 org.eclipse.jface.examples.databinding,
16
 org.eclipse.core.databinding.beans,
16
 org.eclipse.core.databinding.beans,
17
 org.eclipse.jface.databinding
17
 org.eclipse.jface.databinding,
18
 org.eclipse.jface.tests.databinding.conformance
18
Import-Package: com.ibm.icu.text
19
Import-Package: com.ibm.icu.text
19
20
(-)src/org/eclipse/jface/tests/databinding/scenarios/ScenariosTestCase.java (-1 / +1 lines)
Lines 17-25 Link Here
17
17
18
import org.eclipse.core.databinding.DataBindingContext;
18
import org.eclipse.core.databinding.DataBindingContext;
19
import org.eclipse.core.databinding.observable.Realm;
19
import org.eclipse.core.databinding.observable.Realm;
20
import org.eclipse.jface.databinding.conformance.util.RealmTester;
20
import org.eclipse.jface.databinding.swt.SWTObservables;
21
import org.eclipse.jface.databinding.swt.SWTObservables;
21
import org.eclipse.jface.examples.databinding.model.SampleData;
22
import org.eclipse.jface.examples.databinding.model.SampleData;
22
import org.eclipse.jface.tests.databinding.RealmTester;
23
import org.eclipse.swt.SWT;
23
import org.eclipse.swt.SWT;
24
import org.eclipse.swt.layout.FillLayout;
24
import org.eclipse.swt.layout.FillLayout;
25
import org.eclipse.swt.widgets.Button;
25
import org.eclipse.swt.widgets.Button;

Return to bug 182059