|
1 | 1 | /* |
2 | | - * Copyright 2012-2024 the original author or authors. |
| 2 | + * Copyright 2012-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. |
|
28 | 28 |
|
29 | 29 | import org.springframework.boot.actuate.autoconfigure.metrics.export.otlp.OtlpMetricsExportAutoConfiguration.PropertiesOtlpMetricsConnectionDetails; |
30 | 30 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
| 31 | +import org.springframework.boot.test.context.assertj.AssertableApplicationContext; |
31 | 32 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
32 | 33 | import org.springframework.boot.testsupport.assertj.ScheduledExecutorServiceAssert; |
33 | 34 | import org.springframework.context.annotation.Bean; |
@@ -136,27 +137,22 @@ void testConnectionFactoryWithOverridesWhenUsingCustomConnectionDetails() { |
136 | 137 | @Test |
137 | 138 | void allowsCustomMetricsSenderToBeUsed() { |
138 | 139 | this.contextRunner.withUserConfiguration(BaseConfiguration.class, CustomMetricsSenderConfiguration.class) |
139 | | - .run((context) -> { |
140 | | - assertThat(context).hasSingleBean(OtlpMeterRegistry.class); |
141 | | - OtlpMeterRegistry registry = context.getBean(OtlpMeterRegistry.class); |
142 | | - assertThat(registry).extracting("metricsSender") |
143 | | - .satisfies((sender) -> assertThat(sender) |
144 | | - .isSameAs(CustomMetricsSenderConfiguration.customMetricsSender)); |
145 | | - }); |
| 140 | + .run(this::assertHasCustomMetricsSender); |
146 | 141 | } |
147 | 142 |
|
148 | 143 | @Test |
149 | 144 | @EnabledForJreRange(min = JRE.JAVA_21) |
150 | 145 | void allowsCustomMetricsSenderToBeUsedWithVirtualThreads() { |
151 | 146 | this.contextRunner.withUserConfiguration(BaseConfiguration.class, CustomMetricsSenderConfiguration.class) |
152 | 147 | .withPropertyValues("spring.threads.virtual.enabled=true") |
153 | | - .run((context) -> { |
154 | | - assertThat(context).hasSingleBean(OtlpMeterRegistry.class); |
155 | | - OtlpMeterRegistry registry = context.getBean(OtlpMeterRegistry.class); |
156 | | - assertThat(registry).extracting("metricsSender") |
157 | | - .satisfies((sender) -> assertThat(sender) |
158 | | - .isSameAs(CustomMetricsSenderConfiguration.customMetricsSender)); |
159 | | - }); |
| 148 | + .run(this::assertHasCustomMetricsSender); |
| 149 | + } |
| 150 | + |
| 151 | + private void assertHasCustomMetricsSender(AssertableApplicationContext context) { |
| 152 | + assertThat(context).hasSingleBean(OtlpMeterRegistry.class); |
| 153 | + OtlpMeterRegistry registry = context.getBean(OtlpMeterRegistry.class); |
| 154 | + assertThat(registry).extracting("metricsSender") |
| 155 | + .satisfies((sender) -> assertThat(sender).isSameAs(CustomMetricsSenderConfiguration.customMetricsSender)); |
160 | 156 | } |
161 | 157 |
|
162 | 158 | @Configuration(proxyBeanMethods = false) |
|
0 commit comments