3030import io .github .eocqrs .kafka .parameters .ValueSerializer ;
3131import io .github .eocqrs .kafka .producer .settings .KfProducerParams ;
3232import io .github .eocqrs .kafka .xml .KfXmlFlexible ;
33+ import org .apache .kafka .clients .producer .KafkaProducer ;
3334import org .junit .jupiter .api .Test ;
35+ import org .junit .jupiter .api .extension .ExtendWith ;
36+ import org .mockito .Mock ;
37+ import org .mockito .junit .jupiter .MockitoExtension ;
3438
3539import static org .assertj .core .api .Assertions .assertThat ;
3640import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
4448 * @todo #47:45m/DEV Consumer Producer communication.
4549 * We have to create an ITCase for communication between Consumer and Producer.
4650 */
51+ @ ExtendWith (MockitoExtension .class )
4752final class KfProducerTest {
4853
4954 @ Test
50- void constructsProducerWithXML () throws Exception {
51- final Producer <String , String > producer =
52- new KfProducer <>(
53- new KfXmlFlexible <String , String >("settings.xml" )
54- .producer ()
55- );
55+ void constructsProducerWithExistingProducer (@ Mock final KafkaProducer <String , String > mock ) {
56+ final Producer <String , String > producer = new KfProducer <>(mock );
5657 assertThat (producer ).isNotNull ();
57- assertDoesNotThrow (
58- producer ::close
58+ assertDoesNotThrow (producer ::close );
59+ }
60+
61+ @ Test
62+ void constructsProducerWithXml () throws Exception {
63+ final Producer <String , String > producer = new KfProducer <>(
64+ new KfXmlFlexible <>("settings.xml" )
5965 );
66+ assertThat (producer ).isNotNull ();
67+ assertDoesNotThrow (producer ::close );
6068 }
6169
6270 @ Test
@@ -74,8 +82,6 @@ void constructsProducerWithParams() {
7482 )
7583 );
7684 assertThat (producer ).isNotNull ();
77- assertDoesNotThrow (
78- producer ::close
79- );
85+ assertDoesNotThrow (producer ::close );
8086 }
8187}
0 commit comments