/*
 * Copyright 2012-2019 the original author or authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      https://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package sample.kafka;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.extension.OutputCapture;
import org.springframework.kafka.test.context.EmbeddedKafka;

import static org.assertj.core.api.Assertions.assertThat;

/**
 * Integration tests for demo application.
 *
 * @author hcxin
 * @author Gary Russell
 * @author Stephane Nicoll
 */
@SpringBootTest(
		properties = "spring.kafka.bootstrap-servers=${spring.embedded.kafka.brokers}")
@EmbeddedKafka(topics = "testTopic")
class SampleKafkaApplicationTests {

	@RegisterExtension
	OutputCapture output = new OutputCapture();

	@Test
	void testVanillaExchange() throws Exception {
		long end = System.currentTimeMillis() + 30000;
		while (!this.output.toString().contains("A simple test message")
				&& System.currentTimeMillis() < end) {
			Thread.sleep(250);
		}
		assertThat(this.output).contains("A simple test message");
	}

}

@@ -669,24 +669,25 @@
 r.api.Test;%0A
+%0A
 import org.j
@@ -689,56 +689,60 @@
 org.
-junit.jupiter.api.extension.RegisterExtension
+springframework.beans.factory.annotation.Autowired
 ;%0A
-%0A
 impo
@@ -802,70 +802,8 @@
 st;%0A
-import org.springframework.boot.test.extension.OutputCapture;%0A
 impo
@@ -1220,69 +1220,44 @@
 %0A%0A%09@
-RegisterExtension%0A%09OutputCapture output = new OutputCapture()
+Autowired%0A%09private Consumer consumer
 ;%0A%0A%09
@@ -1355,9 +1355,9 @@
 ) + 
-3
+1
 0000
@@ -1371,64 +1371,44 @@
 le (
-!
 this.
-output.toString().contains(%22A simple test message%22
+consumer.getMessages().isEmpty(
 )%0A%09%09
@@ -1496,15 +1496,58 @@
 his.
-output)
+consumer.getMessages()).extracting(%22message%22)%0A%09%09%09%09
 .con
@@ -1551,16 +1551,20 @@
 contains
+Only
 (%22A simp

Improve reliability of kafka sample integration test