ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/tck/CopyOnWriteArrayListTest.java
(Generate patch)

Comparing jsr166/src/test/tck/CopyOnWriteArrayListTest.java (file contents):
Revision 1.5 by dl, Thu Sep 25 11:02:41 2003 UTC vs.
Revision 1.9 by jsr166, Mon Nov 16 04:57:10 2009 UTC

# Line 1 | Line 1
1   /*
2 < * Written by members of JCP JSR-166 Expert Group and released to the
3 < * public domain. Use, modify, and redistribute this code in any way
4 < * without acknowledgement. Other contributors include Andrew Wright,
5 < * Jeffrey Hayes, Pat Fischer, Mike Judd.
2 > * Written by Doug Lea with assistance from members of JCP JSR-166
3 > * Expert Group and released to the public domain, as explained at
4 > * http://creativecommons.org/licenses/publicdomain
5 > * Other contributors include Andrew Wright, Jeffrey Hayes,
6 > * Pat Fisher, Mike Judd.
7   */
8  
9   import junit.framework.*;
# Line 11 | Line 12 | import java.util.concurrent.*;
12   import java.io.*;
13  
14   public class CopyOnWriteArrayListTest extends JSR166TestCase{
15 <    
15 >
16      public static void main(String[] args) {
17 <        junit.textui.TestRunner.run (suite());  
17 >        junit.textui.TestRunner.run (suite());
18      }
19  
20      public static Test suite() {
# Line 23 | Line 24 | public class CopyOnWriteArrayListTest ex
24      static CopyOnWriteArrayList populatedArray(int n){
25          CopyOnWriteArrayList a = new CopyOnWriteArrayList();
26          assertTrue(a.isEmpty());
27 <        for (int i = 0; i < n; ++i)
27 >        for (int i = 0; i < n; ++i)
28              a.add(new Integer(i));
29          assertFalse(a.isEmpty());
30          assertEquals(n, a.size());
# Line 47 | Line 48 | public class CopyOnWriteArrayListTest ex
48          for (int i = 0; i < SIZE-1; ++i)
49              ints[i] = new Integer(i);
50          CopyOnWriteArrayList a = new CopyOnWriteArrayList(ints);
51 <        for (int i = 0; i < SIZE; ++i)
51 >        for (int i = 0; i < SIZE; ++i)
52              assertEquals(ints[i], a.get(i));
53      }
54  
# Line 59 | Line 60 | public class CopyOnWriteArrayListTest ex
60          for (int i = 0; i < SIZE-1; ++i)
61              ints[i] = new Integer(i);
62          CopyOnWriteArrayList a = new CopyOnWriteArrayList(Arrays.asList(ints));
63 <        for (int i = 0; i < SIZE; ++i)
63 >        for (int i = 0; i < SIZE; ++i)
64              assertEquals(ints[i], a.get(i));
65      }
66 <        
66 >
67  
68      /**
69       *   addAll  adds each element from the given collection
# Line 140 | Line 141 | public class CopyOnWriteArrayListTest ex
141      }
142  
143      /**
144 <     * adding at an index places it in the indindicated index
144 >     * adding at an index places it in the indicated index
145       */
146      public void testAddIndex() {
147          CopyOnWriteArrayList full = populatedArray(3);
# Line 173 | Line 174 | public class CopyOnWriteArrayListTest ex
174          assertEquals(a.hashCode(), b.hashCode());
175      }
176  
177 <    
177 >
178      /**
179       *   containsAll returns true for collection with subset of elements
180       */
# Line 225 | Line 226 | public class CopyOnWriteArrayListTest ex
226      }
227  
228      /**
229 <     *   iterator() returns an iterator containing the elements of the list
229 >     *   iterator() returns an iterator containing the elements of the list
230       */
231      public void testIterator() {
232          CopyOnWriteArrayList full = populatedArray(SIZE);
233          Iterator i = full.iterator();
234          int j;
235 <        for(j = 0; i.hasNext(); j++)
235 >        for (j = 0; i.hasNext(); j++)
236              assertEquals(j, ((Integer)i.next()).intValue());
237          assertEquals(SIZE, j);
238      }
# Line 259 | Line 260 | public class CopyOnWriteArrayListTest ex
260          for (int i = 0; i < 3; ++i) {
261              assertTrue(s.indexOf(String.valueOf(i)) >= 0);
262          }
263 <    }        
263 >    }
264  
265      /**
266       *   lastIndexOf returns the index for the given object
# Line 290 | Line 291 | public class CopyOnWriteArrayListTest ex
291          CopyOnWriteArrayList full = populatedArray(SIZE);
292          ListIterator i = full.listIterator();
293          int j;
294 <        for(j = 0; i.hasNext(); j++)
294 >        for (j = 0; i.hasNext(); j++)
295              assertEquals(j, ((Integer)i.next()).intValue());
296          assertEquals(SIZE, j);
297      }
# Line 302 | Line 303 | public class CopyOnWriteArrayListTest ex
303          CopyOnWriteArrayList full = populatedArray(3);
304          ListIterator i = full.listIterator(1);
305          int j;
306 <        for(j = 0; i.hasNext(); j++)
306 >        for (j = 0; i.hasNext(); j++)
307              assertEquals(j+1, ((Integer)i.next()).intValue());
308          assertEquals(2, j);
309      }
# Line 380 | Line 381 | public class CopyOnWriteArrayListTest ex
381      public void testSubList() {
382          CopyOnWriteArrayList a = populatedArray(10);
383          assertTrue(a.subList(1,1).isEmpty());
384 <        for(int j = 0; j < 9; ++j) {
385 <            for(int i = j ; i < 10; ++i) {
384 >        for (int j = 0; j < 9; ++j) {
385 >            for (int i = j ; i < 10; ++i) {
386                  List b = a.subList(j,i);
387 <                for(int k = j; k < i; ++k) {
387 >                for (int k = j; k < i; ++k) {
388                      assertEquals(new Integer(k), b.get(k-j));
389                  }
390              }
# Line 410 | Line 411 | public class CopyOnWriteArrayListTest ex
411              c.add("asdadasd");
412              c.toArray(new Long[5]);
413              shouldThrow();
414 <        } catch(ArrayStoreException e){}
414 >        } catch (ArrayStoreException e){}
415      }
416  
417      /**
# Line 421 | Line 422 | public class CopyOnWriteArrayListTest ex
422              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
423              c.get(-1);
424              shouldThrow();
425 <        } catch(IndexOutOfBoundsException e){}
425 >        } catch (IndexOutOfBoundsException e){}
426      }
427 <    
427 >
428      /**
429       *   get throws an IndexOutOfBoundsException on a too high index
430       */
# Line 434 | Line 435 | public class CopyOnWriteArrayListTest ex
435              c.add("asdad");
436              c.get(100);
437              shouldThrow();
438 <        } catch(IndexOutOfBoundsException e){}
438 >        } catch (IndexOutOfBoundsException e){}
439      }
440  
441      /**
# Line 445 | Line 446 | public class CopyOnWriteArrayListTest ex
446              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
447              c.set(-1,"qwerty");
448              shouldThrow();
449 <        } catch(IndexOutOfBoundsException e){}
449 >        } catch (IndexOutOfBoundsException e){}
450      }
451 <    
451 >
452      /**
453       *   set throws an IndexOutOfBoundsException on a too high index
454       */
# Line 458 | Line 459 | public class CopyOnWriteArrayListTest ex
459              c.add("asdad");
460              c.set(100, "qwerty");
461              shouldThrow();
462 <        } catch(IndexOutOfBoundsException e){}
462 >        } catch (IndexOutOfBoundsException e){}
463      }
464  
465      /**
# Line 469 | Line 470 | public class CopyOnWriteArrayListTest ex
470              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
471              c.add(-1,"qwerty");
472              shouldThrow();
473 <        } catch(IndexOutOfBoundsException e){}
473 >        } catch (IndexOutOfBoundsException e){}
474      }
475 <    
475 >
476      /**
477       *   add throws an IndexOutOfBoundsException on a too high index
478       */
# Line 482 | Line 483 | public class CopyOnWriteArrayListTest ex
483              c.add("asdasdasd");
484              c.add(100, "qwerty");
485              shouldThrow();
486 <        } catch(IndexOutOfBoundsException e){}
486 >        } catch (IndexOutOfBoundsException e){}
487      }
488  
489      /**
# Line 493 | Line 494 | public class CopyOnWriteArrayListTest ex
494              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
495              c.remove(-1);
496              shouldThrow();
497 <        } catch(IndexOutOfBoundsException e){}
497 >        } catch (IndexOutOfBoundsException e){}
498      }
499  
500      /**
# Line 506 | Line 507 | public class CopyOnWriteArrayListTest ex
507              c.add("adasdasd");
508              c.remove(100);
509              shouldThrow();
510 <        } catch(IndexOutOfBoundsException e){}
510 >        } catch (IndexOutOfBoundsException e){}
511      }
512 <    
512 >
513      /**
514       *   addAll throws an IndexOutOfBoundsException on a negative index
515       */
# Line 517 | Line 518 | public class CopyOnWriteArrayListTest ex
518              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
519              c.addAll(-1,new LinkedList());
520              shouldThrow();
521 <        } catch(IndexOutOfBoundsException e){}
521 >        } catch (IndexOutOfBoundsException e){}
522      }
523 <    
523 >
524      /**
525       *   addAll throws an IndexOutOfBoundsException on a too high index
526       */
# Line 530 | Line 531 | public class CopyOnWriteArrayListTest ex
531              c.add("asdasdasd");
532              c.addAll(100, new LinkedList());
533              shouldThrow();
534 <        } catch(IndexOutOfBoundsException e){}
534 >        } catch (IndexOutOfBoundsException e){}
535      }
536  
537      /**
# Line 541 | Line 542 | public class CopyOnWriteArrayListTest ex
542              CopyOnWriteArrayList c = new CopyOnWriteArrayList();
543              c.listIterator(-1);
544              shouldThrow();
545 <        } catch(IndexOutOfBoundsException e){}
545 >        } catch (IndexOutOfBoundsException e){}
546      }
547  
548      /**
# Line 554 | Line 555 | public class CopyOnWriteArrayListTest ex
555              c.add("asdasdas");
556              c.listIterator(100);
557              shouldThrow();
558 <        } catch(IndexOutOfBoundsException e){}
558 >        } catch (IndexOutOfBoundsException e){}
559      }
560  
561      /**
# Line 566 | Line 567 | public class CopyOnWriteArrayListTest ex
567              c.subList(-1,100);
568  
569              shouldThrow();
570 <        } catch(IndexOutOfBoundsException e){}
570 >        } catch (IndexOutOfBoundsException e){}
571      }
572  
573      /**
# Line 578 | Line 579 | public class CopyOnWriteArrayListTest ex
579              c.add("asdasd");
580              c.subList(1,100);
581              shouldThrow();
582 <        } catch(IndexOutOfBoundsException e){}
582 >        } catch (IndexOutOfBoundsException e){}
583      }
584  
585      /**
586       *   subList throws IndexOutOfBoundsException when the second index
587 <     *  is lower then the first
587 >     *  is lower then the first
588       */
589      public void testSubList3_IndexOutOfBoundsException() {
590          try {
# Line 591 | Line 592 | public class CopyOnWriteArrayListTest ex
592              c.subList(3,1);
593  
594              shouldThrow();
595 <        } catch(IndexOutOfBoundsException e){}
595 >        } catch (IndexOutOfBoundsException e){}
596      }
597  
598      /**
# Line 612 | Line 613 | public class CopyOnWriteArrayListTest ex
613              assertEquals(q.size(), r.size());
614              assertTrue(q.equals(r));
615              assertTrue(r.equals(q));
616 <        } catch(Exception e){
616 >        } catch (Exception e){
617              unexpectedException();
618          }
619      }
620 <    
620 >
621   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines