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.AbstractVetoableValue;
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 AbstractVetoableValueTest extends TestCase {
24: public void testSetValueInvokesDoSetApprovedValue()
25: throws Exception {
26: class VetoableValue extends VetoableValueStub {
27: int count;
28: Object value;
29:
30: VetoableValue(Realm realm) {
31: super (realm);
32: }
33:
34: protected void doSetApprovedValue(Object value) {
35: count++;
36: this .value = value;
37: }
38: }
39:
40: Realm realm = new CurrentRealm(true);
41: VetoableValue vetoableValue = new VetoableValue(realm);
42: assertEquals(0, vetoableValue.count);
43: assertEquals(null, vetoableValue.value);
44:
45: Object value = new Object();
46: vetoableValue.setValue(value);
47: assertEquals(1, vetoableValue.count);
48: assertEquals(value, vetoableValue.value);
49: }
50:
51: public void testFireValueChangeRealmChecks() throws Exception {
52: RealmTester.exerciseCurrent(new Runnable() {
53: public void run() {
54: VetoableValueStub observable = new VetoableValueStub();
55: observable.fireValueChanging(null);
56: }
57: });
58: }
59:
60: private static class VetoableValueStub extends
61: AbstractVetoableValue {
62: VetoableValueStub() {
63: this (Realm.getDefault());
64: }
65:
66: VetoableValueStub(Realm realm) {
67: super (realm);
68: }
69:
70: protected void doSetApprovedValue(Object value) {
71: }
72:
73: protected Object doGetValue() {
74: return null;
75: }
76:
77: public Object getValueType() {
78: return null;
79: }
80:
81: protected boolean fireValueChanging(ValueDiff diff) {
82: return super.fireValueChanging(diff);
83: }
84: }
85: }
|