01: /*******************************************************************************
02: * Copyright (c) 2006 Brad Reynolds and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Brad Reynolds - initial API and implementation
10: ******************************************************************************/package org.eclipse.core.tests.databinding.observable.value;
11:
12: import junit.framework.TestCase;
13:
14: import org.eclipse.core.databinding.observable.Realm;
15: import org.eclipse.core.databinding.observable.value.AbstractObservableValue;
16: import org.eclipse.core.databinding.observable.value.ValueDiff;
17: import org.eclipse.jface.tests.databinding.RealmTester;
18: import org.eclipse.jface.tests.databinding.RealmTester.CurrentRealm;
19:
20: /**
21: * @since 3.2
22: */
23: public class AbstractObservableValueTest extends TestCase {
24: public void testSetValueRealmChecks() throws Exception {
25: RealmTester.exerciseCurrent(new Runnable() {
26: public void run() {
27: ObservableValueStub observable = new ObservableValueStub();
28: try {
29: observable.setValue(null);
30: } catch (UnsupportedOperationException e) {
31: // do nothing
32: }
33: }
34: });
35: }
36:
37: public void testSetValueInvokesDoSetValue() throws Exception {
38: class ValueStub extends ObservableValueStub {
39: int doSetValue;
40:
41: ValueStub(Realm realm) {
42: super (realm);
43: }
44:
45: protected void doSetValue(Object value) {
46: doSetValue++;
47: }
48: }
49:
50: Realm realm = new CurrentRealm(true);
51: ValueStub stub = new ValueStub(realm);
52: assertEquals(0, stub.doSetValue);
53: stub.setValue(new Object());
54: assertEquals("doSetValue should have been invoked", 1,
55: stub.doSetValue);
56: }
57:
58: public void testFireValueChangeRealmChecks() throws Exception {
59: RealmTester.exerciseCurrent(new Runnable() {
60: public void run() {
61: ObservableValueStub observable = new ObservableValueStub();
62: observable.fireValueChange(null);
63: }
64: });
65: }
66:
67: private static class ObservableValueStub extends
68: AbstractObservableValue {
69: ObservableValueStub() {
70: super (Realm.getDefault());
71: }
72:
73: private ObservableValueStub(Realm realm) {
74: super (realm);
75: }
76:
77: protected Object doGetValue() {
78: return null;
79: }
80:
81: public Object getValueType() {
82: return null;
83: }
84:
85: protected void fireValueChange(ValueDiff diff) {
86: super.fireValueChange(diff);
87: }
88: }
89: }
|