-
-
Notifications
You must be signed in to change notification settings - Fork 266
/
FeaturesEListTests.java
253 lines (204 loc) · 7.59 KB
/
FeaturesEListTests.java
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
/**
* This program and the accompanying materials
* are made available under the terms of the License
* which accompanies this distribution in the file LICENSE.txt
*/
package com.archimatetool.model.impl;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import org.eclipse.emf.ecore.InternalEObject;
import org.junit.Before;
import org.junit.Test;
import com.archimatetool.model.IArchimateElement;
import com.archimatetool.model.IArchimateFactory;
import com.archimatetool.model.IArchimatePackage;
import com.archimatetool.model.IFeature;
import com.archimatetool.model.IFeaturesEList;
import junit.framework.JUnit4TestAdapter;
@SuppressWarnings("nls")
public class FeaturesEListTests {
public static junit.framework.Test suite() {
return new JUnit4TestAdapter(FeaturesEListTests.class);
}
private IFeaturesEList list;
@Before
public void runBeforeEachTest() {
IArchimateElement element = IArchimateFactory.eINSTANCE.createArtifact();
list = new FeaturesEList(IFeature.class, (InternalEObject)element, IArchimatePackage.ARCHIMATE_CONCEPT__FEATURES);
}
@Test
public void putString() {
list.putString("name1", "value1");
assertEquals("name1", list.get(0).getName());
assertEquals("value1", list.get(0).getValue());
}
@Test
public void putStringValueChanged() {
list.putString("name1", "value1");
assertEquals("name1", list.get(0).getName());
assertEquals("value1", list.get(0).getValue());
list.putString("name1", "value2");
assertEquals("name1", list.get(0).getName());
assertEquals("value2", list.get(0).getValue());
}
@Test
public void putStringDefaultValue() {
list.putString("name1", "value", "default");
assertEquals("name1", list.get(0).getName());
assertEquals("value", list.get(0).getValue());
list.putString("name1", "default", "default");
assertTrue(list.isEmpty());
}
@Test
public void putInt() {
list.putInt("name1", 1);
assertEquals("name1", list.get(0).getName());
assertEquals("1", list.get(0).getValue());
}
@Test
public void putIntDefaultValue() {
list.putInt("name1", 1, 0);
assertEquals("name1", list.get(0).getName());
assertEquals("1", list.get(0).getValue());
list.putInt("name1", 1, 1);
assertTrue(list.isEmpty());
}
@Test
public void putBoolean() {
list.putBoolean("name1", true);
assertEquals("name1", list.get(0).getName());
assertEquals("true", list.get(0).getValue());
list.putBoolean("name1", false);
assertEquals("false", list.get(0).getValue());
}
@Test
public void putBooleanDefaultValue() {
list.putBoolean("name1", true, false);
assertEquals("name1", list.get(0).getName());
assertEquals("true", list.get(0).getValue());
list.putBoolean("name1", true, true);
assertTrue(list.isEmpty());
}
@Test
public void getString() {
list.putString("name1", "value1");
assertEquals("value1", list.getString("name1", ""));
}
@Test
public void getStringDefault() {
assertEquals("value1", list.getString("name1", "value1"));
}
@Test
public void getInt() {
list.putInt("name1", 1);
assertEquals(1, list.getInt("name1", 0));
}
@Test
public void getIntDefault() {
assertEquals(2, list.getInt("name1", 2));
}
@Test
public void getBoolean() {
list.putBoolean("name1", true);
assertEquals(true, list.getBoolean("name1", false));
}
@Test
public void getBooleanDefault() {
assertEquals(true, list.getBoolean("name1", true));
assertEquals(false, list.getBoolean("name1", false));
}
@Test
public void remove() {
list.putString("name1", "value1");
assertEquals("name1", list.get(0).getName());
assertEquals("value1", list.get(0).getValue());
list.remove("name1");
assertTrue(list.isEmpty());
}
@Test
public void has() {
assertFalse(list.has("name1"));
list.putString("name1", "value1");
assertTrue(list.has("name1"));
}
@Test
public void getFeature() {
list.putString("name1", "value1");
assertNotNull(list.getFeature("name1"));
assertNull(list.getFeature("bogus"));
}
@Test
public void noDuplicateFeature1() {
IFeature feature = IArchimateFactory.eINSTANCE.createFeature();
feature.setName("uniqueName");
feature.setValue("someValue");
// Add the feature
boolean result = list.add(feature);
assertTrue(result);
// Should not be able to add the first feature again
result = list.add(feature);
assertFalse(result);
// Should not be able to add the first feature again, even if name and value change
feature.setName("uniqueName2");
feature.setValue("someValue2");
result = list.add(feature);
assertFalse(result);
}
@Test
public void noDuplicateFeature2() {
IFeature feature = IArchimateFactory.eINSTANCE.createFeature();
feature.setName("uniqueName");
feature.setValue("someValue");
// Add the feature
boolean result = list.add(feature);
assertTrue(result);
// Should not be able to add a different feature object with the same name
IFeature feature2 = IArchimateFactory.eINSTANCE.createFeature();
feature2.setName("uniqueName");
feature2.setValue("someValue2");
result = list.add(feature2);
assertFalse(result);
}
@Test
public void noDuplicateFeature3() {
IFeature feature = IArchimateFactory.eINSTANCE.createFeature();
feature.setName("uniqueName");
feature.setValue("someValue");
// Add the feature
boolean result = list.add(feature);
assertTrue(result);
// Should be able to add a different feature object with a different name
IFeature feature2 = IArchimateFactory.eINSTANCE.createFeature();
feature2.setName("uniqueName2");
feature2.setValue("someValue2");
result = list.add(feature2);
assertTrue(result);
}
@Test
public void noDuplicateFeature4() {
// Create another list
IArchimateElement element = IArchimateFactory.eINSTANCE.createArtifact();
FeaturesEList list2 = new FeaturesEList(IFeature.class, (InternalEObject)element, IArchimatePackage.ARCHIMATE_CONCEPT__FEATURES);
// Add Feature to first list
IFeature feature1 = IArchimateFactory.eINSTANCE.createFeature();
feature1.setName("uniqueName");
feature1.setValue("someValue");
list.add(feature1);
// Add feature with same name to second list
IFeature feature2 = IArchimateFactory.eINSTANCE.createFeature();
feature2.setName("uniqueName");
feature2.setValue("someValue");
list2.add(feature2);
// Should not be able to add first list to second list
boolean result = list2.addAll(list);
assertFalse(result);
// remove it
list2.remove(feature2);
// Should be able to add it now
result = list2.addAll(list);
assertTrue(result);
}
}