mjsax commented on a change in pull request #9309:
URL: https://github.com/apache/kafka/pull/9309#discussion_r497712541



##########
File path: 
clients/src/test/java/org/apache/kafka/clients/producer/MockProducerTest.java
##########
@@ -765,6 +766,16 @@ public void shouldThrowOnFlushProducerIfProducerIsClosed() 
{
             fail("Should have thrown as producer is already closed");
         } catch (IllegalStateException e) { }
     }
+    
+    @Test
+    @SuppressWarnings("unchecked")

Review comment:
       We should avoid to suppress warning. Seems, you need to add generics to 
`ProducerRecord` in L774 to fix it?

##########
File path: 
clients/src/test/java/org/apache/kafka/clients/producer/MockProducerTest.java
##########
@@ -765,6 +766,16 @@ public void shouldThrowOnFlushProducerIfProducerIsClosed() 
{
             fail("Should have thrown as producer is already closed");
         } catch (IllegalStateException e) { }
     }
+    
+    @Test
+    @SuppressWarnings("unchecked")
+    public void shouldThrowClassCastException() {
+        try (MockProducer<Integer, String> producer = new MockProducer<>(true, 
new IntegerSerializer(), new StringSerializer());) {
+            ProducerRecord record = new ProducerRecord(topic, "key1", 
"value1");
+            producer.send(record);
+            fail("Should have thrown ClassCastException because record cannot 
be casted with serializers");

Review comment:
       instead of `fail` we should use ```
   assertThrows(
       ClassCastException.class,
       () -> producer.send(record);
   );
   ```
   
   For this case, we can remove the `catch` block below.




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

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


Reply via email to