Fix tests for SK 2.3.0.M3

This commit is contained in:
Gary Russell
2019-06-14 17:35:37 -04:00
committed by Artem Bilan
parent bc443474cb
commit a1b51c9f47
2 changed files with 11 additions and 4 deletions

View File

@@ -18,6 +18,8 @@ package org.springframework.integration.kafka.config.xml;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import java.util.concurrent.Executors;
@@ -38,6 +40,7 @@ import org.springframework.integration.kafka.outbound.KafkaProducerMessageHandle
import org.springframework.integration.test.util.TestUtils;
import org.springframework.kafka.core.KafkaProducerException;
import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.kafka.core.ProducerFactory;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.support.GenericMessage;
import org.springframework.test.annotation.DirtiesContext;
@@ -102,7 +105,10 @@ public class KafkaOutboundAdapterParserTests {
}
};
KafkaTemplate<Integer, String> template = new KafkaTemplate<>(() -> mockProducer);
@SuppressWarnings("unchecked")
ProducerFactory<Integer, String> pf = mock(ProducerFactory.class);
given(pf.createProducer(isNull())).willReturn(mockProducer);
KafkaTemplate<Integer, String> template = new KafkaTemplate<>(pf);
KafkaProducerMessageHandler<Integer, String> handler = new KafkaProducerMessageHandler<>(template);
handler.setBeanFactory(mock(BeanFactory.class));
handler.afterPropertiesSet();

View File

@@ -19,6 +19,7 @@ package org.springframework.integration.kafka.outbound;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.isNull;
import static org.mockito.BDDMockito.given;
import static org.mockito.BDDMockito.willAnswer;
import static org.mockito.BDDMockito.willReturn;
@@ -427,7 +428,7 @@ public class KafkaProducerMessageHandlerTests {
ProducerFactory pf = mock(ProducerFactory.class);
given(pf.transactionCapable()).willReturn(true);
Producer producer = mock(Producer.class);
given(pf.createProducer()).willReturn(producer);
given(pf.createProducer(isNull())).willReturn(producer);
ListenableFuture future = mock(ListenableFuture.class);
willReturn(future).given(producer).send(any(ProducerRecord.class), any(Callback.class));
KafkaTemplate template = new KafkaTemplate(pf);
@@ -481,7 +482,7 @@ public class KafkaProducerMessageHandlerTests {
willAnswer(i -> {
transactionalIds.add(TransactionSupport.getTransactionIdSuffix());
return producer;
}).given(pf).createProducer();
}).given(pf).createProducer(isNull());
KafkaTransactionManager tm = new KafkaTransactionManager(pf);
PlatformTransactionManager ptm = tm;
ContainerProperties props = new ContainerProperties("foo");
@@ -515,7 +516,7 @@ public class KafkaProducerMessageHandlerTests {
inOrder.verify(producer).commitTransaction();
inOrder.verify(producer).close();
container.stop();
verify(pf, times(2)).createProducer();
verify(pf, times(2)).createProducer(isNull());
verifyNoMoreInteractions(producer);
assertThat(transactionalIds.get(0)).isEqualTo("group.foo.0");
assertThat(transactionalIds.get(0)).isEqualTo("group.foo.0");