Skip to content

Commit a869d25

Browse files
committed
Polish
1 parent eac4c7e commit a869d25

17 files changed

+566
-573
lines changed

spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/admin/SpringApplicationAdminJmxAutoConfigurationTests.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class SpringApplicationAdminJmxAutoConfigurationTests {
5959
@Rule
6060
public final ExpectedException thrown = ExpectedException.none();
6161

62-
private final MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer();
62+
private final MBeanServer server = ManagementFactory.getPlatformMBeanServer();
6363

6464
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
6565
.withConfiguration(AutoConfigurations.of(JmxAutoConfiguration.class,
@@ -70,15 +70,15 @@ public void notRegisteredByDefault()
7070
throws MalformedObjectNameException, InstanceNotFoundException {
7171
this.contextRunner.run((context) -> {
7272
this.thrown.expect(InstanceNotFoundException.class);
73-
this.mBeanServer.getObjectInstance(createDefaultObjectName());
73+
this.server.getObjectInstance(createDefaultObjectName());
7474
});
7575
}
7676

7777
@Test
7878
public void registeredWithProperty() throws Exception {
7979
this.contextRunner.withPropertyValues(ENABLE_ADMIN_PROP).run((context) -> {
8080
ObjectName objectName = createDefaultObjectName();
81-
ObjectInstance objectInstance = this.mBeanServer.getObjectInstance(objectName);
81+
ObjectInstance objectInstance = this.server.getObjectInstance(objectName);
8282
assertThat(objectInstance).as("Lifecycle bean should have been registered")
8383
.isNotNull();
8484
});
@@ -87,18 +87,20 @@ public void registeredWithProperty() throws Exception {
8787
@Test
8888
public void registerWithCustomJmxName() throws InstanceNotFoundException {
8989
String customJmxName = "org.acme:name=FooBar";
90-
this.contextRunner.withSystemProperties(
91-
"spring.application.admin.jmx-name=" + customJmxName)
90+
this.contextRunner
91+
.withSystemProperties(
92+
"spring.application.admin.jmx-name=" + customJmxName)
9293
.withPropertyValues(ENABLE_ADMIN_PROP).run((context) -> {
93-
try {
94-
this.mBeanServer.getObjectInstance(createObjectName(customJmxName));
95-
}
96-
catch (InstanceNotFoundException ex) {
97-
fail("Admin MBean should have been exposed with custom name");
98-
}
99-
this.thrown.expect(InstanceNotFoundException.class); // Should not be exposed
100-
this.mBeanServer.getObjectInstance(createDefaultObjectName());
101-
});
94+
try {
95+
this.server.getObjectInstance(createObjectName(customJmxName));
96+
}
97+
catch (InstanceNotFoundException ex) {
98+
fail("Admin MBean should have been exposed with custom name");
99+
}
100+
this.thrown.expect(InstanceNotFoundException.class); // Should not be
101+
// exposed
102+
this.server.getObjectInstance(createDefaultObjectName());
103+
});
102104
}
103105

104106
@Test
@@ -110,7 +112,7 @@ public void registerWithSimpleWebApp() throws Exception {
110112
SpringApplicationAdminJmxAutoConfiguration.class)
111113
.run("--" + ENABLE_ADMIN_PROP, "--server.port=0")) {
112114
assertThat(context).isInstanceOf(ServletWebServerApplicationContext.class);
113-
assertThat(this.mBeanServer.getAttribute(createDefaultObjectName(),
115+
assertThat(this.server.getAttribute(createDefaultObjectName(),
114116
"EmbeddedWebApplication")).isEqualTo(Boolean.TRUE);
115117
int expected = ((ServletWebServerApplicationContext) context).getWebServer()
116118
.getPort();
@@ -128,11 +130,10 @@ public void onlyRegisteredOnceWhenThereIsAChildContext() throws Exception {
128130
.child(JmxAutoConfiguration.class,
129131
SpringApplicationAdminJmxAutoConfiguration.class)
130132
.web(WebApplicationType.NONE);
131-
132133
try (ConfigurableApplicationContext parent = parentBuilder
133134
.run("--" + ENABLE_ADMIN_PROP);
134-
ConfigurableApplicationContext child = childBuilder
135-
.run("--" + ENABLE_ADMIN_PROP)) {
135+
ConfigurableApplicationContext child = childBuilder
136+
.run("--" + ENABLE_ADMIN_PROP)) {
136137
BeanFactoryUtils.beanOfType(parent.getBeanFactory(),
137138
SpringApplicationAdminMXBeanRegistrar.class);
138139
this.thrown.expect(NoSuchBeanDefinitionException.class);
@@ -155,7 +156,7 @@ private ObjectName createObjectName(String jmxName) {
155156
}
156157

157158
private String getProperty(ObjectName objectName, String key) throws Exception {
158-
return (String) this.mBeanServer.invoke(objectName, "getProperty",
159+
return (String) this.server.invoke(objectName, "getProperty",
159160
new Object[] { key }, new String[] { String.class.getName() });
160161
}
161162

0 commit comments

Comments
 (0)