1717package org .springframework .jmx .access ;
1818
1919import java .beans .PropertyDescriptor ;
20+ import java .lang .management .ManagementFactory ;
21+ import java .lang .management .MemoryMXBean ;
22+ import java .lang .management .ThreadMXBean ;
2023import java .lang .reflect .Method ;
2124import java .net .BindException ;
2225import java .util .HashMap ;
3033
3134import org .junit .jupiter .api .Test ;
3235
36+ import org .springframework .aop .framework .ProxyFactory ;
3337import org .springframework .jmx .AbstractMBeanServerTests ;
3438import org .springframework .jmx .IJmxTestBean ;
3539import org .springframework .jmx .JmxException ;
5054 * @author Sam Brannen
5155 * @author Chris Beams
5256 */
53- public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
57+ class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
5458
5559 protected static final String OBJECT_NAME = "spring:test=proxy" ;
5660
@@ -87,14 +91,14 @@ protected IJmxTestBean getProxy() throws Exception {
8791 }
8892
8993 @ Test
90- public void testProxyClassIsDifferent () throws Exception {
94+ void testProxyClassIsDifferent () throws Exception {
9195 assumeTrue (runTests );
9296 IJmxTestBean proxy = getProxy ();
93- assertThat (( proxy .getClass () != IJmxTestBean . class )) .as ("The proxy class should be different than the base class" ).isTrue ( );
97+ assertThat (proxy .getClass ()) .as ("The proxy class should be different than the base class" ).isNotSameAs ( IJmxTestBean . class );
9498 }
9599
96100 @ Test
97- public void testDifferentProxiesSameClass () throws Exception {
101+ void testDifferentProxiesSameClass () throws Exception {
98102 assumeTrue (runTests );
99103 IJmxTestBean proxy1 = getProxy ();
100104 IJmxTestBean proxy2 = getProxy ();
@@ -104,79 +108,79 @@ public void testDifferentProxiesSameClass() throws Exception {
104108 }
105109
106110 @ Test
107- public void testGetAttributeValue () throws Exception {
111+ void testGetAttributeValue () throws Exception {
108112 assumeTrue (runTests );
109113 IJmxTestBean proxy1 = getProxy ();
110114 int age = proxy1 .getAge ();
111115 assertThat (age ).as ("The age should be 100" ).isEqualTo (100 );
112116 }
113117
114118 @ Test
115- public void testSetAttributeValue () throws Exception {
119+ void testSetAttributeValue () throws Exception {
116120 assumeTrue (runTests );
117121 IJmxTestBean proxy = getProxy ();
118122 proxy .setName ("Rob Harrop" );
119123 assertThat (target .getName ()).as ("The name of the bean should have been updated" ).isEqualTo ("Rob Harrop" );
120124 }
121125
122126 @ Test
123- public void testSetAttributeValueWithRuntimeException () throws Exception {
127+ void testSetAttributeValueWithRuntimeException () throws Exception {
124128 assumeTrue (runTests );
125129 IJmxTestBean proxy = getProxy ();
126130 assertThatIllegalArgumentException ().isThrownBy (() ->
127131 proxy .setName ("Juergen" ));
128132 }
129133
130134 @ Test
131- public void testSetAttributeValueWithCheckedException () throws Exception {
135+ void testSetAttributeValueWithCheckedException () throws Exception {
132136 assumeTrue (runTests );
133137 IJmxTestBean proxy = getProxy ();
134138 assertThatExceptionOfType (ClassNotFoundException .class ).isThrownBy (() ->
135139 proxy .setName ("Juergen Class" ));
136140 }
137141
138142 @ Test
139- public void testSetAttributeValueWithIOException () throws Exception {
143+ void testSetAttributeValueWithIOException () throws Exception {
140144 assumeTrue (runTests );
141145 IJmxTestBean proxy = getProxy ();
142146 assertThatIOException ().isThrownBy (() ->
143147 proxy .setName ("Juergen IO" ));
144148 }
145149
146150 @ Test
147- public void testSetReadOnlyAttribute () throws Exception {
151+ void testSetReadOnlyAttribute () throws Exception {
148152 assumeTrue (runTests );
149153 IJmxTestBean proxy = getProxy ();
150154 assertThatExceptionOfType (InvalidInvocationException .class ).isThrownBy (() ->
151155 proxy .setAge (900 ));
152156 }
153157
154158 @ Test
155- public void testInvokeNoArgs () throws Exception {
159+ void testInvokeNoArgs () throws Exception {
156160 assumeTrue (runTests );
157161 IJmxTestBean proxy = getProxy ();
158162 long result = proxy .myOperation ();
159163 assertThat (result ).as ("The operation should return 1" ).isEqualTo (1 );
160164 }
161165
162166 @ Test
163- public void testInvokeArgs () throws Exception {
167+ void testInvokeArgs () throws Exception {
164168 assumeTrue (runTests );
165169 IJmxTestBean proxy = getProxy ();
166170 int result = proxy .add (1 , 2 );
167171 assertThat (result ).as ("The operation should return 3" ).isEqualTo (3 );
168172 }
169173
170174 @ Test
171- public void testInvokeUnexposedMethodWithException () throws Exception {
175+ void testInvokeUnexposedMethodWithException () throws Exception {
172176 assumeTrue (runTests );
173177 IJmxTestBean bean = getProxy ();
174178 assertThatExceptionOfType (InvalidInvocationException .class ).isThrownBy (() ->
175179 bean .dontExposeMe ());
176180 }
177181
178182 @ Test
179- public void testTestLazyConnectionToRemote () throws Exception {
183+ void testTestLazyConnectionToRemote () throws Exception {
180184 assumeTrue (runTests );
181185
182186 final int port = SocketUtils .findAvailableTcpPort ();
@@ -219,46 +223,25 @@ public void testTestLazyConnectionToRemote() throws Exception {
219223 catch (JmxException ex ) {
220224 // expected
221225 }
222-
223- connector = JMXConnectorServerFactory .newJMXConnectorServer (url , null , getServer ());
224- connector .start ();
225-
226- // should now be able to access data via the lazy proxy
227- try {
228- assertThat (bean .getName ()).isEqualTo ("Rob Harrop" );
229- assertThat (bean .getAge ()).isEqualTo (100 );
230- }
231- finally {
232- connector .stop ();
233- }
234226 }
235227
236- /*
237228 public void testMXBeanAttributeAccess () throws Exception {
238229 MBeanClientInterceptor interceptor = new MBeanClientInterceptor ();
239230 interceptor .setServer (ManagementFactory .getPlatformMBeanServer ());
240231 interceptor .setObjectName ("java.lang:type=Memory" );
241232 interceptor .setManagementInterface (MemoryMXBean .class );
242233 MemoryMXBean proxy = ProxyFactory .getProxy (MemoryMXBean .class , interceptor );
243- assertTrue (proxy.getHeapMemoryUsage().getMax() > 0);
234+ assertThat (proxy .getHeapMemoryUsage ().getMax ()). isGreaterThan ( 0 );
244235 }
245236
246237 public void testMXBeanOperationAccess () throws Exception {
247238 MBeanClientInterceptor interceptor = new MBeanClientInterceptor ();
248239 interceptor .setServer (ManagementFactory .getPlatformMBeanServer ());
249240 interceptor .setObjectName ("java.lang:type=Threading" );
250241 ThreadMXBean proxy = ProxyFactory .getProxy (ThreadMXBean .class , interceptor );
251- assertTrue (proxy.getThreadInfo(Thread.currentThread().getId()).getStackTrace() != null );
242+ assertThat (proxy .getThreadInfo (Thread .currentThread ().getId ()).getStackTrace ()). isNotNull ( );
252243 }
253244
254- public void testMXBeanAttributeListAccess() throws Exception {
255- MBeanClientInterceptor interceptor = new MBeanClientInterceptor();
256- interceptor.setServer(ManagementFactory.getPlatformMBeanServer());
257- interceptor.setObjectName("com.sun.management:type=HotSpotDiagnostic");
258- HotSpotDiagnosticMXBean proxy = ProxyFactory.getProxy(HotSpotDiagnosticMXBean.class, interceptor);
259- assertFalse(proxy.getDiagnosticOptions().isEmpty());
260- }
261- */
262245
263246 private static class ProxyTestAssembler extends AbstractReflectiveMBeanInfoAssembler {
264247
0 commit comments