6291ea406d4b1f5a4e9d4ac9015d790c34704087
[JavaForFun] /
1 package de.example.spring.kafka;
2
3 import static org.hamcrest.CoreMatchers.is;
4 import static org.junit.Assert.assertThat;
5 import static org.mockito.Mockito.doNothing;
6
7 import javax.inject.Inject;
8
9 import org.junit.Test;
10 import org.junit.runner.RunWith;
11 import org.mockito.ArgumentCaptor;
12 import org.springframework.boot.test.context.SpringBootTest;
13 import org.springframework.boot.test.mock.mockito.MockBean;
14 import org.springframework.cloud.stream.messaging.Sink;
15 import org.springframework.messaging.Message;
16 import org.springframework.messaging.support.GenericMessage;
17 import org.springframework.test.annotation.DirtiesContext;
18 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
19
20 @RunWith(SpringJUnit4ClassRunner.class)
21 @SpringBootTest(classes = { Receiver.class })
22 @DirtiesContext
23 public class ReceiverShould {
24
25         @Inject
26         Sink source;
27         
28         @MockBean
29         DummyService dummyService;
30         
31         @Test
32         public void callSomeDummy() {
33                 String productName = "product";
34                 String productDescription = "productDescription";
35                 Product product = new Product(productName, productDescription);
36             ArgumentCaptor<String> dummyArgCaptor = ArgumentCaptor.forClass(String.class);
37                 doNothing().when(dummyService).iAmVeryDummy(dummyArgCaptor.capture());
38                 
39             Message<Product> message = new GenericMessage<>(product);
40             source.input().send(message);
41
42             assertThat(dummyArgCaptor.getValue(), is(product.getName()));
43         }
44
45 }