11/*
2- * Copyright 2016-2022 the original author or authors.
2+ * Copyright 2016-2023 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -559,19 +559,21 @@ void testFutureFailureOnSend() {
559559
560560 @ SuppressWarnings ("unchecked" )
561561 @ Test
562- void testProducerInterceptorManagedOnKafkaTemplate () {
562+ void testProducerInterceptorManagedOnKafkaTemplate () throws Exception {
563563
564564 Map <String , Object > senderProps = KafkaTestUtils .producerProps (embeddedKafka );
565565 DefaultKafkaProducerFactory <Integer , String > pf = new DefaultKafkaProducerFactory <>(senderProps );
566566 KafkaTemplate <Integer , String > template = new KafkaTemplate <>(pf , true );
567567 ProducerInterceptor <Integer , String > producerInterceptor = Mockito .mock (ProducerInterceptor .class );
568+ willAnswer (inv -> new ProducerRecord <>("prod-interceptor-test-1" , "bar" )).given (producerInterceptor ).onSend (any ());
568569 template .setProducerInterceptor (producerInterceptor );
569570
570571 template .setDefaultTopic ("prod-interceptor-test-1" );
571- template .sendDefault ("foo" );
572+ CompletableFuture < SendResult < Integer , String >> resultCompletableFuture = template .sendDefault ("foo" );
572573
573574 verify (producerInterceptor , times (1 )).onSend (any (ProducerRecord .class ));
574575 verify (producerInterceptor , times (1 )).onAcknowledgement (any (RecordMetadata .class ), Mockito .isNull ());
576+ assertThat (resultCompletableFuture .get (10 , TimeUnit .SECONDS ).getProducerRecord ()).isEqualTo (new ProducerRecord <>("prod-interceptor-test-1" , "bar" ));
575577 }
576578
577579 @ SuppressWarnings ("unchecked" )
@@ -591,13 +593,15 @@ void testProducerInterceptorNotSetOnKafkaTemplateNotInvoked() {
591593
592594 @ SuppressWarnings ("unchecked" )
593595 @ Test
594- void testCompositeProducerInterceptor () {
596+ void testCompositeProducerInterceptor () throws Exception {
595597
596598 Map <String , Object > senderProps = KafkaTestUtils .producerProps (embeddedKafka );
597599 DefaultKafkaProducerFactory <Integer , String > pf = new DefaultKafkaProducerFactory <>(senderProps );
598600 KafkaTemplate <Integer , String > template = new KafkaTemplate <>(pf , true );
599601 ProducerInterceptor <Integer , String > producerInterceptor1 = Mockito .mock (ProducerInterceptor .class );
600602 ProducerInterceptor <Integer , String > producerInterceptor2 = Mockito .mock (ProducerInterceptor .class );
603+ willAnswer (inv -> new ProducerRecord <>("prod-interceptor-test-3" , "bar" )).given (producerInterceptor1 ).onSend (any ());
604+ willAnswer (inv -> new ProducerRecord <>("prod-interceptor-test-3" , "baz" )).given (producerInterceptor2 ).onSend (any ());
601605 CompositeProducerInterceptor <Integer , String > compositeProducerInterceptor =
602606 new CompositeProducerInterceptor <>(producerInterceptor1 , producerInterceptor2 );
603607 template .setProducerInterceptor (compositeProducerInterceptor );
@@ -606,14 +610,15 @@ void testCompositeProducerInterceptor() {
606610 doReturn (mockProducerRecord ).when (producerInterceptor1 ).onSend (any (ProducerRecord .class ));
607611
608612 template .setDefaultTopic ("prod-interceptor-test-3" );
609- template .sendDefault ("foo" );
613+ CompletableFuture < SendResult < Integer , String >> result = template .sendDefault ("foo" );
610614
611615 InOrder inOrder = inOrder (producerInterceptor1 , producerInterceptor2 );
612616
613617 inOrder .verify (producerInterceptor1 ).onSend (any (ProducerRecord .class ));
614618 inOrder .verify (producerInterceptor2 ).onSend (any (ProducerRecord .class ));
615619 inOrder .verify (producerInterceptor1 ).onAcknowledgement (any (RecordMetadata .class ), Mockito .isNull ());
616620 inOrder .verify (producerInterceptor2 ).onAcknowledgement (any (RecordMetadata .class ), Mockito .isNull ());
621+ assertThat (result .get (10 , TimeUnit .SECONDS ).getProducerRecord ()).isEqualTo (new ProducerRecord <>("prod-interceptor-test-3" , "baz" ));
617622 }
618623
619624 @ ParameterizedTest (name = "{0} is invalid" )
0 commit comments