test/jdk/java/util/PriorityQueue/NoNulls.java
author dl
Tue, 16 Jan 2018 18:28:39 -0800
changeset 48541 946e34c2dec9
parent 47216 71c04702a3d5
permissions -rw-r--r--
8193300: Miscellaneous changes imported from jsr166 CVS 2018-01 Reviewed-by: martin
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5467
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     1
/*
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     3
 *
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     4
 * This code is free software; you can redistribute it and/or modify it
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     5
 * under the terms of the GNU General Public License version 2 only, as
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     6
 * published by the Free Software Foundation.
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     7
 *
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     8
 * This code is distributed in the hope that it will be useful, but WITHOUT
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
     9
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    10
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    11
 * version 2 for more details (a copy is included in the LICENSE file that
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    12
 * accompanied this code).
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    13
 *
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License version
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    15
 * 2 along with this work; if not, write to the Free Software Foundation,
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    16
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    17
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5467
diff changeset
    18
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5467
diff changeset
    19
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 5467
diff changeset
    20
 * questions.
5467
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    21
 */
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    22
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    23
/*
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    24
 * This file is available under and governed by the GNU General Public
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    25
 * License version 2 only, as published by the Free Software Foundation.
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    26
 * However, the following notice accompanied the original version of this
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    27
 * file:
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    28
 *
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    29
 * Written by Martin Buchholz with assistance from members of JCP JSR-166
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    30
 * Expert Group and released to the public domain, as explained at
9242
ef138d47df58 7034657: Update Creative Commons license URL in legal notices
dl
parents: 8580
diff changeset
    31
 * http://creativecommons.org/publicdomain/zero/1.0/
5467
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    32
 */
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    33
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    34
/*
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    35
 * @test
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    36
 * @bug 6950540
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    37
 * @summary Attempt to add a null throws NullPointerException
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    38
 */
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    39
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    40
import java.util.ArrayList;
48541
946e34c2dec9 8193300: Miscellaneous changes imported from jsr166 CVS 2018-01
dl
parents: 47216
diff changeset
    41
import java.util.Collection;
5467
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    42
import java.util.Comparator;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    43
import java.util.PriorityQueue;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    44
import java.util.SortedSet;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    45
import java.util.TreeSet;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    46
import java.util.concurrent.ArrayBlockingQueue;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    47
import java.util.concurrent.LinkedBlockingDeque;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    48
import java.util.concurrent.LinkedBlockingQueue;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    49
import java.util.concurrent.PriorityBlockingQueue;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    50
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    51
public class NoNulls {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    52
    void test(String[] args) throws Throwable {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    53
        final Comparator<String> nullTolerantComparator
43522
f9c6f543c4db 8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents: 40817
diff changeset
    54
            = new Comparator<>() {
5467
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    55
            public int compare(String x, String y) {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    56
                return (x == null ? -1 :
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    57
                        y == null ? 1 :
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    58
                        x.compareTo(y));
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    59
            }};
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    60
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    61
        final SortedSet<String> nullSortedSet
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    62
            = new TreeSet<>(nullTolerantComparator);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    63
        nullSortedSet.add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    64
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    65
        final PriorityQueue<String> nullPriorityQueue
43522
f9c6f543c4db 8171886: Miscellaneous changes imported from jsr166 CVS 2017-02
dl
parents: 40817
diff changeset
    66
            = new PriorityQueue<>() {
5467
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    67
            public Object[] toArray() { return new Object[] { null };}};
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    68
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    69
        final Collection<String> nullCollection = new ArrayList<>();
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    70
        nullCollection.add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    71
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    72
        THROWS(NullPointerException.class,
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    73
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    74
                   new PriorityQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    75
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    76
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    77
                   new PriorityBlockingQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    78
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    79
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    80
                   new ArrayBlockingQueue<String>(10, false, nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    81
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    82
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    83
                   new ArrayBlockingQueue<String>(10, true, nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    84
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    85
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    86
                   new LinkedBlockingQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    87
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    88
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    89
                   new LinkedBlockingDeque<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    90
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    91
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    92
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    93
                   new PriorityQueue<String>((Collection<String>) nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    94
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    95
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    96
                   new PriorityBlockingQueue<String>((Collection<String>) nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    97
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    98
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
    99
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   100
                   new PriorityQueue<String>(nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   101
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   102
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   103
                   new PriorityBlockingQueue<String>(nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   104
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   105
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   106
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   107
                   new PriorityQueue<String>((Collection<String>) nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   108
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   109
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   110
                   new PriorityBlockingQueue<String>((Collection<String>) nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   111
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   112
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   113
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   114
                   new PriorityQueue<String>(nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   115
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   116
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   117
                   new PriorityBlockingQueue<String>(nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   118
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   119
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   120
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   121
                   new PriorityQueue<String>().add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   122
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   123
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   124
                   new PriorityBlockingQueue<String>().add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   125
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   126
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   127
                   new ArrayBlockingQueue<String>(10, false).add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   128
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   129
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   130
                   new ArrayBlockingQueue<String>(10, true).add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   131
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   132
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   133
                   new LinkedBlockingQueue<String>().add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   134
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   135
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   136
                   new LinkedBlockingDeque<String>().add(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   137
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   138
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   139
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   140
                   new PriorityQueue<String>().offer(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   141
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   142
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   143
                   new PriorityBlockingQueue<String>().offer(null);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   144
               }});
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   145
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   146
        nullSortedSet.add("foo");
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   147
        nullCollection.add("foo");
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   148
        THROWS(NullPointerException.class,
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   149
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   150
                   new PriorityQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   151
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   152
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   153
                   new PriorityBlockingQueue<String>(nullCollection);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   154
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   155
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   156
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   157
                   new PriorityQueue<String>((Collection<String>) nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   158
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   159
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   160
                   new PriorityBlockingQueue<String>((Collection<String>) nullPriorityQueue);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   161
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   162
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   163
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   164
                   new PriorityQueue<String>(nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   165
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   166
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   167
                   new PriorityBlockingQueue<String>(nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   168
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   169
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   170
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   171
                   new PriorityQueue<String>((Collection<String>) nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   172
               }},
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   173
               new F() { void f() {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   174
                   new PriorityBlockingQueue<String>((Collection<String>) nullSortedSet);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   175
               }});
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   176
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   177
    }
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   178
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   179
    //--------------------- Infrastructure ---------------------------
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   180
    volatile int passed = 0, failed = 0;
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   181
    void pass() {passed++;}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   182
    void fail() {failed++; Thread.dumpStack();}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   183
    void fail(String msg) {System.err.println(msg); fail();}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   184
    void unexpected(Throwable t) {failed++; t.printStackTrace();}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   185
    void check(boolean cond) {if (cond) pass(); else fail();}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   186
    void equal(Object x, Object y) {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   187
        if (x == null ? y == null : x.equals(y)) pass();
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   188
        else fail(x + " not equal to " + y);}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   189
    public static void main(String[] args) throws Throwable {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   190
        new NoNulls().instanceMain(args);}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   191
    public void instanceMain(String[] args) throws Throwable {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   192
        try {test(args);} catch (Throwable t) {unexpected(t);}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   193
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   194
        if (failed > 0) throw new AssertionError("Some tests failed");}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   195
    abstract class F {abstract void f() throws Throwable;}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   196
    void THROWS(Class<? extends Throwable> k, F... fs) {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   197
        for (F f : fs)
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   198
            try {f.f(); fail("Expected " + k.getName() + " not thrown");}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   199
            catch (Throwable t) {
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   200
                if (k.isAssignableFrom(t.getClass())) pass();
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   201
                else unexpected(t);}}
0cfa1c70b5ab 6950540: PriorityQueue(collection) should throw NPE if collection contains a null
martin
parents:
diff changeset
   202
}