|
16 | 16 |
|
17 | 17 | package org.springframework.boot.actuate.autoconfigure.metrics.export.graphite; |
18 | 18 |
|
19 | | -import java.util.Map; |
20 | | - |
21 | 19 | import io.micrometer.core.instrument.Clock; |
22 | 20 | import io.micrometer.core.instrument.Tags; |
23 | 21 | import io.micrometer.graphite.GraphiteConfig; |
24 | 22 | import io.micrometer.graphite.GraphiteMeterRegistry; |
25 | 23 | import org.junit.Test; |
26 | 24 |
|
27 | 25 | import org.springframework.boot.autoconfigure.AutoConfigurations; |
28 | | -import org.springframework.boot.test.context.assertj.AssertableApplicationContext; |
29 | 26 | import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
30 | 27 | import org.springframework.context.annotation.Bean; |
31 | 28 | import org.springframework.context.annotation.Configuration; |
32 | 29 | import org.springframework.context.annotation.Import; |
33 | | -import org.springframework.test.util.ReflectionTestUtils; |
34 | 30 |
|
35 | 31 | import static org.assertj.core.api.Assertions.assertThat; |
36 | | -import static org.mockito.Mockito.spy; |
37 | | -import static org.mockito.Mockito.verify; |
38 | 32 |
|
39 | 33 | /** |
40 | 34 | * Tests for {@link GraphiteMetricsExportAutoConfiguration}. |
@@ -106,27 +100,14 @@ public void allowsCustomRegistryToBeUsed() { |
106 | 100 | public void stopsMeterRegistryWhenContextIsClosed() { |
107 | 101 | this.contextRunner.withUserConfiguration(BaseConfiguration.class) |
108 | 102 | .run((context) -> { |
109 | | - GraphiteMeterRegistry registry = spyOnDisposableBean( |
110 | | - GraphiteMeterRegistry.class, context); |
| 103 | + GraphiteMeterRegistry registry = context |
| 104 | + .getBean(GraphiteMeterRegistry.class); |
| 105 | + assertThat(registry.isClosed()).isFalse(); |
111 | 106 | context.close(); |
112 | | - verify(registry).stop(); |
| 107 | + assertThat(registry.isClosed()).isTrue(); |
113 | 108 | }); |
114 | 109 | } |
115 | 110 |
|
116 | | - @SuppressWarnings("unchecked") |
117 | | - private <T> T spyOnDisposableBean(Class<T> type, |
118 | | - AssertableApplicationContext context) { |
119 | | - String[] names = context.getBeanNamesForType(type); |
120 | | - assertThat(names).hasSize(1); |
121 | | - String registryBeanName = names[0]; |
122 | | - Map<String, Object> disposableBeans = (Map<String, Object>) ReflectionTestUtils |
123 | | - .getField(context.getAutowireCapableBeanFactory(), "disposableBeans"); |
124 | | - Object registryAdapter = disposableBeans.get(registryBeanName); |
125 | | - T registry = (T) spy(ReflectionTestUtils.getField(registryAdapter, "bean")); |
126 | | - ReflectionTestUtils.setField(registryAdapter, "bean", registry); |
127 | | - return registry; |
128 | | - } |
129 | | - |
130 | 111 | @Configuration |
131 | 112 | static class BaseConfiguration { |
132 | 113 |
|
|
0 commit comments