2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package tests.api.java.util;
20 import dalvik.annotation.TestTargetNew;
21 import dalvik.annotation.TestTargets;
22 import dalvik.annotation.TestLevel;
23 import dalvik.annotation.TestTargetClass;
25 import java.util.Collection;
26 import java.util.ConcurrentModificationException;
27 import java.util.Iterator;
28 import java.util.LinkedList;
30 @TestTargetClass(ConcurrentModificationException.class)
31 public class ConcurrentModificationExceptionTest extends
32 junit.framework.TestCase {
34 static public class CollectionModifier implements Runnable {
37 boolean keepGoing = true;
39 public CollectionModifier(Collection c) {
43 public void stopNow() {
48 Object someItem = new Integer(-1);
57 * @tests java.util.ConcurrentModificationException#ConcurrentModificationException()
60 level = TestLevel.COMPLETE,
62 method = "ConcurrentModificationException",
65 public void test_Constructor() {
66 // Test for method java.util.ConcurrentModificationException()
67 Collection myCollection = new LinkedList();
68 Iterator myIterator = myCollection.iterator();
69 for (int counter = 0; counter < 50; counter++)
70 myCollection.add(new Integer(counter));
71 CollectionModifier cm = new CollectionModifier(myCollection);
72 Thread collectionSlapper = new Thread(cm);
74 collectionSlapper.start();
75 while (myIterator.hasNext())
77 } catch (ConcurrentModificationException e) {
82 // The exception should have been thrown--if the code flow makes it here
83 // the test has failed
84 fail("Failed to throw expected ConcurrentModificationException");
88 * @tests java.util.ConcurrentModificationException#ConcurrentModificationException(java.lang.String)
91 level = TestLevel.COMPLETE,
93 method = "ConcurrentModificationException",
94 args = {java.lang.String.class}
96 public void test_ConstructorLjava_lang_String() {
98 // java.util.ConcurrentModificationException(java.lang.String)
99 String errorMessage = "This is an error message";
101 // This is here to stop "unreachable code" unresolved problem
103 throw new ConcurrentModificationException(errorMessage);
104 } catch (ConcurrentModificationException e) {
105 assertTrue("Exception thrown without error message", e.getMessage()
106 .equals(errorMessage));
109 fail("Failed to throw expected ConcurrentModificationException");
113 * Sets up the fixture, for example, open a network connection. This method
114 * is called before a test is executed.
116 protected void setUp() {
120 * Tears down the fixture, for example, close a network connection. This
121 * method is called after a test is executed.
123 protected void tearDown() {