test/java/util/Objects/BasicObjectsTest.java

Print this page
rev 7044 : 8013712: Add Objects.nonNull and Objects.isNull
Reviewed-by: duke

@@ -38,10 +38,12 @@
         errors += testHashCode();
         errors += testHash();
         errors += testToString();
         errors += testToString2();
         errors += testCompare();
+        errors += testRequireNonNull();
+        errors += testIsNull();
         errors += testNonNull();
         if (errors > 0 )
             throw new RuntimeException();
     }
 

@@ -156,11 +158,11 @@
                               a, b, result, expected);
         }
         return errors;
     }
 
-    private static int testNonNull() {
+    private static int testRequireNonNull() {
         int errors = 0;
         String s;
 
         // Test 1-arg variant
         try {

@@ -204,6 +206,24 @@
                 errors++;
             }
         }
         return errors;
     }
+
+    private static int testIsNull() {
+        int errors = 0;
+
+        errors += Objects.isNull(null) ? 0 : 1;
+        errors += Objects.isNull(Objects.class) ? 1 : 0;
+
+        return errors;
+    }
+
+    private static int testNonNull() {
+        int errors = 0;
+
+        errors += Objects.nonNull(null) ? 1 : 0;
+        errors += Objects.nonNull(Objects.class) ? 0 : 1;
+
+        return errors;
+    }
 }