1 package de.example.spring.kafka;
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.junit.Assert.assertThat;
6 import javax.inject.Inject;
9 import org.junit.runner.RunWith;
10 import org.springframework.boot.test.context.SpringBootTest;
11 import org.springframework.cloud.stream.messaging.Source;
12 import org.springframework.cloud.stream.test.binder.MessageCollector;
13 import org.springframework.messaging.Message;
14 import org.springframework.test.annotation.DirtiesContext;
15 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
17 @RunWith(SpringJUnit4ClassRunner.class)
18 @SpringBootTest(classes = { Sender.class })
20 public class SenderShould {
29 private MessageCollector messageCollector;
32 public void sendSomeProduct() {
33 Product product = new Product("hello", "this is some description");
35 sender.sendMessage("hello");
37 Message<Product> received = (Message<Product>) messageCollector.forChannel(source.output()).poll();
39 assertThat(received.getPayload().getDescription(), is(product.getDescription()));