hotspot/test/testlibrary_tests/AssertsTest.java
author ctornqvi
Wed, 25 Sep 2013 17:47:22 +0200
changeset 20280 0305ea27e15b
parent 19322 hotspot/test/testlibrary/AssertsTest.java@e35f9ed4f081
child 30604 b8d532cb6420
permissions -rw-r--r--
8024677: [TESTBUG] Move tests for classes in /testlibrary Summary: Moved the tests to /testlibrary_tests and updated TEST.groups Reviewed-by: dholmes, sla
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19322
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     1
/*
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     4
 *
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     7
 * published by the Free Software Foundation.
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     8
 *
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    13
 * accompanied this code).
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    14
 *
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    18
 *
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    21
 * questions.
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    22
 */
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    23
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    24
import static com.oracle.java.testlibrary.Asserts.*;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    25
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    26
/* @test
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    27
 * @summary Tests the different assertions in the Assert class
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    28
 * @library /testlibrary
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    29
 */
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    30
public class AssertsTest {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    31
    private static class Foo implements Comparable<Foo> {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    32
        final int id;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    33
        public Foo(int id) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    34
            this.id = id;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    35
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    36
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    37
        public int compareTo(Foo f) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    38
            return new Integer(id).compareTo(new Integer(f.id));
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    39
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    40
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    41
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    42
    public static void main(String[] args) throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    43
        testLessThan();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    44
        testLessThanOrEqual();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    45
        testEquals();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    46
        testGreaterThanOrEqual();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    47
        testGreaterThan();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    48
        testNotEquals();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    49
        testNull();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    50
        testNotNull();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    51
        testTrue();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    52
        testFalse();
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    53
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    54
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    55
    private static void testLessThan() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    56
        expectPass(Assertion.LT, 1, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    57
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    58
        expectFail(Assertion.LT, 2, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    59
        expectFail(Assertion.LT, 2, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    60
        expectFail(Assertion.LT, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    61
        expectFail(Assertion.LT, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    62
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    63
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    64
    private static void testLessThanOrEqual() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    65
        expectPass(Assertion.LTE, 1, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    66
        expectPass(Assertion.LTE, 2, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    67
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    68
        expectFail(Assertion.LTE, 3, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    69
        expectFail(Assertion.LTE, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    70
        expectFail(Assertion.LTE, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    71
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    72
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    73
    private static void testEquals() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    74
        expectPass(Assertion.EQ, 1, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    75
        expectPass(Assertion.EQ, null, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    76
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    77
        Foo f1 = new Foo(1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    78
        expectPass(Assertion.EQ, f1, f1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    79
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    80
        Foo f2 = new Foo(1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    81
        expectFail(Assertion.EQ, f1, f2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    82
        expectFail(Assertion.LTE, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    83
        expectFail(Assertion.LTE, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    84
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    85
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    86
    private static void testGreaterThanOrEqual() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    87
        expectPass(Assertion.GTE, 1, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    88
        expectPass(Assertion.GTE, 2, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    89
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    90
        expectFail(Assertion.GTE, 1, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    91
        expectFail(Assertion.GTE, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    92
        expectFail(Assertion.GTE, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    93
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    94
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    95
    private static void testGreaterThan() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    96
        expectPass(Assertion.GT, 2, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    97
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    98
        expectFail(Assertion.GT, 1, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
    99
        expectFail(Assertion.GT, 1, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   100
        expectFail(Assertion.GT, null, 2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   101
        expectFail(Assertion.GT, 2, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   102
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   103
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   104
    private static void testNotEquals() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   105
        expectPass(Assertion.NE, null, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   106
        expectPass(Assertion.NE, 1, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   107
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   108
        Foo f1 = new Foo(1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   109
        Foo f2 = new Foo(1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   110
        expectPass(Assertion.NE, f1, f2);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   111
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   112
        expectFail(Assertion.NE, null, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   113
        expectFail(Assertion.NE, f1, f1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   114
        expectFail(Assertion.NE, 1, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   115
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   116
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   117
    private static void testNull() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   118
        expectPass(Assertion.NULL, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   119
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   120
        expectFail(Assertion.NULL, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   121
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   122
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   123
    private static void testNotNull() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   124
        expectPass(Assertion.NOTNULL, 1);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   125
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   126
        expectFail(Assertion.NOTNULL, null);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   127
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   128
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   129
    private static void testTrue() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   130
        expectPass(Assertion.TRUE, true);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   131
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   132
        expectFail(Assertion.TRUE, false);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   133
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   134
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   135
    private static void testFalse() throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   136
        expectPass(Assertion.FALSE, false);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   137
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   138
        expectFail(Assertion.FALSE, true);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   139
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   140
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   141
    private static <T extends Comparable<T>> void expectPass(Assertion assertion, T ... args)
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   142
        throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   143
        Assertion.run(assertion, args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   144
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   145
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   146
    private static <T extends Comparable<T>> void expectFail(Assertion assertion, T ... args)
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   147
        throws Exception {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   148
        try {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   149
            Assertion.run(assertion, args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   150
        } catch (RuntimeException e) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   151
            return;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   152
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   153
        throw new Exception("Expected " + Assertion.format(assertion, (Object[]) args) +
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   154
                            " to throw a RuntimeException");
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   155
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   156
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   157
}
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   158
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   159
enum Assertion {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   160
    LT, LTE, EQ, GTE, GT, NE, NULL, NOTNULL, FALSE, TRUE;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   161
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   162
    public static <T extends Comparable<T>> void run(Assertion assertion, T ... args) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   163
        String msg = "Expected " + format(assertion, args) + " to pass";
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   164
        switch (assertion) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   165
            case LT:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   166
                assertLessThan(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   167
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   168
            case LTE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   169
                assertLessThanOrEqual(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   170
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   171
            case EQ:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   172
                assertEquals(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   173
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   174
            case GTE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   175
                assertGreaterThanOrEqual(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   176
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   177
            case GT:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   178
                assertGreaterThan(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   179
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   180
            case NE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   181
                assertNotEquals(args[0], args[1], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   182
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   183
            case NULL:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   184
                assertNull(args == null ? args : args[0], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   185
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   186
            case NOTNULL:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   187
                assertNotNull(args == null ? args : args[0], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   188
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   189
            case FALSE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   190
                assertFalse((Boolean) args[0], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   191
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   192
            case TRUE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   193
                assertTrue((Boolean) args[0], msg);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   194
                break;
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   195
            default:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   196
                // do nothing
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   197
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   198
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   199
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   200
    public static String format(Assertion assertion, Object ... args) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   201
        switch (assertion) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   202
            case LT:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   203
                return asString("assertLessThan", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   204
            case LTE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   205
                return asString("assertLessThanOrEqual", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   206
            case EQ:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   207
                return asString("assertEquals", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   208
            case GTE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   209
                return asString("assertGreaterThanOrEquals", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   210
            case GT:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   211
                return asString("assertGreaterThan", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   212
            case NE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   213
                return asString("assertNotEquals", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   214
            case NULL:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   215
                return asString("assertNull", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   216
            case NOTNULL:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   217
                return asString("assertNotNull", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   218
            case FALSE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   219
                return asString("assertFalse", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   220
            case TRUE:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   221
                return asString("assertTrue", args);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   222
            default:
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   223
                return "";
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   224
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   225
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   226
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   227
    private static String asString(String assertion, Object ... args) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   228
        if (args == null) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   229
            return String.format("%s(null)", assertion);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   230
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   231
        if (args.length == 1) {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   232
            return String.format("%s(%s)", assertion, args[0]);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   233
        } else {
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   234
            return String.format("%s(%s, %s)", assertion, args[0], args[1]);
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   235
        }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   236
    }
e35f9ed4f081 8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff changeset
   237
}