Mercurial > hg > truffle
annotate test/testlibrary_tests/AssertsTest.java @ 17532:e5561d89fe8b jdk8u5-b02
Merge
author | asaha |
---|---|
date | Fri, 20 Dec 2013 09:29:09 -0800 |
parents | 5b1191bf0b4b |
children |
rev | line source |
---|---|
12063
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
1 /* |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
4 * |
1a8fb39bdbc4
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 |
1a8fb39bdbc4
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 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
8 * |
1a8fb39bdbc4
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 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1a8fb39bdbc4
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 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
13 * accompanied this code). |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
14 * |
1a8fb39bdbc4
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 |
1a8fb39bdbc4
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, |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
18 * |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
1a8fb39bdbc4
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 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
21 * questions. |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
22 */ |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
23 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
24 import static com.oracle.java.testlibrary.Asserts.*; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
25 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
26 /* @test |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
27 * @summary Tests the different assertions in the Assert class |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
28 * @library /testlibrary |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
29 */ |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
30 public class AssertsTest { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
31 private static class Foo implements Comparable<Foo> { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
32 final int id; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
33 public Foo(int id) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
34 this.id = id; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
35 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
36 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
37 public int compareTo(Foo f) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
38 return new Integer(id).compareTo(new Integer(f.id)); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
39 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
40 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
41 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
42 public static void main(String[] args) throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
43 testLessThan(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
44 testLessThanOrEqual(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
45 testEquals(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
46 testGreaterThanOrEqual(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
47 testGreaterThan(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
48 testNotEquals(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
49 testNull(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
50 testNotNull(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
51 testTrue(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
52 testFalse(); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
53 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
54 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
55 private static void testLessThan() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
56 expectPass(Assertion.LT, 1, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
57 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
58 expectFail(Assertion.LT, 2, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
59 expectFail(Assertion.LT, 2, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
60 expectFail(Assertion.LT, null, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
61 expectFail(Assertion.LT, 2, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
62 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
63 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
64 private static void testLessThanOrEqual() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
65 expectPass(Assertion.LTE, 1, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
66 expectPass(Assertion.LTE, 2, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
67 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
68 expectFail(Assertion.LTE, 3, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
69 expectFail(Assertion.LTE, null, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
70 expectFail(Assertion.LTE, 2, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
71 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
72 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
73 private static void testEquals() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
74 expectPass(Assertion.EQ, 1, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
75 expectPass(Assertion.EQ, null, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
76 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
77 Foo f1 = new Foo(1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
78 expectPass(Assertion.EQ, f1, f1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
79 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
80 Foo f2 = new Foo(1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
81 expectFail(Assertion.EQ, f1, f2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
82 expectFail(Assertion.LTE, null, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
83 expectFail(Assertion.LTE, 2, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
84 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
85 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
86 private static void testGreaterThanOrEqual() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
87 expectPass(Assertion.GTE, 1, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
88 expectPass(Assertion.GTE, 2, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
89 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
90 expectFail(Assertion.GTE, 1, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
91 expectFail(Assertion.GTE, null, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
92 expectFail(Assertion.GTE, 2, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
93 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
94 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
95 private static void testGreaterThan() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
96 expectPass(Assertion.GT, 2, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
97 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
98 expectFail(Assertion.GT, 1, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
99 expectFail(Assertion.GT, 1, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
100 expectFail(Assertion.GT, null, 2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
101 expectFail(Assertion.GT, 2, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
102 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
103 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
104 private static void testNotEquals() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
105 expectPass(Assertion.NE, null, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
106 expectPass(Assertion.NE, 1, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
107 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
108 Foo f1 = new Foo(1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
109 Foo f2 = new Foo(1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
110 expectPass(Assertion.NE, f1, f2); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
111 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
112 expectFail(Assertion.NE, null, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
113 expectFail(Assertion.NE, f1, f1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
114 expectFail(Assertion.NE, 1, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
115 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
116 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
117 private static void testNull() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
118 expectPass(Assertion.NULL, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
119 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
120 expectFail(Assertion.NULL, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
121 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
122 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
123 private static void testNotNull() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
124 expectPass(Assertion.NOTNULL, 1); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
125 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
126 expectFail(Assertion.NOTNULL, null); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
127 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
128 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
129 private static void testTrue() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
130 expectPass(Assertion.TRUE, true); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
131 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
132 expectFail(Assertion.TRUE, false); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
133 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
134 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
135 private static void testFalse() throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
136 expectPass(Assertion.FALSE, false); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
137 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
138 expectFail(Assertion.FALSE, true); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
139 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
140 |
1a8fb39bdbc4
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) |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
142 throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
143 Assertion.run(assertion, args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
144 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
145 |
1a8fb39bdbc4
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) |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
147 throws Exception { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
148 try { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
149 Assertion.run(assertion, args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
150 } catch (RuntimeException e) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
151 return; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
152 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
153 throw new Exception("Expected " + Assertion.format(assertion, (Object[]) args) + |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
154 " to throw a RuntimeException"); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
155 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
156 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
157 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
158 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
159 enum Assertion { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
160 LT, LTE, EQ, GTE, GT, NE, NULL, NOTNULL, FALSE, TRUE; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
161 |
1a8fb39bdbc4
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) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
163 String msg = "Expected " + format(assertion, args) + " to pass"; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
164 switch (assertion) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
165 case LT: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
166 assertLessThan(args[0], args[1], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
167 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
168 case LTE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
169 assertLessThanOrEqual(args[0], args[1], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
170 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
171 case EQ: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
172 assertEquals(args[0], args[1], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
173 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
174 case GTE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
175 assertGreaterThanOrEqual(args[0], args[1], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
176 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
177 case GT: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
178 assertGreaterThan(args[0], args[1], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
179 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
180 case NE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
181 assertNotEquals(args[0], args[1], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
182 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
183 case NULL: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
184 assertNull(args == null ? args : args[0], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
185 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
186 case NOTNULL: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
187 assertNotNull(args == null ? args : args[0], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
188 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
189 case FALSE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
190 assertFalse((Boolean) args[0], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
191 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
192 case TRUE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
193 assertTrue((Boolean) args[0], msg); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
194 break; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
195 default: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
196 // do nothing |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
197 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
198 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
199 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
200 public static String format(Assertion assertion, Object ... args) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
201 switch (assertion) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
202 case LT: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
203 return asString("assertLessThan", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
204 case LTE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
205 return asString("assertLessThanOrEqual", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
206 case EQ: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
207 return asString("assertEquals", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
208 case GTE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
209 return asString("assertGreaterThanOrEquals", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
210 case GT: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
211 return asString("assertGreaterThan", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
212 case NE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
213 return asString("assertNotEquals", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
214 case NULL: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
215 return asString("assertNull", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
216 case NOTNULL: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
217 return asString("assertNotNull", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
218 case FALSE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
219 return asString("assertFalse", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
220 case TRUE: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
221 return asString("assertTrue", args); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
222 default: |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
223 return ""; |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
224 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
225 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
226 |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
227 private static String asString(String assertion, Object ... args) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
228 if (args == null) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
229 return String.format("%s(null)", assertion); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
230 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
231 if (args.length == 1) { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
232 return String.format("%s(%s)", assertion, args[0]); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
233 } else { |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
234 return String.format("%s(%s, %s)", assertion, args[0], args[1]); |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
235 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
236 } |
1a8fb39bdbc4
8014659: NPG: performance counters for compressed klass space
ehelin
parents:
diff
changeset
|
237 } |