2121
2222import org .apache .kafka .clients .admin .NewTopic ;
2323import org .apache .kafka .clients .producer .Producer ;
24- import org .junit .ClassRule ;
25- import org .junit .Test ;
24+ import org .junit .jupiter .api .AfterAll ;
2625import org .junit .jupiter .api .AfterEach ;
26+ import org .junit .jupiter .api .BeforeAll ;
27+ import org .junit .jupiter .api .Test ;
2728
2829import org .springframework .boot .test .util .TestPropertyValues ;
2930import org .springframework .context .annotation .AnnotationConfigApplicationContext ;
3536import org .springframework .kafka .core .DefaultKafkaProducerFactory ;
3637import org .springframework .kafka .core .KafkaTemplate ;
3738import org .springframework .kafka .support .KafkaHeaders ;
38- import org .springframework .kafka .test .rule . EmbeddedKafkaRule ;
39+ import org .springframework .kafka .test .EmbeddedKafkaBroker ;
3940import org .springframework .messaging .handler .annotation .Header ;
4041
4142import static org .assertj .core .api .Assertions .assertThat ;
@@ -52,19 +53,28 @@ public class KafkaAutoConfigurationIntegrationTests {
5253
5354 private static final String ADMIN_CREATED_TOPIC = "adminCreatedTopic" ;
5455
55- @ ClassRule
56- public static final EmbeddedKafkaRule embeddedKafka = new EmbeddedKafkaRule (1 , true ,
57- TEST_TOPIC );
56+ public static final EmbeddedKafkaBroker embeddedKafka = new EmbeddedKafkaBroker (1 ,
57+ true , TEST_TOPIC );
5858
5959 private AnnotationConfigApplicationContext context ;
6060
61+ @ BeforeAll
62+ public static void setUp () {
63+ embeddedKafka .afterPropertiesSet ();
64+ }
65+
6166 @ AfterEach
6267 public void close () {
6368 if (this .context != null ) {
6469 this .context .close ();
6570 }
6671 }
6772
73+ @ AfterAll
74+ public static void tearDown () {
75+ embeddedKafka .destroy ();
76+ }
77+
6878 @ SuppressWarnings ({ "unchecked" , "rawtypes" })
6979 @ Test
7080 public void testEndToEnd () throws Exception {
@@ -110,7 +120,7 @@ private AnnotationConfigApplicationContext doLoad(Class<?>[] configs,
110120 }
111121
112122 private String getEmbeddedKafkaBrokersAsString () {
113- return embeddedKafka .getEmbeddedKafka (). getBrokersAsString ();
123+ return embeddedKafka .getBrokersAsString ();
114124 }
115125
116126 @ Configuration (proxyBeanMethods = false )
0 commit comments