--- old/test/java/util/Objects/BasicObjectsTest.java 2009-10-23 11:07:25.000000000 -0700 +++ new/test/java/util/Objects/BasicObjectsTest.java 2009-10-23 11:07:25.000000000 -0700 @@ -23,7 +23,7 @@ /* * @test - * @bug 6797535 + * @bug 6797535 6889858 6891113 * @summary Basic tests for methods in java.util.Objects * @author Joseph D. Darcy */ @@ -34,8 +34,11 @@ public static void main(String... args) { int errors = 0; errors += testEquals(); + errors += testDeepEquals(); errors += testHashCode(); + errors += testHash(); errors += testToString(); + errors += testToString2(); errors += testCompare(); errors += testNonNull(); if (errors > 0 ) @@ -60,6 +63,36 @@ return errors; } + private static int testDeepEquals() { + int errors = 0; + Object[] values = {null, + 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"}}; + values[1] = values; + + for(int i = 0; i < values.length; i++) + for(int j = 0; j < values.length; j++) { + boolean expected = (i == j); + Object a = values[i]; + Object b = values[j]; + boolean result = Objects.deepEquals(a, b); + if (result != expected) { + errors++; + System.err.printf("When equating %s to %s, got %b instead of %b%n.", + a, b, result, expected); + } + } + + return errors; + } + private static int testHashCode() { int errors = 0; errors += (Objects.hashCode(null) == 0 ) ? 0 : 1; @@ -68,6 +101,19 @@ return errors; } + private static int testHash() { + int errors = 0; + + Object[] data = new String[]{"perfect", "ham", "THC"}; + + errors += ((Objects.hash((Object[])null) == 0) ? 0 : 1); + + errors += (Objects.hash("perfect", "ham", "THC") == + Arrays.hashCode(data)) ? 0 : 1; + + return errors; + } + private static int testToString() { int errors = 0; errors += ("null".equals(Objects.toString(null)) ) ? 0 : 1; @@ -76,6 +122,14 @@ return errors; } + private static int testToString2() { + int errors = 0; + String s = "not the default"; + errors += (s.equals(Objects.toString(null, s)) ) ? 0 : 1; + errors += (s.equals(Objects.toString(s, "another string")) ) ? 0 : 1; + return errors; + } + private static int testCompare() { int errors = 0; String[] values = {"e. e. cummings", "zzz"};