author | ohair |
Wed, 06 Apr 2011 22:06:11 -0700 | |
changeset 9035 | 1255eb81cc2f |
parent 8166 | 13423c0952ad |
child 16863 | f51406efb328 |
permissions | -rw-r--r-- |
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
1 |
/* |
9035
1255eb81cc2f
7033660: Update copyright year to 2011 on any files changed in 2011
ohair
parents:
8166
diff
changeset
|
2 |
* Copyright (c) 2009, 2011, Oracle and/or its affiliates. All rights reserved. |
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
4 |
* |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
8 |
* |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
13 |
* accompanied this code). |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
14 |
* |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
18 |
* |
5506 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
22 |
*/ |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
23 |
|
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
24 |
/* |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
25 |
* @test |
4165
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
26 |
* @bug 6797535 6889858 6891113 |
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
27 |
* @summary Basic tests for methods in java.util.Objects |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
28 |
* @author Joseph D. Darcy |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
29 |
*/ |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
30 |
|
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
31 |
import java.util.*; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
32 |
|
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
33 |
public class BasicObjectsTest { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
34 |
public static void main(String... args) { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
35 |
int errors = 0; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
36 |
errors += testEquals(); |
4165
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
37 |
errors += testDeepEquals(); |
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
38 |
errors += testHashCode(); |
4165
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
39 |
errors += testHash(); |
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
40 |
errors += testToString(); |
4165
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
41 |
errors += testToString2(); |
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
42 |
errors += testCompare(); |
4061 | 43 |
errors += testNonNull(); |
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
44 |
if (errors > 0 ) |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
45 |
throw new RuntimeException(); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
46 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
47 |
|
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
48 |
private static int testEquals() { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
49 |
int errors = 0; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
50 |
Object[] values = {null, "42", 42}; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
51 |
for(int i = 0; i < values.length; i++) |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
52 |
for(int j = 0; j < values.length; j++) { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
53 |
boolean expected = (i == j); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
54 |
Object a = values[i]; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
55 |
Object b = values[j]; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
56 |
boolean result = Objects.equals(a, b); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
57 |
if (result != expected) { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
58 |
errors++; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
59 |
System.err.printf("When equating %s to %s, got %b instead of %b%n.", |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
60 |
a, b, result, expected); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
61 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
62 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
63 |
return errors; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
64 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
65 |
|
4165
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
66 |
private static int testDeepEquals() { |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
67 |
int errors = 0; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
68 |
Object[] values = {null, |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
69 |
null, // Change to values later |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
70 |
new byte[] {(byte)1}, |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
71 |
new short[] {(short)1}, |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
72 |
new int[] {1}, |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
73 |
new long[] {1L}, |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
74 |
new char[] {(char)1}, |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
75 |
new float[] {1.0f}, |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
76 |
new double[]{1.0d}, |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
77 |
new String[]{"one"}}; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
78 |
values[1] = values; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
79 |
|
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
80 |
for(int i = 0; i < values.length; i++) |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
81 |
for(int j = 0; j < values.length; j++) { |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
82 |
boolean expected = (i == j); |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
83 |
Object a = values[i]; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
84 |
Object b = values[j]; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
85 |
boolean result = Objects.deepEquals(a, b); |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
86 |
if (result != expected) { |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
87 |
errors++; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
88 |
System.err.printf("When equating %s to %s, got %b instead of %b%n.", |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
89 |
a, b, result, expected); |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
90 |
} |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
91 |
} |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
92 |
|
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
93 |
return errors; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
94 |
} |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
95 |
|
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
96 |
private static int testHashCode() { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
97 |
int errors = 0; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
98 |
errors += (Objects.hashCode(null) == 0 ) ? 0 : 1; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
99 |
String s = "42"; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
100 |
errors += (Objects.hashCode(s) == s.hashCode() ) ? 0 : 1; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
101 |
return errors; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
102 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
103 |
|
4165
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
104 |
private static int testHash() { |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
105 |
int errors = 0; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
106 |
|
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
107 |
Object[] data = new String[]{"perfect", "ham", "THC"}; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
108 |
|
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
109 |
errors += ((Objects.hash((Object[])null) == 0) ? 0 : 1); |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
110 |
|
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
111 |
errors += (Objects.hash("perfect", "ham", "THC") == |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
112 |
Arrays.hashCode(data)) ? 0 : 1; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
113 |
|
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
114 |
return errors; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
115 |
} |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
116 |
|
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
117 |
private static int testToString() { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
118 |
int errors = 0; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
119 |
errors += ("null".equals(Objects.toString(null)) ) ? 0 : 1; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
120 |
String s = "Some string"; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
121 |
errors += (s.equals(Objects.toString(s)) ) ? 0 : 1; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
122 |
return errors; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
123 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
124 |
|
4165
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
125 |
private static int testToString2() { |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
126 |
int errors = 0; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
127 |
String s = "not the default"; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
128 |
errors += (s.equals(Objects.toString(null, s)) ) ? 0 : 1; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
129 |
errors += (s.equals(Objects.toString(s, "another string")) ) ? 0 : 1; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
130 |
return errors; |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
131 |
} |
7cd799c224da
6891113: More methods for java.util.Objects: deepEquals, hash, toString with default
darcy
parents:
4061
diff
changeset
|
132 |
|
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
133 |
private static int testCompare() { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
134 |
int errors = 0; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
135 |
String[] values = {"e. e. cummings", "zzz"}; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
136 |
String[] VALUES = {"E. E. Cummings", "ZZZ"}; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
137 |
errors += compareTest(null, null, 0); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
138 |
for(int i = 0; i < values.length; i++) { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
139 |
String a = values[i]; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
140 |
errors += compareTest(a, a, 0); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
141 |
for(int j = 0; j < VALUES.length; j++) { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
142 |
int expected = Integer.compare(i, j); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
143 |
String b = VALUES[j]; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
144 |
errors += compareTest(a, b, expected); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
145 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
146 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
147 |
return errors; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
148 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
149 |
|
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
150 |
private static int compareTest(String a, String b, int expected) { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
151 |
int errors = 0; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
152 |
int result = Objects.compare(a, b, String.CASE_INSENSITIVE_ORDER); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
153 |
if (Integer.signum(result) != Integer.signum(expected)) { |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
154 |
errors++; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
155 |
System.err.printf("When comparing %s to %s, got %d instead of %d%n.", |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
156 |
a, b, result, expected); |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
157 |
} |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
158 |
return errors; |
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
159 |
} |
4061 | 160 |
|
161 |
private static int testNonNull() { |
|
162 |
int errors = 0; |
|
163 |
String s; |
|
164 |
||
165 |
// Test 1-arg variant |
|
166 |
try { |
|
8166
13423c0952ad
7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents:
5506
diff
changeset
|
167 |
s = Objects.requireNonNull("pants"); |
4061 | 168 |
if (s != "pants") { |
169 |
System.err.printf("1-arg non-null failed to return its arg"); |
|
170 |
errors++; |
|
171 |
} |
|
172 |
} catch (NullPointerException e) { |
|
173 |
System.err.printf("1-arg nonNull threw unexpected NPE"); |
|
174 |
errors++; |
|
175 |
} |
|
176 |
||
177 |
try { |
|
8166
13423c0952ad
7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents:
5506
diff
changeset
|
178 |
s = Objects.requireNonNull(null); |
4061 | 179 |
System.err.printf("1-arg nonNull failed to throw NPE"); |
180 |
errors++; |
|
181 |
} catch (NullPointerException e) { |
|
182 |
// Expected |
|
183 |
} |
|
184 |
||
185 |
// Test 2-arg variant |
|
186 |
try { |
|
8166
13423c0952ad
7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents:
5506
diff
changeset
|
187 |
s = Objects.requireNonNull("pants", "trousers"); |
4061 | 188 |
if (s != "pants") { |
189 |
System.err.printf("2-arg nonNull failed to return its arg"); |
|
190 |
errors++; |
|
191 |
} |
|
192 |
} catch (NullPointerException e) { |
|
193 |
System.err.printf("2-arg nonNull threw unexpected NPE"); |
|
194 |
errors++; |
|
195 |
} |
|
196 |
||
197 |
try { |
|
8166
13423c0952ad
7012540: java.util.Objects.nonNull() incorrectly named
briangoetz
parents:
5506
diff
changeset
|
198 |
s = Objects.requireNonNull(null, "pantaloons"); |
4061 | 199 |
System.err.printf("2-arg nonNull failed to throw NPE"); |
200 |
errors++; |
|
201 |
} catch (NullPointerException e) { |
|
202 |
if (e.getMessage() != "pantaloons") { |
|
203 |
System.err.printf("2-arg nonNull threw NPE w/ bad detail msg"); |
|
204 |
errors++; |
|
205 |
} |
|
206 |
} |
|
207 |
return errors; |
|
208 |
} |
|
4038
ea7aa63169db
6797535: Add shared two argument static equals method to the platform
darcy
parents:
diff
changeset
|
209 |
} |