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

Comparing jsr166/src/test/jtreg/util/Collections/EmptyIterator.java (file contents):
Revision 1.5 by dl, Wed Feb 8 00:01:38 2012 UTC vs.
Revision 1.7 by jsr166, Mon Jan 8 03:12:03 2018 UTC

# Line 1 | Line 1
1   /*
2 < * Copyright (c) 2007, Oracle and/or its affiliates. All rights reserved.
2 > * Copyright (c) 2007, 2014, Oracle and/or its affiliates. All rights reserved.
3   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4   *
5   * This code is free software; you can redistribute it and/or modify it
# Line 23 | Line 23
23  
24   /*
25   * @test
26 < * @bug 5017904 6356890
26 > * @bug 5017904 6356890 8004928
27   * @summary Test empty iterators, enumerations, and collections
28   */
29  
30 < import java.util.*;
31 < import static java.util.Collections.*;
30 > import java.util.Collection;
31 > import java.util.Collections;
32 > import java.util.Enumeration;
33 > import java.util.Hashtable;
34 > import java.util.Iterator;
35 > import java.util.List;
36 > import java.util.Map;
37 > import java.util.NoSuchElementException;
38 > import java.util.concurrent.SynchronousQueue;
39 >
40 > import static java.util.Collections.emptyEnumeration;
41 > import static java.util.Collections.emptyIterator;
42 > import static java.util.Collections.emptyList;
43 > import static java.util.Collections.emptyListIterator;
44 > import static java.util.Collections.emptyMap;
45 > import static java.util.Collections.emptySet;
46 > import static java.util.Collections.nCopies;
47 > import static java.util.Collections.unmodifiableMap;
48  
49   public class EmptyIterator {
50  
51      void test(String[] args) throws Throwable {
52 <        testEmptyCollection(Collections.<Object>emptyList());
53 <        testEmptyCollection(Collections.<Object>emptySet());
54 < //         Removed jdk7 dependency from SynchronousQueue.
55 < //         testEmptyCollection(new java.util.concurrent.
40 < //                             SynchronousQueue<Object>());
52 >        testEmptyCollection(emptyList());
53 >        testEmptyCollection(emptySet());
54 >        testEmptyCollection(new SynchronousQueue<Object>());
55 >        testEmptyMap(emptyMap());
56  
57 <        testEmptyMap(Collections.<Object, Object>emptyMap());
43 <
44 <        Hashtable<Object, Object> emptyTable = new Hashtable<Object, Object>();
57 >        Hashtable<?,?> emptyTable = new Hashtable<>();
58          testEmptyEnumeration(emptyTable.keys());
59          testEmptyEnumeration(emptyTable.elements());
60          testEmptyIterator(emptyTable.keySet().iterator());
61          testEmptyIterator(emptyTable.values().iterator());
62          testEmptyIterator(emptyTable.entrySet().iterator());
63  
64 <        testEmptyEnumeration(javax.swing.tree.DefaultMutableTreeNode
65 <                             .EMPTY_ENUMERATION);
66 <        testEmptyEnumeration(javax.swing.text.SimpleAttributeSet
67 <                             .EMPTY.getAttributeNames());
68 <
69 <        @SuppressWarnings("unchecked")
70 <        Iterator<?> x = new sun.tools.java.MethodSet()
58 <            .lookupName(sun.tools.java.Identifier.lookup(""));
59 <        testEmptyIterator(x);
64 >        final Enumeration<EmptyIterator> finalEmptyTyped = emptyEnumeration();
65 >        testEmptyEnumeration(finalEmptyTyped);
66 >
67 >        final Enumeration<?> finalEmptyAbstract = emptyEnumeration();
68 >        testEmptyEnumeration(finalEmptyAbstract);
69 >
70 >        testEmptyIterator(emptyIterator());
71      }
72  
73 <    <T> void testEmptyEnumeration(final Enumeration<T> e) {
74 <        check(! e.hasMoreElements());
73 >    void testEmptyEnumeration(final Enumeration<?> e) {
74 >        check(e == emptyEnumeration());
75 >        check(!e.hasMoreElements());
76          THROWS(NoSuchElementException.class,
77                 new F(){void f(){ e.nextElement(); }});
78      }
79  
80 <    <T> void testEmptyIterator(final Iterator<T> it) {
80 >    void testEmptyIterator(final Iterator<?> it) {
81 >        check(it == emptyIterator());
82          check(! it.hasNext());
83          THROWS(NoSuchElementException.class,
84                 new F(){void f(){ it.next(); }});
# Line 73 | Line 86 | public class EmptyIterator {
86                 new F(){void f(){ it.remove(); }});
87      }
88  
89 <    void testEmptyMap(Map<Object, Object> m) {
89 >    void testEmptyMap(Map<?,?> m) {
90 >        check(m == emptyMap());
91          check(m.entrySet().iterator() ==
92 <              Collections.<Map.Entry<Object,Object>>emptyIterator());
92 >              Collections.<Map.Entry<?,?>>emptyIterator());
93          check(m.values().iterator() == emptyIterator());
94          check(m.keySet().iterator() == emptyIterator());
95          equal(m, unmodifiableMap(m));
# Line 85 | Line 99 | public class EmptyIterator {
99          testEmptyCollection(m.values());
100      }
101  
102 <    <E> void testToArray(final Collection<E> c) {
102 >    void testToArray(final Collection<?> c) {
103          Object[] a = c.toArray();
104          equal(a.length, 0);
105          equal(a.getClass().getComponentType(), Object.class);
# Line 106 | Line 120 | public class EmptyIterator {
120          }
121      }
122  
123 <    <E> void testEmptyCollection(final Collection<E> c) {
123 >    void testEmptyCollection(final Collection<?> c) {
124          testEmptyIterator(c.iterator());
125 +
126 +        check(c.iterator() == emptyIterator());
127 +        if (c instanceof List)
128 +            check(((List<?>)c).listIterator() == emptyListIterator());
129 +
130          testToArray(c);
131      }
132  

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines