11/*
2- * Copyright 2002-2013 the original author or authors.
2+ * Copyright 2002-2014 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
2121import java .util .HashMap ;
2222import java .util .List ;
2323import java .util .Map ;
24-
2524import javax .management .Attribute ;
2625import javax .management .InstanceNotFoundException ;
2726import javax .management .JMException ;
3433import javax .management .modelmbean .ModelMBeanInfo ;
3534
3635import org .junit .Test ;
36+
3737import org .springframework .aop .framework .ProxyFactory ;
3838import org .springframework .beans .factory .support .BeanDefinitionBuilder ;
3939import org .springframework .beans .factory .support .DefaultListableBeanFactory ;
@@ -68,25 +68,10 @@ public final class MBeanExporterTests extends AbstractMBeanServerTests {
6868
6969 private static final String OBJECT_NAME = "spring:test=jmxMBeanAdaptor" ;
7070
71- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
72- @ Test
73- public void testRegisterNonNotificationListenerType () throws Exception {
74- Map listeners = new HashMap ();
75- // put a non-NotificationListener instance in as a value...
76- listeners .put ("*" , this );
77- MBeanExporter exporter = new MBeanExporter ();
78- try {
79- exporter .setNotificationListenerMappings (listeners );
80- fail ("Must have thrown a ClassCastException when registering a non-NotificationListener instance as a NotificationListener." );
81- }
82- catch (ClassCastException expected ) {
83- }
84- }
8571
86- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
8772 @ Test
8873 public void testRegisterNullNotificationListenerType () throws Exception {
89- Map listeners = new HashMap ();
74+ Map < String , NotificationListener > listeners = new HashMap < String , NotificationListener > ();
9075 // put null in as a value...
9176 listeners .put ("*" , null );
9277 MBeanExporter exporter = new MBeanExporter ();
@@ -98,10 +83,9 @@ public void testRegisterNullNotificationListenerType() throws Exception {
9883 }
9984 }
10085
101- @ SuppressWarnings ({ "rawtypes" , "unchecked" })
10286 @ Test
10387 public void testRegisterNotificationListenerForNonExistentMBean () throws Exception {
104- Map listeners = new HashMap ();
88+ Map < String , NotificationListener > listeners = new HashMap < String , NotificationListener > ();
10589 NotificationListener dummyListener = new NotificationListener () {
10690 @ Override
10791 public void handleNotification (Notification notification , Object handback ) {
@@ -175,7 +159,8 @@ public void testAutodetectMBeans() throws Exception {
175159 assertNotNull (instance );
176160 instance = server .getObjectInstance (ObjectNameManager .getInstance ("spring:mbean3=true" ));
177161 assertNotNull (instance );
178- } finally {
162+ }
163+ finally {
179164 bf .destroySingletons ();
180165 }
181166 }
@@ -193,9 +178,11 @@ public void testAutodetectWithExclude() throws Exception {
193178 try {
194179 server .getObjectInstance (ObjectNameManager .getInstance ("spring:mbean=false" ));
195180 fail ("MBean with name spring:mbean=false should have been excluded" );
196- } catch (InstanceNotFoundException expected ) {
197181 }
198- } finally {
182+ catch (InstanceNotFoundException expected ) {
183+ }
184+ }
185+ finally {
199186 bf .destroySingletons ();
200187 }
201188 }
@@ -217,7 +204,8 @@ public void testAutodetectLazyMBeans() throws Exception {
217204 assertNotNull (server .getObjectInstance (oname ));
218205 name = (String ) server .getAttribute (oname , "Name" );
219206 assertEquals ("Invalid name returned" , "Juergen Hoeller" , name );
220- } finally {
207+ }
208+ finally {
221209 bf .destroySingletons ();
222210 }
223211 }
@@ -228,7 +216,8 @@ public void testAutodetectNoMBeans() throws Exception {
228216 new XmlBeanDefinitionReader (bf ).loadBeanDefinitions (new ClassPathResource ("autodetectNoMBeans.xml" , getClass ()));
229217 try {
230218 bf .getBean ("exporter" );
231- } finally {
219+ }
220+ finally {
232221 bf .destroySingletons ();
233222 }
234223 }
@@ -241,7 +230,7 @@ public void testWithMBeanExporterListeners() throws Exception {
241230 MBeanExporter exporter = new MBeanExporter ();
242231 exporter .setBeans (getBeanMap ());
243232 exporter .setServer (server );
244- exporter .setListeners (new MBeanExporterListener [] { listener1 , listener2 } );
233+ exporter .setListeners (listener1 , listener2 );
245234 exporter .afterPropertiesSet ();
246235 exporter .destroy ();
247236
@@ -257,7 +246,7 @@ public void testExportJdkProxy() throws Exception {
257246 ProxyFactory factory = new ProxyFactory ();
258247 factory .setTarget (bean );
259248 factory .addAdvice (new NopInterceptor ());
260- factory .setInterfaces (new Class <?>[] { IJmxTestBean .class } );
249+ factory .setInterfaces (IJmxTestBean .class );
261250
262251 IJmxTestBean proxy = (IJmxTestBean ) factory .getProxy ();
263252 String name = "bean:mmm=whatever" ;
@@ -377,8 +366,8 @@ public void testWithExposeClassLoader() throws Exception {
377366
378367 assertIsRegistered ("Bean instance not registered" , objectName );
379368
380- Object result = server .invoke (objectName , "add" , new Object [] { new Integer (2 ), new Integer (3 ) }, new String [] {
381- int .class .getName (), int .class .getName () });
369+ Object result = server .invoke (objectName , "add" , new Object [] {new Integer (2 ), new Integer (3 )}, new String [] {
370+ int .class .getName (), int .class .getName ()});
382371
383372 assertEquals ("Incorrect result return from add" , result , new Integer (5 ));
384373 assertEquals ("Incorrect attribute value" , name , server .getAttribute (objectName , "Name" ));
@@ -593,7 +582,7 @@ public void testMBeanIsNotUnregisteredSpuriouslyIfSomeExternalProcessHasUnregist
593582 exporter .setBeans (getBeanMap ());
594583 exporter .setServer (this .server );
595584 MockMBeanExporterListener listener = new MockMBeanExporterListener ();
596- exporter .setListeners (new MBeanExporterListener [] { listener } );
585+ exporter .setListeners (listener );
597586 exporter .afterPropertiesSet ();
598587 assertIsRegistered ("The bean was not registered with the MBeanServer" ,
599588 ObjectNameManager .getInstance (OBJECT_NAME ));
@@ -702,6 +691,7 @@ private void assertListener(MockMBeanExporterListener listener) throws Malformed
702691 assertEquals ("Incorrect ObjectName in unregister" , desired , listener .getUnregistered ().get (0 ));
703692 }
704693
694+
705695 private static class InvokeDetectAssembler implements MBeanInfoAssembler {
706696
707697 private boolean invoked = false ;
@@ -713,6 +703,7 @@ public ModelMBeanInfo getMBeanInfo(Object managedResource, String beanKey) throw
713703 }
714704 }
715705
706+
716707 private static class MockMBeanExporterListener implements MBeanExporterListener {
717708
718709 private List <ObjectName > registered = new ArrayList <ObjectName >();
@@ -738,6 +729,7 @@ public List<ObjectName> getUnregistered() {
738729 }
739730 }
740731
732+
741733 private static class SelfNamingTestBean implements SelfNaming {
742734
743735 private ObjectName objectName ;
@@ -752,11 +744,13 @@ public ObjectName getObjectName() throws MalformedObjectNameException {
752744 }
753745 }
754746
747+
755748 public static interface PersonMBean {
756749
757750 String getName ();
758751 }
759752
753+
760754 public static class Person implements PersonMBean {
761755
762756 private String name ;
@@ -771,6 +765,7 @@ public void setName(String name) {
771765 }
772766 }
773767
768+
774769 public static final class StubNotificationListener implements NotificationListener {
775770
776771 private List <Notification > notifications = new ArrayList <Notification >();
@@ -785,6 +780,7 @@ public List<Notification> getNotifications() {
785780 }
786781 }
787782
783+
788784 private static class RuntimeExceptionThrowingConstructorBean {
789785
790786 @ SuppressWarnings ("unused" )
@@ -793,6 +789,7 @@ public RuntimeExceptionThrowingConstructorBean() {
793789 }
794790 }
795791
792+
796793 private static final class NamedBeanAutodetectCapableMBeanInfoAssemblerStub extends
797794 SimpleReflectiveMBeanInfoAssembler implements AutodetectCapableMBeanInfoAssembler {
798795
0 commit comments