BasicObjectsTest.java revision 2362
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* @test
* @bug 6797535 6889858 6891113
* @summary Basic tests for methods in java.util.Objects
* @author Joseph D. Darcy
*/
public class BasicObjectsTest {
int errors = 0;
errors += testEquals();
errors += testDeepEquals();
errors += testHashCode();
errors += testToString();
errors += testToString2();
errors += testCompare();
errors += testNonNull();
if (errors > 0 )
throw new RuntimeException();
}
private static int testEquals() {
int errors = 0;
boolean expected = (i == j);
errors++;
}
}
return errors;
}
private static int testDeepEquals() {
int errors = 0;
null, // Change to values later
new byte[] {(byte)1},
new short[] {(short)1},
new int[] {1},
new long[] {1L},
new char[] {(char)1},
new float[] {1.0f},
new double[]{1.0d},
new String[]{"one"}};
boolean expected = (i == j);
errors++;
}
}
return errors;
}
private static int testHashCode() {
int errors = 0;
String s = "42";
return errors;
}
private static int testHash() {
int errors = 0;
return errors;
}
private static int testToString() {
int errors = 0;
String s = "Some string";
return errors;
}
private static int testToString2() {
int errors = 0;
String s = "not the default";
return errors;
}
private static int testCompare() {
int errors = 0;
}
}
return errors;
}
int errors = 0;
errors++;
}
return errors;
}
private static int testNonNull() {
int errors = 0;
String s;
// Test 1-arg variant
try {
if (s != "pants") {
errors++;
}
} catch (NullPointerException e) {
errors++;
}
try {
errors++;
} catch (NullPointerException e) {
// Expected
}
// Test 2-arg variant
try {
if (s != "pants") {
errors++;
}
} catch (NullPointerException e) {
errors++;
}
try {
errors++;
} catch (NullPointerException e) {
if (e.getMessage() != "pantaloons") {
errors++;
}
}
return errors;
}
}