mjsax commented on a change in pull request #9309: URL: https://github.com/apache/kafka/pull/9309#discussion_r497991542
########## 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: Yes, we used an older version of the test libraries and thus existing code uses a different pattern. We just try to use the newer (and better) pattern in new code and migrate existing code lazily to the new pattern. ---------------------------------------------------------------- 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