jdk/test/java/util/Collection/BiggernYours.java
author rupashka
Mon, 17 May 2010 17:23:18 +0400
changeset 5581 9c2282c6f080
parent 4110 ac033ba6ede4
child 5506 202f599c92aa
permissions -rw-r--r--
6938481: 4906607 is not fixed for NIMBUS L&F Reviewed-by: alexp
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
 * @test
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
 * @bug 6415641 6377302
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
 * @summary Concurrent collections are permitted to lie about their size
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
 * @author Martin Buchholz
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.concurrent.*;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
@SuppressWarnings("unchecked")
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
public class BiggernYours {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
    static final Random rnd = new Random();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
    static void compareCollections(Collection c1, Collection c2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
        arrayEqual(c1.toArray(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
                   c2.toArray());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
        arrayEqual(c1.toArray(new Object[0]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
                   c2.toArray(new Object[0]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
        arrayEqual(c1.toArray(new Object[5]),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
                   c2.toArray(new Object[5]));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
    static void compareMaps(Map m1, Map m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
        compareCollections(m1.keySet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
                           m2.keySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
        compareCollections(m1.values(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
                           m2.values());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
        compareCollections(m1.entrySet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                           m2.entrySet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
    static void compareNavigableMaps(NavigableMap m1, NavigableMap m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
        compareMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
        compareMaps(m1.descendingMap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
                    m2.descendingMap());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
        compareMaps(m1.tailMap(Integer.MIN_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
                    m2.tailMap(Integer.MIN_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
        compareMaps(m1.headMap(Integer.MAX_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
                    m2.headMap(Integer.MAX_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    static void compareNavigableSets(NavigableSet s1, NavigableSet s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
        compareCollections(s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
        compareCollections(s1.descendingSet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
                           s2.descendingSet());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        compareCollections(s1.tailSet(Integer.MIN_VALUE),
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
                           s2.tailSet(Integer.MIN_VALUE));
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    static abstract class MapFrobber { abstract void frob(Map m); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    static abstract class SetFrobber { abstract void frob(Set s); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
    static abstract class ColFrobber { abstract void frob(Collection c); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
    static ColFrobber adder(final int i) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        return new ColFrobber() {void frob(Collection c) { c.add(i); }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
    static final ColFrobber[] adders =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    { adder(1), adder(3), adder(2) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    static MapFrobber putter(final int k, final int v) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        return new MapFrobber() {void frob(Map m) { m.put(k,v); }};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
    static final MapFrobber[] putters =
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    { putter(1, -2), putter(3, -6), putter(2, -4) };
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    static void unexpected(Throwable t, Object suspect) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
        System.out.println(suspect.getClass());
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
        unexpected(t);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    static void testCollections(Collection c1, Collection c2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
            compareCollections(c1, c2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
            for (ColFrobber adder : adders) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                for (Collection c : new Collection[]{c1, c2})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                    adder.frob(c);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
                compareCollections(c1, c2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
        } catch (Throwable t) { unexpected(t, c1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
    static void testNavigableSets(NavigableSet s1, NavigableSet s2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            compareNavigableSets(s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            for (ColFrobber adder : adders) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                for (Set s : new Set[]{s1, s2})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
                    adder.frob(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
                compareNavigableSets(s1, s2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        } catch (Throwable t) { unexpected(t, s1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
    static void testMaps(Map m1, Map m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            compareMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
            for (MapFrobber putter : putters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
                for (Map m : new Map[]{m1, m2})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
                    putter.frob(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
                compareMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
        } catch (Throwable t) { unexpected(t, m1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
    static void testNavigableMaps(NavigableMap m1, NavigableMap m2) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            compareNavigableMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
            for (MapFrobber putter : putters) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
                for (Map m : new Map[]{m1, m2})
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
                    putter.frob(m);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
                compareNavigableMaps(m1, m2);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
        } catch (Throwable t) { unexpected(t, m1); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
    static int randomize(int size) { return rnd.nextInt(size + 2); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
    @SuppressWarnings("serial")
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
    private static void realMain(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        testNavigableMaps(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            new ConcurrentSkipListMap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            new ConcurrentSkipListMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
        testNavigableSets(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
            new ConcurrentSkipListSet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
            new ConcurrentSkipListSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
            new CopyOnWriteArraySet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
            new CopyOnWriteArraySet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
            new CopyOnWriteArrayList(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
            new CopyOnWriteArrayList() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            new TreeSet(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
            new TreeSet() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        testMaps(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            new ConcurrentHashMap(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
            new ConcurrentHashMap() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
            new ConcurrentLinkedQueue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            new ConcurrentLinkedQueue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
4110
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 3708
diff changeset
   181
        testCollections(
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 3708
diff changeset
   182
            new LinkedTransferQueue(),
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 3708
diff changeset
   183
            new LinkedTransferQueue() {
ac033ba6ede4 6865582: jsr166y - jsr166 maintenance update
dl
parents: 3708
diff changeset
   184
                public int size() {return randomize(super.size());}});
3708
f838f712922e 6868712: Improve concurrent queue tests
dl
parents: 2
diff changeset
   185
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
            new LinkedBlockingQueue(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
            new LinkedBlockingQueue() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            new LinkedBlockingDeque(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
            new LinkedBlockingDeque() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
            new ArrayBlockingQueue(5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
            new ArrayBlockingQueue(5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
        testCollections(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
            new PriorityBlockingQueue(5),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
            new PriorityBlockingQueue(5) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                public int size() {return randomize(super.size());}});
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
    //--------------------- Infrastructure ---------------------------
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    static volatile int passed = 0, failed = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
    static void pass() {passed++;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    static void fail() {failed++; Thread.dumpStack();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
    static void fail(String msg) {System.out.println(msg); fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
    static void unexpected(Throwable t) {failed++; t.printStackTrace();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    static void check(boolean cond) {if (cond) pass(); else fail();}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
    static void equal(Object x, Object y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
        if (x == null ? y == null : x.equals(y)) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        else fail(x + " not equal to " + y);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
    static void arrayEqual(Object[] x, Object[] y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
        if (x == null ? y == null : Arrays.equals(x, y)) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
        else fail(Arrays.toString(x) + " not equal to " + Arrays.toString(y));}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
    public static void main(String[] args) throws Throwable {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
        try {realMain(args);} catch (Throwable t) {unexpected(t);}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
        System.out.printf("%nPassed = %d, failed = %d%n%n", passed, failed);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        if (failed > 0) throw new AssertionError("Some tests failed");}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
    private static abstract class Fun {abstract void f() throws Throwable;}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    static void THROWS(Class<? extends Throwable> k, Fun... fs) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
        for (Fun f : fs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
            try { f.f(); fail("Expected " + k.getName() + " not thrown"); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
            catch (Throwable t) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
                if (k.isAssignableFrom(t.getClass())) pass();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
                else unexpected(t);}}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
    private static abstract class CheckedThread extends Thread {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
        abstract void realRun() throws Throwable;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
        public void run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            try {realRun();} catch (Throwable t) {unexpected(t);}}}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
}