chia7712 commented on code in PR #23277:
URL: https://github.com/apache/kafka/pull/23277#discussion_r3881924309


##########
clients/src/test/java/org/apache/kafka/clients/producer/ProducerRecordTest.java:
##########
@@ -53,26 +53,17 @@ public void testEqualsAndHashCode() {
 
     @Test
     public void testInvalidRecords() {
-        try {
-            new ProducerRecord<>(null, 0, "key", 1);
-            fail("Expected IllegalArgumentException to be raised because topic 
is null");
-        } catch (IllegalArgumentException e) {
-            //expected
-        }
+        assertThrows(IllegalArgumentException.class,
+                () -> new ProducerRecord<>(null, 0, "key", 1),
+                "Expected IllegalArgumentException to be raised because topic 
is null");
 
-        try {
-            new ProducerRecord<>("test", 0, -1L, "key", 1);
-            fail("Expected IllegalArgumentException to be raised because of 
negative timestamp");
-        } catch (IllegalArgumentException e) {
-            //expected
-        }
+        assertThrows(IllegalArgumentException.class,
+                () -> new ProducerRecord<>("test", 0, -1L, "key", 1),
+                "Expected IllegalArgumentException to be raised because of 
negative timestamp");
 
-        try {
-            new ProducerRecord<>("test", -1, "key", 1);
-            fail("Expected IllegalArgumentException to be raised because of 
negative partition");
-        } catch (IllegalArgumentException e) {
-            //expected
-        }
+        assertThrows(IllegalArgumentException.class,
+                () -> new ProducerRecord<>("test", -1, "key", 1),
+                "Expected IllegalArgumentException to be raised because of 
negative partition");

Review Comment:
   ditto



##########
clients/src/test/java/org/apache/kafka/clients/producer/ProducerRecordTest.java:
##########
@@ -53,26 +53,17 @@ public void testEqualsAndHashCode() {
 
     @Test
     public void testInvalidRecords() {
-        try {
-            new ProducerRecord<>(null, 0, "key", 1);
-            fail("Expected IllegalArgumentException to be raised because topic 
is null");
-        } catch (IllegalArgumentException e) {
-            //expected
-        }
+        assertThrows(IllegalArgumentException.class,
+                () -> new ProducerRecord<>(null, 0, "key", 1),
+                "Expected IllegalArgumentException to be raised because topic 
is null");
 
-        try {
-            new ProducerRecord<>("test", 0, -1L, "key", 1);
-            fail("Expected IllegalArgumentException to be raised because of 
negative timestamp");
-        } catch (IllegalArgumentException e) {
-            //expected
-        }
+        assertThrows(IllegalArgumentException.class,
+                () -> new ProducerRecord<>("test", 0, -1L, "key", 1),
+                "Expected IllegalArgumentException to be raised because of 
negative timestamp");

Review Comment:
   ditto



##########
clients/src/test/java/org/apache/kafka/clients/producer/ProducerRecordTest.java:
##########
@@ -53,26 +53,17 @@ public void testEqualsAndHashCode() {
 
     @Test
     public void testInvalidRecords() {
-        try {
-            new ProducerRecord<>(null, 0, "key", 1);
-            fail("Expected IllegalArgumentException to be raised because topic 
is null");
-        } catch (IllegalArgumentException e) {
-            //expected
-        }
+        assertThrows(IllegalArgumentException.class,
+                () -> new ProducerRecord<>(null, 0, "key", 1),
+                "Expected IllegalArgumentException to be raised because topic 
is null");

Review Comment:
   This error message is redundant



-- 
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