/*
 * Copyright 2012-2018 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
 *
 *      http://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 java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;

import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.test.rule.OutputCapture;
import org.springframework.context.annotation.Bean;
import org.springframework.kafka.test.context.EmbeddedKafka;
import org.springframework.test.context.junit4.SpringRunner;

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

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

	private static final CountDownLatch latch = new CountDownLatch(1);

	@Rule
	public OutputCapture outputCapture = new OutputCapture();

	@Test
	public void testVanillaExchange() throws Exception {
		assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();
		assertThat(this.outputCapture.toString().contains("A simple test message"))
				.isTrue();
	}

	@TestConfiguration
	public static class Config {

		@Bean
		public Consumer consumer() {
			return new Consumer() {

				@Override
				public void processMessage(SampleMessage message) {
					super.processMessage(message);
					latch.countDown();
				}

			};
		}

	}

}

@@ -641,91 +641,8 @@
 a;%0A%0A
-import java.util.concurrent.CountDownLatch;%0Aimport java.util.concurrent.TimeUnit;%0A%0A
 impo
@@ -782,72 +782,8 @@
 st;%0A
-import org.springframework.boot.test.context.TestConfiguration;%0A
 impo
@@ -839,60 +839,8 @@
 re;%0A
-import org.springframework.context.annotation.Bean;%0A
 impo
@@ -1327,77 +1327,8 @@
  %7B%0A%0A
-%09private static final CountDownLatch latch = new CountDownLatch(1);%0A%0A
 %09@Ru
@@ -1457,77 +1457,65 @@
 %7B%0A%09%09
-assertThat(latch.await(10, TimeUnit.SECONDS)).isTrue();%0A%09%09assertThat(
+long end = System.currentTimeMillis() + 10000;%0A%09%09while (!
 this
@@ -1577,213 +1577,152 @@
 ge%22)
-)
 %0A%09%09%09%09
-.isTrue();%0A%09%7D%0A%0A%09@TestConfiguration%0A%09public static class Config %7B%0A%0A%09%09@Bean%0A%09%09public Consumer consumer() %7B%0A%09%09%09return new Consumer() %7B%0A%0A%09%09%09%09@Override%0A%09%09%09%09public void processMessage(SampleMessage
+&& System.currentTimeMillis() %3C end) %7B%0A%09%09%09Thread.sleep(250);%0A%09%09%7D%0A%09%09assertThat(this.outputCapture.toString().contains(%22A simple test
  message
 ) %7B%0A
@@ -1721,89 +1721,26 @@
 sage
-) %7B
+%22))
 %0A%09%09%09%09
-%09super.processMessage(message);%0A%09%09%09%09%09latch.countDown();%0A%09%09%09%09%7D%0A%0A%09%09%09%7D;%0A%09%09%7D%0A
+.isTrue();
 %0A%09%7D%0A

Remove the use of a bean override form SampleKafkaApplicationTests