--- jsr166/src/test/jtreg/util/Collections/CheckedMapBash.java 2009/09/01 01:24:16 1.1 +++ jsr166/src/test/jtreg/util/Collections/CheckedMapBash.java 2015/10/18 17:34:26 1.10 @@ -1,5 +1,5 @@ /* - * Copyright 2003-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright (c) 2003, 2013, 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 @@ -16,92 +16,100 @@ * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * - * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, - * CA 95054 USA or visit www.sun.com if you need additional information or - * have any questions. + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA + * or visit www.oracle.com if you need additional information or have any + * questions. */ /* * @test - * @bug 4904067 5023830 + * @bug 4904067 5023830 7129185 8072015 * @summary Unit test for Collections.checkedMap * @author Josh Bloch + * @run testng CheckedMapBash + * @key randomness */ import java.util.*; +import java.util.function.Supplier; +import org.testng.annotations.Test; +import org.testng.annotations.DataProvider; + +import static org.testng.Assert.fail; +import static org.testng.Assert.assertTrue; public class CheckedMapBash { - static Random rnd = new Random(); - static Object nil = new Integer(0); + static final Random rnd = new Random(); + static final Object nil = new Integer(0); + static final int numItr = 100; + static final int mapSize = 100; + + @Test(dataProvider = "Bash.Supplier>") + public static void testCheckedMap(String description, Supplier> supplier) { + Map m = supplier.get(); + Object head = nil; + + for (int j=0; j> supplier) { + Map m = supplier.get(); for (int i=0; i bashNavigableMapProvider() { + ArrayList iters = new ArrayList<>(makeCheckedMaps()); + iters.ensureCapacity(numItr * iters.size()); + for (int each=1; each < numItr; each++) { + iters.addAll(makeCheckedMaps()); + } + return iters.iterator(); + } - if (!m.isEmpty()) - fail("New instance non empty."); - return m; + @DataProvider(name = "Supplier>", parallel = true) + public static Iterator navigableMapProvider() { + return makeCheckedMaps().iterator(); } - static void fail(String s) { - throw new RuntimeException(s); + public static Collection makeCheckedMaps() { + Object[][] params = { + {"Collections.checkedMap(HashMap)", + (Supplier) () -> Collections.checkedMap(new HashMap(), Integer.class, Integer.class)}, + {"Collections.checkedMap(TreeMap(reverseOrder))", + (Supplier) () -> Collections.checkedMap(new TreeMap(Collections.reverseOrder()), Integer.class, Integer.class)}, + {"Collections.checkedMap(TreeMap.descendingMap())", + (Supplier) () -> Collections.checkedMap(new TreeMap().descendingMap(), Integer.class, Integer.class)}, + {"Collections.checkedNavigableMap(TreeMap)", + (Supplier) () -> Collections.checkedNavigableMap(new TreeMap(), Integer.class, Integer.class)}, + {"Collections.checkedNavigableMap(TreeMap(reverseOrder))", + (Supplier) () -> Collections.checkedNavigableMap(new TreeMap(Collections.reverseOrder()), Integer.class, Integer.class)}, + {"Collections.checkedNavigableMap(TreeMap.descendingMap())", + (Supplier) () -> Collections.checkedNavigableMap(new TreeMap().descendingMap(), Integer.class, Integer.class)}, + }; + return Arrays.asList(params); } }