I am having issues testing my spring cloud stream service (which writes to a Kafka stream). It is based for the following baeldung introduction
Here is the service code (with specifics omitted)
@Service
@EnableBinding(Source.class)
public class KafkaWriterService {
@SendTo(Source.OUTPUT)
public String write(String str) {
return str;
}
}
And here is the test
@SpringBootTest
@RunWith(SpringRunner.class)
public class KafkaWriterServiceTest {
@Autowired
private Source source;
@Autowired
private MessageCollector collector;
@Autowired
private KafkaWriterService service;
@Test
public void testMessages() {
BlockingQueue<Message<?>> messages = collector.forChannel(source.output());
service.write("FooBar");
Object payload = messages.poll().getPayload();
System.out.println(payload);
}
Pretty straight forward, however when executing the test I get a NullPointerException as poll returns a Null.
Any idea what the issue may be?
Thanks!
Aucun commentaire:
Enregistrer un commentaire