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 org
.apache
.harmony
.tests
.java
.util
;
20 import java
.util
.Collection
;
21 import java
.util
.ConcurrentModificationException
;
22 import java
.util
.Iterator
;
23 import java
.util
.LinkedList
;
25 public class ConcurrentModificationExceptionTest
extends
26 junit
.framework
.TestCase
{
28 static public class CollectionModifier
implements Runnable
{
31 boolean keepGoing
= true;
33 public CollectionModifier(Collection c
) {
37 public void stopNow() {
42 Object someItem
= new Integer(-1);
51 * java.util.ConcurrentModificationException#ConcurrentModificationException()
53 public void test_Constructor() {
54 // Test for method java.util.ConcurrentModificationException()
55 Collection myCollection
= new LinkedList();
56 Iterator myIterator
= myCollection
.iterator();
57 for (int counter
= 0; counter
< 50; counter
++)
58 myCollection
.add(new Integer(counter
));
59 CollectionModifier cm
= new CollectionModifier(myCollection
);
60 Thread collectionSlapper
= new Thread(cm
);
62 collectionSlapper
.start();
63 while (myIterator
.hasNext())
65 } catch (ConcurrentModificationException e
) {
70 // The exception should have been thrown--if the code flow makes it here
71 // the test has failed
72 fail("Failed to throw expected ConcurrentModificationException");
76 * java.util.ConcurrentModificationException#ConcurrentModificationException(java.lang.String)
78 public void test_ConstructorLjava_lang_String() {
80 // java.util.ConcurrentModificationException(java.lang.String)
81 String errorMessage
= "This is an error message";
83 // This is here to stop "unreachable code" unresolved problem
85 throw new ConcurrentModificationException(errorMessage
);
86 } catch (ConcurrentModificationException e
) {
87 assertTrue("Exception thrown without error message", e
.getMessage()
88 .equals(errorMessage
));
91 fail("Failed to throw expected ConcurrentModificationException");
95 * Sets up the fixture, for example, open a network connection. This method
96 * is called before a test is executed.
98 protected void setUp() {
102 * Tears down the fixture, for example, close a network connection. This
103 * method is called after a test is executed.
105 protected void tearDown() {