c89e56551254c1b0ce42ad4ab4703c7a66ea4ede
[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.cloud.stream.test.binder.TestSupportBinderAutoConfiguration;
16 import org.springframework.messaging.Message;
17 import org.springframework.messaging.support.GenericMessage;
18 import org.springframework.test.annotation.DirtiesContext;
19 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
20
21 @RunWith(SpringJUnit4ClassRunner.class)
22 @SpringBootTest(classes = { Receiver.class, TestSupportBinderAutoConfiguration.class })
23 @DirtiesContext
24 public class ReceiverIntegrationTest {
25
26         @Inject
27         Sink source;
28         
29         @MockBean
30         DummyService dummyService;
31         
32         @Test
33         public void callSomeDummy() {
34                 String productName = "product";
35                 String productDescription = "productDescription";
36                 Product product = new Product(productName, productDescription);
37             ArgumentCaptor<String> dummyArgCaptor = ArgumentCaptor.forClass(String.class);
38                 doNothing().when(dummyService).iAmVeryDummy(dummyArgCaptor.capture());
39                 
40             Message<Product> message = new GenericMessage<>(product);
41             source.input().send(message);
42
43             assertThat(dummyArgCaptor.getValue(), is(product.getName()));
44         }
45
46 }