Skip to content

Commit 9f3e333

Browse files
committed
fixed NotificationListenerBean assertion in constructor (SPR-8091)
1 parent c2eafdb commit 9f3e333

File tree

2 files changed

+28
-21
lines changed

2 files changed

+28
-21
lines changed

org.springframework.context/src/main/java/org/springframework/jmx/export/NotificationListenerBean.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2008 the original author or authors.
2+
* Copyright 2002-2011 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.
@@ -20,6 +20,7 @@
2020

2121
import org.springframework.beans.factory.InitializingBean;
2222
import org.springframework.jmx.support.NotificationListenerHolder;
23+
import org.springframework.util.Assert;
2324

2425
/**
2526
* Helper class that aggregates a {@link javax.management.NotificationListener},
@@ -55,6 +56,7 @@ public NotificationListenerBean() {
5556
* @param notificationListener the encapsulated listener
5657
*/
5758
public NotificationListenerBean(NotificationListener notificationListener) {
59+
Assert.notNull(notificationListener, "NotificationListener must not be null");
5860
setNotificationListener(notificationListener);
5961
}
6062

org.springframework.context/src/test/java/org/springframework/jmx/export/MBeanExporterTests.java

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -75,27 +75,22 @@ public void testRegisterNonNotificationListenerType() throws Exception {
7575
try {
7676
exporter.setNotificationListenerMappings(listeners);
7777
fail("Must have thrown a ClassCastException when registering a non-NotificationListener instance as a NotificationListener.");
78-
} catch (ClassCastException expected) {
78+
}
79+
catch (ClassCastException expected) {
7980
}
8081
}
8182

82-
// Note that @Ignore has no effect for JUnit 3.8 TestCase-based tests,
83-
// but we leave it here to allow developers to easily search for ignored
84-
// tests. As a work-around, the method is prefixed with "ignore"
85-
// instead of "test" as required by JUnit 3.x.
86-
//
87-
// See: https://jira.springsource.org/browse/SPR-8091
88-
@Ignore("[SPR-8091] NotificationListenerBean constructor does not throw the expected IllegalArgumentException")
8983
@SuppressWarnings({ "rawtypes", "unchecked" })
90-
public void ignoreTestRegisterNullNotificationListenerType() throws Exception {
84+
public void testRegisterNullNotificationListenerType() throws Exception {
9185
Map listeners = new HashMap();
9286
// put null in as a value...
9387
listeners.put("*", null);
9488
MBeanExporter exporter = new MBeanExporter();
9589
try {
9690
exporter.setNotificationListenerMappings(listeners);
9791
fail("Must have thrown an IllegalArgumentException when registering a null instance as a NotificationListener.");
98-
} catch (IllegalArgumentException expected) {
92+
}
93+
catch (IllegalArgumentException expected) {
9994
}
10095
}
10196

@@ -116,7 +111,8 @@ public void handleNotification(Notification notification, Object handback) {
116111
try {
117112
exporter.afterPropertiesSet();
118113
fail("Must have thrown an MBeanExportException when registering a NotificationListener on a non-existent MBean.");
119-
} catch (MBeanExportException expected) {
114+
}
115+
catch (MBeanExportException expected) {
120116
assertTrue(expected.contains(InstanceNotFoundException.class));
121117
}
122118
}
@@ -473,7 +469,8 @@ public void testSetAutodetectModeToOutOfRangeNegativeValue() throws Exception {
473469
MBeanExporter exporter = new MBeanExporter();
474470
exporter.setAutodetectMode(-1);
475471
fail("Must have failed when supplying an invalid negative out-of-range autodetect mode");
476-
} catch (IllegalArgumentException expected) {
472+
}
473+
catch (IllegalArgumentException expected) {
477474
}
478475
}
479476

@@ -482,7 +479,8 @@ public void testSetAutodetectModeToOutOfRangePositiveValue() throws Exception {
482479
MBeanExporter exporter = new MBeanExporter();
483480
exporter.setAutodetectMode(5);
484481
fail("Must have failed when supplying an invalid positive out-of-range autodetect mode");
485-
} catch (IllegalArgumentException expected) {
482+
}
483+
catch (IllegalArgumentException expected) {
486484
}
487485
}
488486

@@ -491,7 +489,8 @@ public void testSetAutodetectModeNameToNull() throws Exception {
491489
MBeanExporter exporter = new MBeanExporter();
492490
exporter.setAutodetectModeName(null);
493491
fail("Must have failed when supplying a null autodetect mode name");
494-
} catch (IllegalArgumentException expected) {
492+
}
493+
catch (IllegalArgumentException expected) {
495494
}
496495
}
497496

@@ -500,7 +499,8 @@ public void testSetAutodetectModeNameToAnEmptyString() throws Exception {
500499
MBeanExporter exporter = new MBeanExporter();
501500
exporter.setAutodetectModeName("");
502501
fail("Must have failed when supplying an empty autodetect mode name");
503-
} catch (IllegalArgumentException expected) {
502+
}
503+
catch (IllegalArgumentException expected) {
504504
}
505505
}
506506

@@ -509,7 +509,8 @@ public void testSetAutodetectModeNameToAWhitespacedString() throws Exception {
509509
MBeanExporter exporter = new MBeanExporter();
510510
exporter.setAutodetectModeName(" \t");
511511
fail("Must have failed when supplying a whitespace-only autodetect mode name");
512-
} catch (IllegalArgumentException expected) {
512+
}
513+
catch (IllegalArgumentException expected) {
513514
}
514515
}
515516

@@ -518,7 +519,8 @@ public void testSetAutodetectModeNameToARubbishValue() throws Exception {
518519
MBeanExporter exporter = new MBeanExporter();
519520
exporter.setAutodetectModeName("That Hansel is... *sssooo* hot right now!");
520521
fail("Must have failed when supplying a whitespace-only autodetect mode name");
521-
} catch (IllegalArgumentException expected) {
522+
}
523+
catch (IllegalArgumentException expected) {
522524
}
523525
}
524526

@@ -530,7 +532,8 @@ public void testNotRunningInBeanFactoryAndPassedBeanNameToExport() throws Except
530532
exporter.setBeans(beans);
531533
exporter.afterPropertiesSet();
532534
fail("Expecting exception because MBeanExporter is not running in a BeanFactory and was passed bean name to (lookup and then) export");
533-
} catch (MBeanExportException expected) {
535+
}
536+
catch (MBeanExportException expected) {
534537
}
535538
}
536539

@@ -540,7 +543,8 @@ public void testNotRunningInBeanFactoryAndAutodetectionIsOn() throws Exception {
540543
exporter.setAutodetectMode(MBeanExporter.AUTODETECT_ALL);
541544
exporter.afterPropertiesSet();
542545
fail("Expecting exception because MBeanExporter is not running in a BeanFactory and was configured to autodetect beans");
543-
} catch (MBeanExportException expected) {
546+
}
547+
catch (MBeanExportException expected) {
544548
}
545549
}
546550

@@ -634,7 +638,8 @@ public void testMBeanIsUnregisteredForRuntimeExceptionDuringInitialization() thr
634638
try {
635639
exporter.afterPropertiesSet();
636640
fail("Must have failed during creation of RuntimeExceptionThrowingConstructorBean");
637-
} catch (RuntimeException expected) {
641+
}
642+
catch (RuntimeException expected) {
638643
}
639644

640645
assertIsNotRegistered("Must have unregistered all previously registered MBeans due to RuntimeException",

0 commit comments

Comments
 (0)