adoroszlai commented on code in PR #981:
URL: https://github.com/apache/ratis/pull/981#discussion_r1419667808


##########
ratis-test/src/test/java/org/apache/ratis/util/TestPreconditions.java:
##########
@@ -50,4 +52,22 @@ public void testAssertUnique() {
 
     Preconditions.assertUnique(three, Arrays.asList(4, 5, 6));
   }
+
+  @Test(timeout = 1000)
+  public void testAssertNull() {
+    final Map<String, String> map = new HashMap<>();
+    final String key = "abc1234";
+    // putNew will call Preconditions.assertNull(..) to assert the entry does 
not exist in the map
+    // putNew the first time should work
+    CollectionUtils.putNew(key, key, map, () -> "m");
+    Preconditions.assertTrue(map.containsKey(key));
+
+    // putNew the second time should fail
+    final Throwable e = testFailureCase("put " + key + " again",
+        () -> CollectionUtils.putNew(key, key, map, () -> "m"),
+        IllegalStateException.class);
+    LOG.info("Expected to get:", e);

Review Comment:
   This log seems strange, as `e` is the actual result, not the expectation.



##########
ratis-common/src/main/java/org/apache/ratis/util/Preconditions.java:
##########
@@ -93,14 +94,8 @@ static void assertNull(Object object, String name) {
         + name + " = " + object + " != null, class = " + object.getClass());
   }
 
-  static <T> T assertNotNull(T object, Supplier<String> message) {
-    assertTrue(object != null, message);
-    return object;
-  }

Review Comment:
   Should we keep this for compatibility, and delegate to 
`Objects.requireNonNull`?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to