gmunozfe commented on a change in pull request #9309: URL: https://github.com/apache/kafka/pull/9309#discussion_r497840533
########## 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: Done, I have followed the same approach that other tests in the same class, but assertThrows is also a good alternative ---------------------------------------------------------------- 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