Skip to content

Commit addf060

Browse files
committed
Add micrometer tracing auto-configuration tests
See spring-projectsgh-30156
1 parent de8921e commit addf060

File tree

1 file changed

+64
-0
lines changed

1 file changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright 2012-2022 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.boot.actuate.autoconfigure.tracing;
18+
19+
import io.micrometer.tracing.Tracer;
20+
import io.micrometer.tracing.handler.DefaultTracingObservationHandler;
21+
import org.junit.jupiter.api.Test;
22+
import org.mockito.Mockito;
23+
24+
import org.springframework.boot.autoconfigure.AutoConfigurations;
25+
import org.springframework.boot.test.context.FilteredClassLoader;
26+
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
27+
import org.springframework.context.annotation.Bean;
28+
import org.springframework.context.annotation.Configuration;
29+
30+
import static org.assertj.core.api.Assertions.assertThat;
31+
32+
/**
33+
* Tests for {@link MicrometerTracingAutoConfiguration}.
34+
*
35+
* @author Moritz Halbritter
36+
*/
37+
class MicrometerTracingAutoConfigurationTests {
38+
39+
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
40+
.withConfiguration(AutoConfigurations.of(MicrometerTracingAutoConfiguration.class));
41+
42+
@Test
43+
void shouldNotFailIfMicrometerIsMissing() {
44+
this.contextRunner.withClassLoader(new FilteredClassLoader("io.micrometer"))
45+
.run((context) -> assertThat(context).doesNotHaveBean(DefaultTracingObservationHandler.class));
46+
}
47+
48+
@Test
49+
void shouldHaveDefaultTracingObservationHandler() {
50+
this.contextRunner.withUserConfiguration(TracerConfiguration.class)
51+
.run((context) -> assertThat(context).hasSingleBean(DefaultTracingObservationHandler.class));
52+
}
53+
54+
@Configuration(proxyBeanMethods = false)
55+
static class TracerConfiguration {
56+
57+
@Bean
58+
Tracer tracer() {
59+
return Mockito.mock(Tracer.class);
60+
}
61+
62+
}
63+
64+
}

0 commit comments

Comments
 (0)