|
16 | 16 |
|
17 | 17 | package org.springframework.grpc.autoconfigure.server; |
18 | 18 |
|
19 | | -import io.grpc.ServerBuilder; |
20 | | -import io.micrometer.core.instrument.binder.grpc.ObservationGrpcServerInterceptor; |
21 | | -import io.micrometer.observation.ObservationRegistry; |
| 19 | +import static org.assertj.core.api.Assertions.assertThat; |
| 20 | + |
| 21 | +import org.assertj.core.api.Condition; |
22 | 22 | import org.junit.jupiter.api.Test; |
23 | 23 | import org.mockito.Mockito; |
24 | | - |
25 | 24 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
26 | 25 | import org.springframework.boot.test.context.FilteredClassLoader; |
27 | 26 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
28 | | -import org.springframework.grpc.server.ServerBuilderCustomizer; |
29 | 27 |
|
30 | | -import static org.assertj.core.api.Assertions.assertThat; |
31 | | -import static org.mockito.Mockito.mock; |
32 | | -import static org.mockito.Mockito.verify; |
| 28 | +import io.micrometer.core.instrument.binder.grpc.ObservationGrpcServerInterceptor; |
| 29 | +import io.micrometer.observation.ObservationRegistry; |
33 | 30 |
|
34 | 31 | /** |
35 | 32 | * Tests for the {@link GrpcServerObservationAutoConfiguration}. |
@@ -79,19 +76,12 @@ void whenObservationPropertyDisabledThenAutoConfigIsSkipped() { |
79 | 76 | .run(context -> assertThat(context).doesNotHaveBean(GrpcServerObservationAutoConfiguration.class)); |
80 | 77 | } |
81 | 78 |
|
82 | | - @SuppressWarnings({ "rawtypes", "unchecked" }) |
83 | 79 | @Test |
84 | 80 | void whenAllConditionsAreMetThenInterceptorConfiguredAsExpected() { |
85 | 81 | this.validContextRunner().run((context) -> { |
86 | | - assertThat(context).hasSingleBean(ObservationGrpcServerInterceptor.class); |
87 | | - assertThat(context).hasSingleBean(ServerBuilderCustomizer.class); |
88 | | - // ensure the customizer in fact adds the interceptor to the builder |
89 | | - ObservationGrpcServerInterceptor serverInterceptor = context |
90 | | - .getBean(ObservationGrpcServerInterceptor.class); |
91 | | - ServerBuilder<?> serverBuilder = mock(); |
92 | | - ServerBuilderCustomizer serverBuilderCustomizer = context.getBean(ServerBuilderCustomizer.class); |
93 | | - serverBuilderCustomizer.customize(serverBuilder); |
94 | | - verify(serverBuilder).intercept(serverInterceptor); |
| 82 | + assertThat(context).hasSingleBean(ObservationGrpcServerInterceptor.class) |
| 83 | + .has(new Condition<>(beans -> beans.getBeansWithAnnotation(GlobalServerInterceptor.class).size() == 1, |
| 84 | + "One global interceptor expected")); |
95 | 85 | }); |
96 | 86 | } |
97 | 87 |
|
|
0 commit comments