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 16
16
package sample .kafka ;
17
17
18
18
import org .junit .jupiter .api .Test ;
19
- import org .junit .jupiter .api .extension .RegisterExtension ;
20
19
20
+ import org .springframework .beans .factory .annotation .Autowired ;
21
21
import org .springframework .boot .test .context .SpringBootTest ;
22
- import org .springframework .boot .test .extension .OutputCapture ;
23
22
import org .springframework .kafka .test .context .EmbeddedKafka ;
24
23
25
24
import static org .assertj .core .api .Assertions .assertThat ;
36
35
@ EmbeddedKafka (topics = "testTopic" )
37
36
class SampleKafkaApplicationTests {
38
37
39
- @ RegisterExtension
40
- OutputCapture output = new OutputCapture () ;
38
+ @ Autowired
39
+ private Consumer consumer ;
41
40
42
41
@ Test
43
42
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 ( )
46
45
&& System .currentTimeMillis () < end ) {
47
46
Thread .sleep (250 );
48
47
}
49
- assertThat (this .output ).contains ("A simple test message" );
48
+ assertThat (this .consumer .getMessages ()).extracting ("message" )
49
+ .containsOnly ("A simple test message" );
50
50
}
51
51
52
52
}
You can’t perform that action at this time.
0 commit comments