/* * 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 * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 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 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 7129185 * @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 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(); } @DataProvider(name = "Supplier>", parallel = true) public static Iterator navigableMapProvider() { return makeCheckedMaps().iterator(); } public static Collection makeCheckedMaps() { return Arrays.asList( new Object[]{"Collections.checkedMap(HashMap)", (Supplier) () -> {return Collections.checkedMap(new HashMap(), Integer.class, Integer.class);}}, new Object[]{"Collections.checkedMap(TreeSet(reverseOrder)", (Supplier) () -> {return Collections.checkedMap(new TreeMap(Collections.reverseOrder()), Integer.class, Integer.class);}}, new Object[]{"Collections.checkedMap(TreeSet).descendingSet()", (Supplier) () -> {return Collections.checkedMap(new TreeMap().descendingMap(), Integer.class, Integer.class);}}, new Object[]{"Collections.checkedNavigableMap(TreeSet)", (Supplier) () -> {return Collections.checkedNavigableMap(new TreeMap(), Integer.class, Integer.class);}}, new Object[]{"Collections.checkedNavigableMap(TreeSet(reverseOrder)", (Supplier) () -> {return Collections.checkedNavigableMap(new TreeMap(Collections.reverseOrder()), Integer.class, Integer.class);}}, new Object[]{"Collections.checkedNavigableMap().descendingSet()", (Supplier) () -> {return Collections.checkedNavigableMap(new TreeMap().descendingMap(), Integer.class, Integer.class);}} ); } }