|
37 | 37 | import org.springframework.boot.autoconfigure.AutoConfigurations;
|
38 | 38 | import org.springframework.boot.autoconfigure.jmx.JmxAutoConfiguration;
|
39 | 39 | import org.springframework.boot.test.context.runner.ApplicationContextRunner;
|
| 40 | +import org.springframework.boot.test.context.runner.ContextConsumer; |
| 41 | +import org.springframework.context.ConfigurableApplicationContext; |
40 | 42 |
|
41 | 43 | import static org.assertj.core.api.Assertions.assertThat;
|
42 | 44 | import static org.mockito.ArgumentMatchers.any;
|
|
52 | 54 | */
|
53 | 55 | class JmxEndpointAutoConfigurationTests {
|
54 | 56 |
|
| 57 | + private static final ContextConsumer<ConfigurableApplicationContext> NO_OPERATION = (context) -> { |
| 58 | + }; |
| 59 | + |
55 | 60 | private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
|
56 | 61 | .withConfiguration(AutoConfigurations.of(EndpointAutoConfiguration.class, JmxAutoConfiguration.class,
|
57 | 62 | JmxEndpointAutoConfiguration.class))
|
@@ -90,11 +95,11 @@ void jmxEndpointWithContextHierarchyGeneratesUniqueNamesForEachEndpoint() throws
|
90 | 95 | given(this.mBeanServer.queryNames(any(), any()))
|
91 | 96 | .willReturn(new HashSet<>(Arrays.asList(new ObjectName("test:test=test"))));
|
92 | 97 | ArgumentCaptor<ObjectName> objectName = ArgumentCaptor.forClass(ObjectName.class);
|
93 |
| - this.contextRunner.withPropertyValues("spring.jmx.enabled=true").with(mockMBeanServer()).run((parent) -> { |
94 |
| - this.contextRunner.withPropertyValues("spring.jmx.enabled=true").withParent(parent).run((child) -> { |
95 |
| - }); |
96 |
| - this.contextRunner.withPropertyValues("spring.jmx.enabled=true").withParent(parent).run((child) -> { |
97 |
| - }); |
| 98 | + ApplicationContextRunner jmxEnabledContextRunner = this.contextRunner |
| 99 | + .withPropertyValues("spring.jmx.enabled=true"); |
| 100 | + jmxEnabledContextRunner.with(mockMBeanServer()).run((parent) -> { |
| 101 | + jmxEnabledContextRunner.withParent(parent).run(NO_OPERATION); |
| 102 | + jmxEnabledContextRunner.withParent(parent).run(NO_OPERATION); |
98 | 103 | });
|
99 | 104 | then(this.mBeanServer).should(times(3)).registerMBean(any(Object.class), objectName.capture());
|
100 | 105 | Set<ObjectName> uniqueValues = new HashSet<>(objectName.getAllValues());
|
|
0 commit comments