blob: f217b39b2d2bb9417c989bfa8cbcb359ca177137 (
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
|
/*******************************************************************************
* Copyright (c) 2009 Oracle. 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 - initial API and implementation
******************************************************************************/
package org.eclipse.jpt.common.utility.tests.internal.iterables;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
import org.eclipse.jpt.common.utility.internal.iterables.ListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.ListListIterable;
import org.eclipse.jpt.common.utility.internal.iterables.ReadOnlyCompositeListIterable;
@SuppressWarnings("nls")
public class ReadOnlyCompositeListIterableTests extends TestCase {
public ReadOnlyCompositeListIterableTests(String name) {
super(name);
}
public void testIterator() {
List<String> c1 = new ArrayList<String>();
c1.add("0");
c1.add("1");
c1.add("2");
c1.add("3");
ListIterable<String> li1 = new ListListIterable<String>(c1);
List<String> c2 = new ArrayList<String>();
c2.add("4");
c2.add("5");
c2.add("6");
c2.add("7");
ListIterable<String> li2 = new ListListIterable<String>(c2);
@SuppressWarnings("unchecked")
Iterable<String> composite = new ReadOnlyCompositeListIterable<String>(li1, li2);
int i = 0;
for (String s : composite) {
assertEquals(String.valueOf(i++), s);
}
}
public void testExtraElement1() {
List<String> c1 = new ArrayList<String>();
c1.add("0");
c1.add("1");
c1.add("2");
c1.add("3");
ListIterable<String> li1 = new ListListIterable<String>(c1);
Iterable<String> composite = new ReadOnlyCompositeListIterable<String>(li1, "4");
int i = 0;
for (String s : composite) {
assertEquals(String.valueOf(i++), s);
}
}
public void testExtraElement2() {
List<String> c1 = new ArrayList<String>();
c1.add("1");
c1.add("2");
c1.add("3");
ListIterable<String> li1 = new ListListIterable<String>(c1);
Iterable<String> composite = new ReadOnlyCompositeListIterable<String>("0", li1);
int i = 0;
for (String s : composite) {
assertEquals(String.valueOf(i++), s);
}
}
public void testCollectionOfIterables() {
List<String> c1 = new ArrayList<String>();
c1.add("0");
c1.add("1");
c1.add("2");
c1.add("3");
ListIterable<String> li1 = new ListListIterable<String>(c1);
List<String> c2 = new ArrayList<String>();
c2.add("4");
c2.add("5");
c2.add("6");
c2.add("7");
ListIterable<String> li2 = new ListListIterable<String>(c2);
List<ListIterable<String>> collection = new ArrayList<ListIterable<String>>();
collection.add(li1);
collection.add(li2);
ListIterable<ListIterable<String>> li = new ListListIterable<ListIterable<String>>(collection);
Iterable<String> composite = new ReadOnlyCompositeListIterable<String>(li);
int i = 0;
for (String s : composite) {
assertEquals(String.valueOf(i++), s);
}
}
public void testToString() {
List<String> c1 = new ArrayList<String>();
c1.add("0");
c1.add("1");
c1.add("2");
c1.add("3");
ListIterable<String> li1 = new ListListIterable<String>(c1);
List<String> c2 = new ArrayList<String>();
c2.add("4");
c2.add("5");
c2.add("6");
c2.add("7");
ListIterable<String> li2 = new ListListIterable<String>(c2);
@SuppressWarnings("unchecked")
Iterable<String> composite = new ReadOnlyCompositeListIterable<String>(li1, li2);
assertNotNull(composite.toString());
}
}
|