Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: b5a9682dd1322d37c9202bf9bd71e3acb0d22411 (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
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
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
/*******************************************************************************
 * Copyright (c) 2008 Oracle and Geensys.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     Oracle and Geensys - initial API and implementation
 *******************************************************************************/
package org.eclipse.emf.teneo.eclipselink.elist.tests;

import java.lang.reflect.Field;
import java.util.ArrayList;

import junit.framework.TestCase;

import org.eclipse.emf.teneo.eclipselink.elist.IndirectEList;
import org.eclipse.persistence.internal.helper.Helper;
import org.eclipse.persistence.internal.security.PrivilegedAccessHelper;


public class IndirectEListTest extends TestCase {
	@SuppressWarnings("serial")
  protected static final class TestEmfIndirectEList<E> extends IndirectEList<E> {
		public boolean isDelegateNull() {
			return delegate == null;
		}
	}

	protected Field delegateField = null;
	protected TestEmfIndirectEList<Object> indirectEList;
	
	public IndirectEListTest(String arg0) {
		super(arg0);
	}

	/* (non-Javadoc)
	 * @see junit.framework.TestCase#setUp()
	 */
	@Override
	protected void setUp() throws Exception {
		super.setUp();
		delegateField = Helper.getField(IndirectEList.class, "delegate");
		indirectEList = new TestEmfIndirectEList<Object>();
	}

	protected void assertDelegateInstantiated() throws Exception {
		Object delegate = getDelegateFromIndirectEList();
		assertNotNull("delegate should be instantiated", delegate);
	}

	protected void assertDelegateNotInstantiated()throws Exception {
		Object delegate = getDelegateFromIndirectEList();
		assertNull("delegate should not be instantiated", delegate);
	}

	Object getDelegateFromIndirectEList() throws IllegalAccessException {
		return PrivilegedAccessHelper.getValueFromField(delegateField, indirectEList);
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.hashCode()'
	 */
	public void testHashCode() throws Exception {
		indirectEList.hashCode();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.size()'
	 */
	public void testSize() throws Exception {
		indirectEList.size();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.isEmpty()'
	 */
	public void testIsEmpty() throws Exception {
		indirectEList.isEmpty();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.clear()'
	 */
	public void testClear() throws Exception {
		indirectEList.clear();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.basicListIterator(int)'
	 */
	public void testBasicListIteratorInt() throws Exception {
		try {
			indirectEList.basicListIterator(10);
			fail("Removing from temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.basicIterator()'
	 */
	public void testBasicIterator() throws Exception {
		indirectEList.basicIterator();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.basicListIterator()'
	 */
	public void testBasicListIterator() throws Exception {
		indirectEList.basicListIterator();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.basicList()'
	 */
	public void testBasicList() throws Exception {
		indirectEList.basicList();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.basicRemove(Object, NotificationChain)'
	 */
	public void testBasicRemove() throws Exception {
		try {
			indirectEList.basicRemove(null, null);
			fail("Removing from temporary EclipseLinkEList should throw an exception.");
		} catch (RuntimeException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.basicAdd(Object, NotificationChain)'
	 */
	public void testBasicAdd() throws Exception {
		try {
			indirectEList.basicAdd(null, null);
			fail("Adding to a temporary EclipseLinkEList should throw an exception.");
		} catch (RuntimeException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}


	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.add(int, Object)'
	 */
	public void testAddIntObject() throws Exception {
		try {
			indirectEList.add(1,null);
			fail("Adding to a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.add(Object)'
	 */
	public void testAddObject() throws Exception {
		indirectEList.add(null);
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.addAll(int, Collection)'
	 */
	public void testAddAllIntCollection() throws Exception {
		try {
			indirectEList.addAll(1, new ArrayList<Object>());
			fail("Adding to a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.addAll(Collection)'
	 */
	public void testAddAllCollection() throws Exception {
		indirectEList.addAll(new ArrayList<Object>());
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.clone()'
	 */
	public void testClone() throws Exception {
		indirectEList.clone();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.contains(Object)'
	 */
	public void testContainsObject() throws Exception {
		indirectEList.contains(null);
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.containsAll(Collection)'
	 */
	public void testContainsAllCollection() throws Exception {
		indirectEList.containsAll(new ArrayList<Object>());
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.equals(Object)'
	 */
	public void testEqualsObject() throws Exception {
		indirectEList.equals(null);
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.get(int)'
	 */
	public void testGetInt() throws Exception {
		try {
			indirectEList.get(0);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.getValueHolder()'
	 */
	public void testGetValueHolder() throws Exception {
		indirectEList.getValueHolder();
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.hasBeenRegistered()'
	 */
	public void testHasBeenRegistered() throws Exception {
		indirectEList.hasBeenRegistered();
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.indexOf(Object)'
	 */
	public void testIndexOfObject() throws Exception {
		indirectEList.indexOf(null);
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.isInstantiated()'
	 */
	public void testIsInstantiated() throws Exception {
		indirectEList.isInstantiated();
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.iterator()'
	 */
	public void testIterator() throws Exception {
		indirectEList.iterator();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.lastIndexOf(Object)'
	 */
	public void testLastIndexOfObject() throws Exception {
		indirectEList.lastIndexOf(null);
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.listIterator()'
	 */
	public void testListIterator() throws Exception {
		indirectEList.listIterator();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.listIterator(int)'
	 */
	public void testListIteratorInt() throws Exception {
		try{
			indirectEList.listIterator(10);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.remove(int)'
	 */
	public void testRemoveInt() throws Exception {
		try {
			indirectEList.remove(1);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.remove(Object)'
	 */
	public void testRemoveObject() throws Exception {
		indirectEList.remove(null);
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.removeAll(Collection)'
	 */
	public void testRemoveAllCollection() throws Exception {
		indirectEList.removeAll(new ArrayList<Object>());
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.removeElement(Object)'
	 */
	public void testRemoveElement() throws Exception {
		indirectEList.removeElement(null);
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.removeElementAt(int)'
	 */
	public void testRemoveElementAt() throws Exception {
		try {
			indirectEList.removeElementAt(1);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.retainAll(Collection)'
	 */
	public void testRetainAllCollection() throws Exception {
		indirectEList.retainAll(new ArrayList<Object>());
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.set(int, Object)'
	 */
	public void testSetIntObject() throws Exception {
		try {
			indirectEList.set(1,null);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.setElementAt(Object, int)'
	 */
	public void testSetElementAt() throws Exception {
		try {
			indirectEList.setElementAt(null, 1);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.setValueHolder(ValueHolderInterface)'
	 */
	public void testSetValueHolder() throws Exception {
		indirectEList.setValueHolder(null);
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.subList(int, int)'
	 */
	public void testSubListIntInt() throws Exception {
		try {
			indirectEList.subList(1,2);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.toArray()'
	 */
	public void testToArray() throws Exception {
		indirectEList.toArray();
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.toArray(Object[])'
	 */
	public void testToArrayObjectArray() throws Exception {
		indirectEList.toArray(new Object[]{});
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.toString()'
	 */
	public void testToString() throws Exception {
		indirectEList.toString();
		// ValueHolder class (not QueryBasedValueHolder and other
		// value holders that lazily load objects) always say
		// they are instantiated which will result in the instantiation
		// of an empty List in the ValueHolder
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.getEclipseLinkPropertyChangeListener()'
	 */
	public void testGetEclipseLinkPropertyChangeListener() throws Exception {
		indirectEList.getEclipseLinkPropertyChangeListener();
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.hasEclipseLinkPropertyChangeListener()'
	 */
	public void testHasEclipseLinkPropertyChangeListener() throws Exception {
		indirectEList.hasEclipseLinkPropertyChangeListener();
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.setEclipseLinkPropertyChangeListener(PropertyChangeListener)'
	 */
	public void testSetEclipseLinkPropertyChangeListener() throws Exception {
		indirectEList.setEclipseLinkPropertyChangeListener(null);
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.getEclipseLinkAttributeName()'
	 */
	public void testGetEclipseLinkAttributeName() throws Exception {
		indirectEList.getEclipseLinkAttributeName();
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.setEclipseLinkAttributeName(String)'
	 */
	public void testSetEclipseLinkAttributeName() throws Exception {
		indirectEList.setEclipseLinkAttributeName(null);
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.move(int, Object)'
	 */
	public void testMoveIntObject() throws Exception {
		try {
			indirectEList.move(1,null);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.move(int, int)'
	 */
	public void testMoveIntInt() throws Exception {
		try {
			indirectEList.move(1,2);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.addUnique(int, Object)'
	 */
	public void testAddUniqueIntObject() throws Exception {
		try {
			indirectEList.addUnique(1, null);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.addUnique(Object)'
	 */
	public void testAddUniqueObject() throws Exception {
		indirectEList.addUnique(null);
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.basicGet(int)'
	 */
	public void testBasicGetInt() throws Exception {
		try {
			indirectEList.basicGet(0);
			fail("Using a temporary EclipseLinkEList should throw an exception.");
		} catch (IndexOutOfBoundsException e) {
			// expected but we are only testing for delegate instantiation
		}
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.setUnique(int, Object)'
	 */
	public void testSetUniqueIntObject() throws Exception {
		indirectEList.setUnique(0, null);
		assertDelegateInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.ensureCapacity(int)'
	 */
	public void testEnsureCapacity() throws Exception {
		indirectEList.ensureCapacity(1);
		assertDelegateNotInstantiated();
	}

	/*
	 * ListTest method for 'org.eclipse.emf.teneo.eclipselink.elist.EmfIndirectEList.trimToSize()'
	 */
	public void testTrimToSize() throws Exception {
		indirectEList.trimToSize();
		assertDelegateNotInstantiated();
	}

}

Back to the top