You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jira@kafka.apache.org by "DL1231 (via GitHub)" <gi...@apache.org> on 2025/06/17 01:07:18 UTC

[PR] MINOR: replace test "catch exception" by assertThrows [kafka]

DL1231 opened a new pull request, #19975:
URL: https://github.com/apache/kafka/pull/19975

   see https://github.com/apache/kafka/pull/19948#discussion_r2150617216, replace test "catch exception" by assertThrows.
   


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: replace test "catch exception" by assertThrows [kafka]

Posted by "chia7712 (via GitHub)" <gi...@apache.org>.
chia7712 merged PR #19975:
URL: https://github.com/apache/kafka/pull/19975


-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: replace test "catch exception" by assertThrows [kafka]

Posted by "frankvicky (via GitHub)" <gi...@apache.org>.
frankvicky commented on code in PR #19975:
URL: https://github.com/apache/kafka/pull/19975#discussion_r2151716431


##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -1974,12 +1974,9 @@ public void testCloseShouldBeIdempotent(GroupProtocol groupProtocol) {
     @ParameterizedTest
     @EnumSource(GroupProtocol.class)
     public void testOperationsBySubscribingConsumerWithDefaultGroupId(GroupProtocol groupProtocol) {
-        try {
-            newConsumer(groupProtocol, null, Optional.of(Boolean.TRUE));
-            fail("Expected an InvalidConfigurationException");
-        } catch (InvalidConfigurationException swallow) {
-            // OK, expected
-        }
+        assertThrows(InvalidConfigurationException.class,
+            () -> newConsumer(groupProtocol, null, Optional.of(Boolean.TRUE)),

Review Comment:
   Out of curiosity, why do we use `Boolean.TRUE` here?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: replace test "catch exception" by assertThrows [kafka]

Posted by "DL1231 (via GitHub)" <gi...@apache.org>.
DL1231 commented on code in PR #19975:
URL: https://github.com/apache/kafka/pull/19975#discussion_r2152115911


##########
clients/src/test/java/org/apache/kafka/clients/consumer/KafkaConsumerTest.java:
##########
@@ -1974,12 +1974,9 @@ public void testCloseShouldBeIdempotent(GroupProtocol groupProtocol) {
     @ParameterizedTest
     @EnumSource(GroupProtocol.class)
     public void testOperationsBySubscribingConsumerWithDefaultGroupId(GroupProtocol groupProtocol) {
-        try {
-            newConsumer(groupProtocol, null, Optional.of(Boolean.TRUE));
-            fail("Expected an InvalidConfigurationException");
-        } catch (InvalidConfigurationException swallow) {
-            // OK, expected
-        }
+        assertThrows(InvalidConfigurationException.class,
+            () -> newConsumer(groupProtocol, null, Optional.of(Boolean.TRUE)),

Review Comment:
   good catch!



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] MINOR: replace test "catch exception" by assertThrows [kafka]

Posted by "FrankYang0529 (via GitHub)" <gi...@apache.org>.
FrankYang0529 commented on code in PR #19975:
URL: https://github.com/apache/kafka/pull/19975#discussion_r2151426572


##########
clients/src/test/java/org/apache/kafka/common/metrics/MetricsTest.java:
##########
@@ -700,24 +681,15 @@ public void testMetricInstances() {
             assertEquals(filledOutTags.get("parent-tag"), "parent-tag-value", "parent-tag should be set properly");
             assertEquals(filledOutTags.get("child-tag"), "child-tag-value", "child-tag should be set properly");
 
-            try {
-                inherited.metricInstance(SampleMetrics.METRIC_WITH_INHERITED_TAGS, parentTagsWithValues);
-                fail("Creating MetricName should fail if the child metrics are not defined at runtime");
-            } catch (IllegalArgumentException e) {
-                // this is expected
-            }
+            // Creating MetricName should throw IllegalArgumentException if the child metrics are not defined at runtime.

Review Comment:
   How about put this message to the third argument in `assertThrows`?



-- 
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: jira-unsubscribe@kafka.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org