001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017:
018: package org.apache.harmony.luni.tests.java.util;
019:
020: import java.util.AbstractList;
021: import java.util.ArrayList;
022: import java.util.Collection;
023: import java.util.ConcurrentModificationException;
024: import java.util.List;
025: import java.util.Vector;
026:
027: import junit.framework.TestCase;
028:
029: public class ConcurrentModTest extends TestCase {
030:
031: /*
032: * Test method for 'java.util.AbstractList.subList(int, int)'
033: */
034: public void testGet() {
035: AbstractList al = new ArrayList();
036: Double one = new Double(1.0);
037: Double two = new Double(2.0);
038: Double three = new Double(3.0);
039: Double four = new Double(4.0);
040: al.add(one);
041: al.add(two);
042: al.add(three);
043: al.add(four);
044: List sub = al.subList(1, 3);
045: assertEquals(2, sub.size());
046: // the sub.get(1) is 3.0
047: assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
048: assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
049:
050: al.remove(1); // remove the 2.0
051:
052: try {
053: // illegal call the subList's method get(int).
054: sub.get(1);
055: fail("It should throws ConcurrentModificationException.");
056: } catch (ConcurrentModificationException e) {
057: return;
058: }
059: }
060:
061: /*
062: * Test method for 'java.util.AbstractList.subList(int, int)'
063: */
064: public void testSet() {
065: AbstractList al = new ArrayList();
066: Double one = new Double(1.0);
067: Double two = new Double(2.0);
068: Double three = new Double(3.0);
069: Double four = new Double(4.0);
070: al.add(one);
071: al.add(two);
072: al.add(three);
073: al.add(four);
074: List sub = al.subList(1, 3);
075: assertEquals(2, sub.size());
076: // the sub.get(1) is 3.0
077: assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
078: assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
079:
080: al.remove(1); // remove the 2.0
081:
082: try {
083: // illegal call the subList's method set(int,Object).
084: sub.set(1, two);
085: fail("It should throws ConcurrentModificationException.");
086: } catch (ConcurrentModificationException e) {
087: return;
088: }
089: }
090:
091: /*
092: * Test method for 'java.util.AbstractList.subList(int, int)'
093: */
094: public void testAdd() {
095: AbstractList al = new ArrayList();
096: Double one = new Double(1.0);
097: Double two = new Double(2.0);
098: Double three = new Double(3.0);
099: Double four = new Double(4.0);
100: al.add(one);
101: al.add(two);
102: al.add(three);
103: al.add(four);
104: List sub = al.subList(1, 3);
105: assertEquals(2, sub.size());
106: // the sub.get(1) is 3.0
107: assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
108: assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
109:
110: al.remove(1); // remove the 2.0
111:
112: try {
113: // illegal call the subList's method Add(int,Object).
114: sub.add(1, two);
115: fail("It should throws ConcurrentModificationException.");
116: } catch (ConcurrentModificationException e) {
117: return;
118: }
119: }
120:
121: /*
122: * Test method for 'java.util.AbstractList.subList(int, int)'
123: */
124: public void testRemove() {
125: AbstractList al = new ArrayList();
126: Double one = new Double(1.0);
127: Double two = new Double(2.0);
128: Double three = new Double(3.0);
129: Double four = new Double(4.0);
130: al.add(one);
131: al.add(two);
132: al.add(three);
133: al.add(four);
134: List sub = al.subList(1, 3);
135: assertEquals(2, sub.size());
136: // the sub.get(1) is 3.0
137: assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
138: assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
139:
140: al.remove(1); // remove the 2.0
141:
142: try {
143: // illegal call the subList's method remove(int).
144: sub.remove(1);
145: fail("It should throws ConcurrentModificationException.");
146: } catch (ConcurrentModificationException e) {
147: return;
148: }
149: }
150:
151: /*
152: * Test method for 'java.util.AbstractList.subList(int, int)'
153: */
154: public void testAddAll() {
155: AbstractList al = new ArrayList();
156: Double one = new Double(1.0);
157: Double two = new Double(2.0);
158: Double three = new Double(3.0);
159: Double four = new Double(4.0);
160: al.add(one);
161: al.add(two);
162: al.add(three);
163: al.add(four);
164: List sub = al.subList(1, 3);
165: assertEquals(2, sub.size());
166: // the sub.get(1) is 3.0
167: assertTrue(((Double) sub.get(1)).doubleValue() <= 3.0);
168: assertTrue(((Double) sub.get(1)).doubleValue() > 2.0);
169:
170: al.remove(1); // remove the 2.0
171:
172: try {
173: // illegal call the subList's method addAll(int,Collection).
174: Collection c = new Vector();
175: Double five = new Double(5.0);
176: c.add(five);
177: sub.addAll(1, c);
178: fail("It should throws ConcurrentModificationException.");
179: } catch (ConcurrentModificationException e) {
180: return;
181: }
182: }
183: }
|