Skip to content

Commit 6937686

Browse files
Addressing PR review
Signed-off-by: chickenchickenlove <[email protected]>
1 parent 696f48f commit 6937686

File tree

1 file changed

+76
-0
lines changed

1 file changed

+76
-0
lines changed
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* Copyright 2017-2025 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.kafka.annotation;
18+
19+
import org.junit.jupiter.api.Test;
20+
21+
import org.springframework.beans.factory.BeanCreationException;
22+
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
23+
import org.springframework.context.annotation.Bean;
24+
import org.springframework.context.annotation.Configuration;
25+
import org.springframework.stereotype.Component;
26+
27+
import static org.assertj.core.api.Assertions.assertThatThrownBy;
28+
29+
/**
30+
* @author Sanghyeok An
31+
*
32+
* @since 4.0.0
33+
*/
34+
35+
class KafkaListenerAnnotationBeanPostProcessorTest {
36+
37+
@Test
38+
void ctx_should_be_fail_to_register_bean_when_no_listener_methods_exist() {
39+
// GIVEN
40+
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
41+
ctx.register(TestConfig.class);
42+
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";
50+
51+
// WHEN + THEN
52+
assertThatThrownBy(ctx::refresh)
53+
.isInstanceOf(expectedErrorType)
54+
.hasMessage(expectedErrorMsg);
55+
}
56+
57+
@Configuration
58+
static class TestConfig {
59+
60+
@Bean
61+
public KafkaListenerAnnotationBeanPostProcessor<Object, Object> kafkaListenerAnnotationBeanPostProcessor() {
62+
return new KafkaListenerAnnotationBeanPostProcessor<>();
63+
}
64+
65+
@Component
66+
@KafkaListener
67+
static class BuggyListener {
68+
69+
public void listen(String message) {
70+
return;
71+
}
72+
}
73+
74+
}
75+
76+
}

0 commit comments

Comments
 (0)