ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/jsr166/jsr166/src/test/jtreg/util/Collections/CheckedMapBash.java
(Generate patch)

Comparing jsr166/src/test/jtreg/util/Collections/CheckedMapBash.java (file contents):
Revision 1.6 by jsr166, Sun Oct 11 00:58:42 2015 UTC vs.
Revision 1.12 by jsr166, Mon Jan 8 03:12:03 2018 UTC

# Line 23 | Line 23
23  
24   /*
25   * @test
26 < * @bug     4904067 5023830 7129185
26 > * @bug     4904067 5023830 7129185 8072015
27   * @summary Unit test for Collections.checkedMap
28   * @author  Josh Bloch
29   * @run testng CheckedMapBash
30   * @key randomness
31   */
32  
33 import java.util.*;
34 import java.util.function.Supplier;
35 import org.testng.annotations.Test;
33   import org.testng.annotations.DataProvider;
34 + import org.testng.annotations.Test;
35 +
36 + import java.util.ArrayList;
37 + import java.util.Arrays;
38 + import java.util.Collection;
39 + import java.util.Collections;
40 + import java.util.HashMap;
41 + import java.util.Iterator;
42 + import java.util.Map;
43 + import java.util.Random;
44 + import java.util.Set;
45 + import java.util.TreeMap;
46 + import java.util.function.Supplier;
47  
48   import static org.testng.Assert.fail;
39 import static org.testng.Assert.assertTrue;
49  
50   public class CheckedMapBash {
51      static final Random rnd = new Random();
# Line 53 | Line 62 | public class CheckedMapBash {
62              Object newHead;
63              do {
64                  newHead = new Integer(rnd.nextInt());
65 <            } while (m.containsKey(newHead));
65 >            } while (m.containsKey(newHead) || newHead.equals(nil));
66              m.put(newHead, head);
67              head = newHead;
68          }
# Line 99 | Line 108 | public class CheckedMapBash {
108      }
109  
110      @Test(dataProvider = "Supplier<Map<Integer,Integer>>")
111 <    public static void testCheckeMap2(String description, Supplier<Map<Integer,Integer>> supplier) {
111 >    public static void testCheckedMap2(String description, Supplier<Map<Integer,Integer>> supplier) {
112          Map m = supplier.get();
113          for (int i=0; i<mapSize; i++)
114              if (m.put(new Integer(i), new Integer(2*i)) != null)
115 <                fail("put returns a non-null value erroenously.");
115 >                fail("put returns a non-null value erroneously.");
116          for (int i=0; i<2*mapSize; i++)
117              if (m.containsValue(new Integer(i)) != (i%2==0))
118                  fail("contains value "+i);
119          if (m.put(nil, nil) == null)
120 <            fail("put returns a null value erroenously.");
120 >            fail("put returns a null value erroneously.");
121          Map m2 = supplier.get(); m2.putAll(m);
122          if (!m.equals(m2))
123              fail("Clone not equal to original. (1)");
# Line 147 | Line 156 | public class CheckedMapBash {
156          ArrayList<Object[]> iters = new ArrayList<>(makeCheckedMaps());
157          iters.ensureCapacity(numItr * iters.size());
158          for (int each=1; each < numItr; each++) {
159 <            iters.addAll( makeCheckedMaps());
159 >            iters.addAll(makeCheckedMaps());
160          }
161          return iters.iterator();
162      }
# Line 158 | Line 167 | public class CheckedMapBash {
167      }
168  
169      public static Collection<Object[]> makeCheckedMaps() {
170 <        return Arrays.asList(
171 <            new Object[]{"Collections.checkedMap(HashMap)",
172 <                (Supplier) () -> {return Collections.checkedMap(new HashMap(), Integer.class, Integer.class);}},
173 <            new Object[]{"Collections.checkedMap(TreeSet(reverseOrder)",
174 <                (Supplier) () -> {return Collections.checkedMap(new TreeMap(Collections.reverseOrder()), Integer.class, Integer.class);}},
175 <            new Object[]{"Collections.checkedMap(TreeSet).descendingSet()",
176 <                (Supplier) () -> {return Collections.checkedMap(new TreeMap().descendingMap(), Integer.class, Integer.class);}},
177 <            new Object[]{"Collections.checkedNavigableMap(TreeSet)",
178 <                (Supplier) () -> {return Collections.checkedNavigableMap(new TreeMap(), Integer.class, Integer.class);}},
179 <            new Object[]{"Collections.checkedNavigableMap(TreeSet(reverseOrder)",
180 <                (Supplier) () -> {return Collections.checkedNavigableMap(new TreeMap(Collections.reverseOrder()), Integer.class, Integer.class);}},
181 <            new Object[]{"Collections.checkedNavigableMap().descendingSet()",
182 <                (Supplier) () -> {return Collections.checkedNavigableMap(new TreeMap().descendingMap(), Integer.class, Integer.class);}}
183 <            );
170 >        Object[][] params = {
171 >            {"Collections.checkedMap(HashMap)",
172 >             (Supplier) () -> Collections.checkedMap(new HashMap(), Integer.class, Integer.class)},
173 >            {"Collections.checkedMap(TreeMap(reverseOrder))",
174 >             (Supplier) () -> Collections.checkedMap(new TreeMap(Collections.reverseOrder()), Integer.class, Integer.class)},
175 >            {"Collections.checkedMap(TreeMap.descendingMap())",
176 >             (Supplier) () -> Collections.checkedMap(new TreeMap().descendingMap(), Integer.class, Integer.class)},
177 >            {"Collections.checkedNavigableMap(TreeMap)",
178 >             (Supplier) () -> Collections.checkedNavigableMap(new TreeMap(), Integer.class, Integer.class)},
179 >            {"Collections.checkedNavigableMap(TreeMap(reverseOrder))",
180 >             (Supplier) () -> Collections.checkedNavigableMap(new TreeMap(Collections.reverseOrder()), Integer.class, Integer.class)},
181 >            {"Collections.checkedNavigableMap(TreeMap.descendingMap())",
182 >             (Supplier) () -> Collections.checkedNavigableMap(new TreeMap().descendingMap(), Integer.class, Integer.class)},
183 >        };
184 >        return Arrays.asList(params);
185      }
186   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines