< prev index next >

test/jdk/java/util/Collections/AddAll.java

Print this page
@@ -1,7 +1,7 @@
  /*
-  * Copyright (c) 2003, Oracle and/or its affiliates. All rights reserved.
+  * Copyright (c) 2003, 2026, Oracle and/or its affiliates. All rights reserved.
   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   *
   * This code is free software; you can redistribute it and/or modify it
   * under the terms of the GNU General Public License version 2 only, as
   * published by the Free Software Foundation.

@@ -25,12 +25,16 @@
   * @test
   * @bug     4822887
   * @summary Basic test for Collections.addAll
   * @author  Josh Bloch
   * @key randomness
+  * @library /test/lib
+  * @run main AddAll
   */
  
+ import jdk.test.lib.valueclass.AsValueClass;
+ import java.io.IOException;
  import java.util.ArrayList;
  import java.util.Arrays;
  import java.util.Collection;
  import java.util.Collections;
  import java.util.HashSet;

@@ -44,20 +48,28 @@
      public static void main(String[] args) {
          test(new ArrayList<Integer>());
          test(new LinkedList<Integer>());
          test(new HashSet<Integer>());
          test(new LinkedHashSet<Integer>());
+         testPoint(new ArrayList<Point>());
      }
  
      private static Random rnd = new Random();
  
+     @AsValueClass
+     static class Point {
+         int x;
+         int y;
+         Point(int x, int y) { this.x = x; this.y = y; }
+     }
+ 
      static void test(Collection<Integer> c) {
          int x = 0;
          for (int i = 0; i < N; i++) {
              int rangeLen = rnd.nextInt(10);
              if (Collections.addAll(c, range(x, x + rangeLen)) !=
-                 (rangeLen != 0))
+                     (rangeLen != 0))
                  throw new RuntimeException("" + rangeLen);
              x += rangeLen;
          }
          if (c instanceof List) {
              if (!c.equals(Arrays.asList(range(0, x))))

@@ -72,6 +84,24 @@
          Integer[] result = new Integer[to - from];
          for (int i = from, j=0; i < to; i++, j++)
              result[j] = new Integer(i);
          return result;
      }
+ 
+     static void testPoint(Collection<Point> c) {
+         int x = 0;
+         for (int i = 0; i < N; i++) {
+             int rangeLen = rnd.nextInt(10);
+             if (Collections.addAll(c, rangePoint(x, x + rangeLen)) !=
+                     (rangeLen != 0))
+                 throw new RuntimeException("" + rangeLen);
+             x += rangeLen;
+         }
+     }
+ 
+     private static Point[] rangePoint(int from, int to) {
+         Point[] result = new Point[to - from];
+         for (int i = from, j = 0; i < to; i++, j++)
+             result[j] = new Point(i, i);
+         return result;
+     }
  }
< prev index next >