Skip to content

Commit 1064894

Browse files
committed
Update AbstractMBeanServerTests hierarchy to JUnit 4
This commit lays the groundwork for introducing TestGroup#JMXMP and related assumptions in select JMX-related tests in a subsequent commit; JUnit assumptions require JUnit 4+ to function properly, so the entire AbstractMBeanServerTests hierarchy must be moved over to JUnit 4+ style. Issue: SPR-8089
1 parent cbe0309 commit 1064894

22 files changed

+222
-18
lines changed

spring-context/src/test/java/org/springframework/jmx/AbstractMBeanServerTests.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2012 the original author or authors.
2+
* Copyright 2002-2013 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,13 +20,15 @@
2020
import javax.management.MBeanServerFactory;
2121
import javax.management.ObjectName;
2222

23-
import junit.framework.TestCase;
24-
23+
import org.junit.After;
24+
import org.junit.Before;
2525
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
2626
import org.springframework.context.ConfigurableApplicationContext;
2727
import org.springframework.context.support.GenericApplicationContext;
2828
import org.springframework.util.MBeanTestUtils;
2929

30+
import static org.junit.Assert.*;
31+
3032
/**
3133
* <strong>Note:</strong> the JMX test suite requires the presence of the
3234
* {@code jmxremote_optional.jar} in your classpath. Thus, if you
@@ -40,12 +42,13 @@
4042
* @author Rob Harrop
4143
* @author Juergen Hoeller
4244
* @author Sam Brannen
45+
* @author Chris Beams
4346
*/
44-
public abstract class AbstractMBeanServerTests extends TestCase {
47+
public abstract class AbstractMBeanServerTests {
4548

4649
protected MBeanServer server;
4750

48-
@Override
51+
@Before
4952
public final void setUp() throws Exception {
5053
this.server = MBeanServerFactory.createMBeanServer();
5154
try {
@@ -64,8 +67,8 @@ protected ConfigurableApplicationContext loadContext(String configLocation) {
6467
return ctx;
6568
}
6669

67-
@Override
68-
protected void tearDown() throws Exception {
70+
@After
71+
public void tearDown() throws Exception {
6972
releaseServer();
7073
onTearDown();
7174
}

spring-context/src/test/java/org/springframework/jmx/access/MBeanClientInterceptorTests.java

+14
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import javax.management.remote.JMXConnectorServerFactory;
3030
import javax.management.remote.JMXServiceURL;
3131

32+
import org.junit.Test;
3233
import org.springframework.jmx.AbstractMBeanServerTests;
3334
import org.springframework.jmx.IJmxTestBean;
3435
import org.springframework.jmx.JmxException;
@@ -40,6 +41,7 @@
4041
* @author Rob Harrop
4142
* @author Juergen Hoeller
4243
* @author Sam Brannen
44+
* @author Chris Beams
4345
*/
4446
public class MBeanClientInterceptorTests extends AbstractMBeanServerTests {
4547

@@ -77,13 +79,15 @@ protected IJmxTestBean getProxy() throws Exception {
7779
return (IJmxTestBean) factory.getObject();
7880
}
7981

82+
@Test
8083
public void testProxyClassIsDifferent() throws Exception {
8184
if (!runTests)
8285
return;
8386
IJmxTestBean proxy = getProxy();
8487
assertTrue("The proxy class should be different than the base class", (proxy.getClass() != IJmxTestBean.class));
8588
}
8689

90+
@Test
8791
public void testDifferentProxiesSameClass() throws Exception {
8892
if (!runTests)
8993
return;
@@ -94,6 +98,7 @@ public void testDifferentProxiesSameClass() throws Exception {
9498
assertSame("The proxy classes should be the same", proxy1.getClass(), proxy2.getClass());
9599
}
96100

101+
@Test
97102
public void testGetAttributeValue() throws Exception {
98103
if (!runTests)
99104
return;
@@ -102,6 +107,7 @@ public void testGetAttributeValue() throws Exception {
102107
assertEquals("The age should be 100", 100, age);
103108
}
104109

110+
@Test
105111
public void testSetAttributeValue() throws Exception {
106112
if (!runTests)
107113
return;
@@ -110,6 +116,7 @@ public void testSetAttributeValue() throws Exception {
110116
assertEquals("The name of the bean should have been updated", "Rob Harrop", target.getName());
111117
}
112118

119+
@Test
113120
public void testSetAttributeValueWithRuntimeException() throws Exception {
114121
if (!runTests)
115122
return;
@@ -122,6 +129,7 @@ public void testSetAttributeValueWithRuntimeException() throws Exception {
122129
}
123130
}
124131

132+
@Test
125133
public void testSetAttributeValueWithCheckedException() throws Exception {
126134
if (!runTests)
127135
return;
@@ -134,6 +142,7 @@ public void testSetAttributeValueWithCheckedException() throws Exception {
134142
}
135143
}
136144

145+
@Test
137146
public void testSetAttributeValueWithIOException() throws Exception {
138147
if (!runTests)
139148
return;
@@ -146,6 +155,7 @@ public void testSetAttributeValueWithIOException() throws Exception {
146155
}
147156
}
148157

158+
@Test
149159
public void testSetReadOnlyAttribute() throws Exception {
150160
if (!runTests)
151161
return;
@@ -158,6 +168,7 @@ public void testSetReadOnlyAttribute() throws Exception {
158168
}
159169
}
160170

171+
@Test
161172
public void testInvokeNoArgs() throws Exception {
162173
if (!runTests)
163174
return;
@@ -166,6 +177,7 @@ public void testInvokeNoArgs() throws Exception {
166177
assertEquals("The operation should return 1", 1, result);
167178
}
168179

180+
@Test
169181
public void testInvokeArgs() throws Exception {
170182
if (!runTests)
171183
return;
@@ -174,6 +186,7 @@ public void testInvokeArgs() throws Exception {
174186
assertEquals("The operation should return 3", 3, result);
175187
}
176188

189+
@Test
177190
public void testInvokeUnexposedMethodWithException() throws Exception {
178191
if (!runTests)
179192
return;
@@ -186,6 +199,7 @@ public void testInvokeUnexposedMethodWithException() throws Exception {
186199
}
187200
}
188201

202+
@Test
189203
public void testTestLazyConnectionToRemote() throws Exception {
190204
if (!runTests)
191205
return;

spring-context/src/test/java/org/springframework/jmx/access/RemoteMBeanClientInterceptorTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
/**
3030
* @author Rob Harrop
31+
* @author Chris Beams
3132
*/
3233
public class RemoteMBeanClientInterceptorTests extends MBeanClientInterceptorTests {
3334

spring-context/src/test/java/org/springframework/jmx/export/CustomEditorConfigurerTests.java

+5
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@
2222

2323
import javax.management.ObjectName;
2424

25+
import org.junit.Test;
2526
import org.springframework.jmx.AbstractJmxTests;
2627

28+
import static org.junit.Assert.*;
29+
2730
/**
2831
* @author Rob Harrop
2932
*/
@@ -36,6 +39,7 @@ protected String getApplicationContextPath() {
3639
return "org/springframework/jmx/export/customConfigurer.xml";
3740
}
3841

42+
@Test
3943
public void testDatesInJmx() throws Exception {
4044
// System.out.println(getServer().getClass().getName());
4145
ObjectName oname = new ObjectName("bean:name=dateRange");
@@ -47,6 +51,7 @@ public void testDatesInJmx() throws Exception {
4751
assertEquals("endDate ", getEndDate(), endJmx);
4852
}
4953

54+
@Test
5055
public void testGetDates() throws Exception {
5156
DateRange dr = (DateRange) getContext().getBean("dateRange");
5257

spring-context/src/test/java/org/springframework/jmx/export/MBeanExporterOperationsTests.java

+2
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import org.springframework.jmx.export.naming.ObjectNamingStrategy;
2929
import org.springframework.jmx.support.ObjectNameManager;
3030

31+
import static org.junit.Assert.*;
32+
3133
/**
3234
* @author Rob Harrop
3335
* @author Juergen Hoeller

0 commit comments

Comments
 (0)