Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 9deff98086c76813de11dccf8c5842a1382efd1e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/*******************************************************************************
 * Copyright (c) 2009, 2012 Oracle. All rights reserved.
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License 2.0, which accompanies this distribution
 * and is available at https://www.eclipse.org/legal/epl-2.0/.
 * 
 * Contributors:
 *     Oracle - initial API and implementation
 ******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.model;

import junit.framework.TestCase;
import org.eclipse.jpt.common.utility.internal.model.AbstractModel;
import org.eclipse.jpt.common.utility.internal.model.ChangeSupport;
import org.eclipse.jpt.common.utility.internal.model.SingleAspectChangeSupport;
import org.eclipse.jpt.common.utility.model.Model;
import org.eclipse.jpt.common.utility.model.listener.CollectionChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.CollectionChangeListener;
import org.eclipse.jpt.common.utility.model.listener.ListChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.ListChangeListener;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeAdapter;
import org.eclipse.jpt.common.utility.model.listener.PropertyChangeListener;
import org.eclipse.jpt.common.utility.model.listener.StateChangeListener;

@SuppressWarnings("nls")
public class SingleAspectChangeSupportTests extends TestCase {

	public SingleAspectChangeSupportTests(String name) {
		super(name);
	}

	public void testAddPropertyChangeListenerInvalidClass() {
		Model model = new StateTestModel();
		boolean exCaught = false;
		PropertyChangeListener listener = new PropertyChangeAdapter();
		try {
			model.addPropertyChangeListener("foo", listener);
			fail("bogus listener: " + listener);
		} catch (IllegalArgumentException ex) {
			exCaught = true;
		}
		assertTrue(exCaught);
	}

	public void testAddPropertyChangeListenerInvalidAspect() {
		Model model = new PropertyTestModel();
		boolean exCaught = false;
		PropertyChangeListener listener = new PropertyChangeAdapter();
		try {
			model.addPropertyChangeListener("bar", listener);
			fail("bogus listener: " + listener);
		} catch (IllegalArgumentException ex) {
			exCaught = true;
		}
		assertTrue(exCaught);
	}

	public void testAddCollectionChangeListenerInvalidClass() {
		Model model = new StateTestModel();
		boolean exCaught = false;
		CollectionChangeListener listener = new CollectionChangeAdapter();
		try {
			model.addCollectionChangeListener("foo", listener);
			fail("bogus listener: " + listener);
		} catch (IllegalArgumentException ex) {
			exCaught = true;
		}
		assertTrue(exCaught);
	}

	public void testAddCollectionChangeListenerInvalidAspect() {
		Model model = new CollectionTestModel();
		boolean exCaught = false;
		CollectionChangeListener listener = new CollectionChangeAdapter();
		try {
			model.addCollectionChangeListener("bar", listener);
			fail("bogus listener: " + listener);
		} catch (IllegalArgumentException ex) {
			exCaught = true;
		}
		assertTrue(exCaught);
	}

	public void testAddListChangeListenerInvalidClass() {
		Model model = new StateTestModel();
		boolean exCaught = false;
		ListChangeListener listener = new ListChangeAdapter();
		try {
			model.addListChangeListener("foo", listener);
			fail("bogus listener: " + listener);
		} catch (IllegalArgumentException ex) {
			exCaught = true;
		}
		assertTrue(exCaught);
	}

	public void testAddListChangeListenerInvalidAspect() {
		Model model = new ListTestModel();
		boolean exCaught = false;
		ListChangeListener listener = new ListChangeAdapter();
		try {
			model.addListChangeListener("bar", listener);
			fail("bogus listener: " + listener);
		} catch (IllegalArgumentException ex) {
			exCaught = true;
		}
		assertTrue(exCaught);
	}


	// ********** test models **********

	static class StateTestModel extends AbstractModel {
		StateTestModel() {
			super();
		}
		@Override
		protected ChangeSupport buildChangeSupport() {
			return new SingleAspectChangeSupport(this, StateChangeListener.class, null);
		}
	}

	static class PropertyTestModel extends AbstractModel {
		PropertyTestModel() {
			super();
		}
		@Override
		protected ChangeSupport buildChangeSupport() {
			return new SingleAspectChangeSupport(this, PropertyChangeListener.class, "foo");
		}
	}

	static class CollectionTestModel extends AbstractModel {
		CollectionTestModel() {
			super();
		}
		@Override
		protected ChangeSupport buildChangeSupport() {
			return new SingleAspectChangeSupport(this, CollectionChangeListener.class, "foo");
		}
	}

	static class ListTestModel extends AbstractModel {
		ListTestModel() {
			super();
		}
		@Override
		protected ChangeSupport buildChangeSupport() {
			return new SingleAspectChangeSupport(this, ListChangeListener.class, "foo");
		}
	}
}

Back to the top