File tree Expand file tree Collapse file tree 1 file changed +7
-7
lines changed
spring-boot-samples/spring-boot-sample-kafka/src/test/java/sample/kafka Expand file tree Collapse file tree 1 file changed +7
-7
lines changed Original file line number Diff line number Diff line change 1616package sample .kafka ;
1717
1818import org .junit .jupiter .api .Test ;
19- import org .junit .jupiter .api .extension .RegisterExtension ;
2019
20+ import org .springframework .beans .factory .annotation .Autowired ;
2121import org .springframework .boot .test .context .SpringBootTest ;
22- import org .springframework .boot .test .extension .OutputCapture ;
2322import org .springframework .kafka .test .context .EmbeddedKafka ;
2423
2524import static org .assertj .core .api .Assertions .assertThat ;
3635@ EmbeddedKafka (topics = "testTopic" )
3736class SampleKafkaApplicationTests {
3837
39- @ RegisterExtension
40- OutputCapture output = new OutputCapture () ;
38+ @ Autowired
39+ private Consumer consumer ;
4140
4241 @ Test
4342 void testVanillaExchange () throws Exception {
44- long end = System .currentTimeMillis () + 30000 ;
45- while (! this .output . toString ().contains ( "A simple test message" )
43+ long end = System .currentTimeMillis () + 10000 ;
44+ while (this .consumer . getMessages ().isEmpty ( )
4645 && System .currentTimeMillis () < end ) {
4746 Thread .sleep (250 );
4847 }
49- assertThat (this .output ).contains ("A simple test message" );
48+ assertThat (this .consumer .getMessages ()).extracting ("message" )
49+ .containsOnly ("A simple test message" );
5050 }
5151
5252}
You can’t perform that action at this time.
0 commit comments