|
1 | 1 | /* |
2 | | - * Copyright 2017-2025 the original author or authors. |
| 2 | + * Copyright 2025 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
20 | 20 |
|
21 | 21 | import org.springframework.beans.factory.BeanCreationException; |
22 | 22 | import org.springframework.context.annotation.AnnotationConfigApplicationContext; |
23 | | -import org.springframework.context.annotation.Bean; |
24 | 23 | import org.springframework.context.annotation.Configuration; |
25 | 24 | import org.springframework.stereotype.Component; |
26 | 25 |
|
27 | | -import static org.assertj.core.api.Assertions.assertThatThrownBy; |
| 26 | +import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
28 | 27 |
|
29 | 28 | /** |
30 | 29 | * @author Sanghyeok An |
31 | 30 | * |
32 | 31 | * @since 4.0.0 |
33 | 32 | */ |
34 | 33 |
|
35 | | -class KafkaListenerAnnotationBeanPostProcessorTest { |
| 34 | +class KafkaListenerAnnotationBeanPostProcessorTests { |
36 | 35 |
|
37 | 36 | @Test |
38 | 37 | void ctx_should_be_fail_to_register_bean_when_no_listener_methods_exist() { |
39 | | - // GIVEN |
| 38 | + |
40 | 39 | AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); |
41 | 40 | ctx.register(TestConfig.class); |
42 | 41 |
|
43 | | - // GIVEN - expected |
44 | | - Class<?> expectedErrorType = BeanCreationException.class; |
45 | | - String expectedErrorMsg = |
46 | | - "Error creating bean with name 'org.springframework.kafka.annotation." |
47 | | - + "KafkaListenerAnnotationBeanPostProcessorTest$TestConfig$BuggyListener': " |
48 | | - + "No kafka listener methods found on bean type: class org.springframework.kafka" |
49 | | - + ".annotation.KafkaListenerAnnotationBeanPostProcessorTest$TestConfig$BuggyListener"; |
| 42 | + assertThatExceptionOfType(BeanCreationException.class) |
| 43 | + .isThrownBy(ctx::refresh) |
| 44 | + .withMessageContaining("No kafka listener methods found on bean type.") |
| 45 | + .withMessageContaining("NoHandlerMethodListener"); |
50 | 46 |
|
51 | | - // WHEN + THEN |
52 | | - assertThatThrownBy(ctx::refresh) |
53 | | - .isInstanceOf(expectedErrorType) |
54 | | - .hasMessage(expectedErrorMsg); |
55 | 47 | } |
56 | 48 |
|
| 49 | + @EnableKafka |
57 | 50 | @Configuration |
58 | 51 | static class TestConfig { |
59 | 52 |
|
60 | | - @Bean |
61 | | - public KafkaListenerAnnotationBeanPostProcessor<Object, Object> kafkaListenerAnnotationBeanPostProcessor() { |
62 | | - return new KafkaListenerAnnotationBeanPostProcessor<>(); |
63 | | - } |
64 | | - |
65 | 53 | @Component |
66 | 54 | @KafkaListener |
67 | | - static class BuggyListener { |
| 55 | + static class NoHandlerMethodListener { |
68 | 56 |
|
69 | 57 | public void listen(String message) { |
70 | | - return; |
71 | 58 | } |
72 | 59 | } |
73 | 60 |
|
|
0 commit comments