GH-134: AssertJ style for thrown assertions
**Cherry-pick to 1.0.x**
This commit is contained in:
committed by
Artem Bilan
parent
6a94ae2d79
commit
aa4db96289
@@ -17,7 +17,7 @@
|
|||||||
package org.springframework.kafka.core;
|
package org.springframework.kafka.core;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.fail;
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.springframework.kafka.test.assertj.KafkaConditions.key;
|
import static org.springframework.kafka.test.assertj.KafkaConditions.key;
|
||||||
import static org.springframework.kafka.test.assertj.KafkaConditions.partition;
|
import static org.springframework.kafka.test.assertj.KafkaConditions.partition;
|
||||||
@@ -48,7 +48,6 @@ import org.springframework.messaging.support.MessageBuilder;
|
|||||||
import org.springframework.util.concurrent.ListenableFuture;
|
import org.springframework.util.concurrent.ListenableFuture;
|
||||||
import org.springframework.util.concurrent.ListenableFutureCallback;
|
import org.springframework.util.concurrent.ListenableFutureCallback;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Gary Russell
|
* @author Gary Russell
|
||||||
* @author Artem Bilan
|
* @author Artem Bilan
|
||||||
@@ -125,7 +124,7 @@ public class KafkaTemplateTests {
|
|||||||
@Test
|
@Test
|
||||||
public void withListener() throws Exception {
|
public void withListener() throws Exception {
|
||||||
Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka);
|
Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka);
|
||||||
ProducerFactory<Integer, String> pf = new DefaultKafkaProducerFactory<Integer, String>(senderProps);
|
ProducerFactory<Integer, String> pf = new DefaultKafkaProducerFactory<>(senderProps);
|
||||||
KafkaTemplate<Integer, String> template = new KafkaTemplate<>(pf);
|
KafkaTemplate<Integer, String> template = new KafkaTemplate<>(pf);
|
||||||
template.setDefaultTopic(INT_KEY_TOPIC);
|
template.setDefaultTopic(INT_KEY_TOPIC);
|
||||||
final CountDownLatch latch = new CountDownLatch(1);
|
final CountDownLatch latch = new CountDownLatch(1);
|
||||||
@@ -152,7 +151,7 @@ public class KafkaTemplateTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testWithCallback() throws Exception {
|
public void testWithCallback() throws Exception {
|
||||||
Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka);
|
Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka);
|
||||||
ProducerFactory<Integer, String> pf = new DefaultKafkaProducerFactory<Integer, String>(senderProps);
|
ProducerFactory<Integer, String> pf = new DefaultKafkaProducerFactory<>(senderProps);
|
||||||
KafkaTemplate<Integer, String> template = new KafkaTemplate<>(pf, true);
|
KafkaTemplate<Integer, String> template = new KafkaTemplate<>(pf, true);
|
||||||
template.setDefaultTopic(INT_KEY_TOPIC);
|
template.setDefaultTopic(INT_KEY_TOPIC);
|
||||||
ListenableFuture<SendResult<Integer, String>> future = template.sendDefault("foo");
|
ListenableFuture<SendResult<Integer, String>> future = template.sendDefault("foo");
|
||||||
@@ -180,12 +179,12 @@ public class KafkaTemplateTests {
|
|||||||
@Test
|
@Test
|
||||||
public void testTemplateDisambiguation() throws Exception {
|
public void testTemplateDisambiguation() throws Exception {
|
||||||
Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka);
|
Map<String, Object> senderProps = KafkaTestUtils.producerProps(embeddedKafka);
|
||||||
DefaultKafkaProducerFactory<String, String> pf = new DefaultKafkaProducerFactory<String, String>(senderProps);
|
DefaultKafkaProducerFactory<String, String> pf = new DefaultKafkaProducerFactory<>(senderProps);
|
||||||
pf.setKeySerializer(new StringSerializer());
|
pf.setKeySerializer(new StringSerializer());
|
||||||
KafkaTemplate<String, String> template = new KafkaTemplate<>(pf, true);
|
KafkaTemplate<String, String> template = new KafkaTemplate<>(pf, true);
|
||||||
template.setDefaultTopic(STRING_KEY_TOPIC);
|
template.setDefaultTopic(STRING_KEY_TOPIC);
|
||||||
Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("testTString", "false", embeddedKafka);
|
Map<String, Object> consumerProps = KafkaTestUtils.consumerProps("testTString", "false", embeddedKafka);
|
||||||
DefaultKafkaConsumerFactory<String, String> cf = new DefaultKafkaConsumerFactory<String, String>(consumerProps);
|
DefaultKafkaConsumerFactory<String, String> cf = new DefaultKafkaConsumerFactory<>(consumerProps);
|
||||||
cf.setKeyDeserializer(new StringDeserializer());
|
cf.setKeyDeserializer(new StringDeserializer());
|
||||||
Consumer<String, String> consumer = cf.createConsumer();
|
Consumer<String, String> consumer = cf.createConsumer();
|
||||||
embeddedKafka.consumeFromAnEmbeddedTopic(consumer, STRING_KEY_TOPIC);
|
embeddedKafka.consumeFromAnEmbeddedTopic(consumer, STRING_KEY_TOPIC);
|
||||||
@@ -201,14 +200,9 @@ public class KafkaTemplateTests {
|
|||||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||||
public void flushWithoutSend() throws Exception {
|
public void flushWithoutSend() throws Exception {
|
||||||
KafkaTemplate template = new KafkaTemplate(mock(ProducerFactory.class));
|
KafkaTemplate template = new KafkaTemplate(mock(ProducerFactory.class));
|
||||||
try {
|
assertThatExceptionOfType(IllegalStateException.class)
|
||||||
template.flush();
|
.isThrownBy(template::flush)
|
||||||
fail("IllegalStateException expected");
|
.withMessageContaining("'producer' must not be null for flushing.");
|
||||||
}
|
|
||||||
catch (Exception e) {
|
|
||||||
assertThat(e).isInstanceOf(IllegalStateException.class);
|
|
||||||
assertThat(e.getMessage()).isEqualTo("'producer' must not be null for flushing.");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user