Skip to content

Commit 03bd50c

Browse files
committed
minor items
1 parent 959b138 commit 03bd50c

File tree

1 file changed

+24
-22
lines changed

1 file changed

+24
-22
lines changed

subprojects/groovy-jmx/src/test/groovy/groovy/jmx/builder/JmxClientConnectorFactoryTest.groovy

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
package groovy.jmx.builder
2020

2121
import org.junit.jupiter.api.AfterEach
22+
import org.junit.jupiter.api.Assumptions
2223
import org.junit.jupiter.api.BeforeEach
2324
import org.junit.jupiter.api.Test
2425

@@ -27,22 +28,29 @@ import javax.management.remote.rmi.RMIConnectorServer
2728

2829
import static groovy.test.GroovyAssert.shouldFail
2930

30-
class JmxClientConnectorFactoryTest {
31-
def builder
32-
int defaultPort = 10990
33-
def rmi
31+
final class JmxClientConnectorFactoryTest {
32+
33+
private JmxBuilder builder
34+
private Map rmi
3435

3536
@BeforeEach
3637
void setUp() {
37-
def hostAddress = getHostAddress()
38-
println "hostAddress: ${hostAddress}"
39-
System.setProperty("java.rmi.server.hostname", hostAddress)
40-
builder = new JmxBuilder()
38+
System.setProperty('java.rmi.server.hostname', hostAddress)
39+
40+
final int defaultPort = 10990
4141
rmi = JmxConnectorHelper.createRmiRegistry(defaultPort)
42+
43+
builder = new JmxBuilder()
44+
try {
45+
builder.getMBeanServer()
46+
} catch (e) {
47+
Assumptions.abort(e.getMessage())
48+
}
4249
}
4350

4451
@AfterEach
4552
void tearDown() {
53+
System.clearProperty('java.rmi.server.hostname')
4654
JmxConnectorHelper.destroyRmiRegistry(rmi.registry)
4755
}
4856

@@ -51,12 +59,9 @@ class JmxClientConnectorFactoryTest {
5159
RMIConnectorServer server = builder.serverConnector(port: rmi.port)
5260
server.start()
5361

54-
RMIConnector client = builder.clientConnector(
55-
port: rmi.port
56-
)
57-
58-
assert client
62+
RMIConnector client = builder.clientConnector(port: rmi.port)
5963
client.connect()
64+
6065
server.stop()
6166
}
6267

@@ -74,34 +79,31 @@ class JmxClientConnectorFactoryTest {
7479
@Test
7580
void testJmxClientConnectorFailure() {
7681
shouldFail {
77-
RMIConnector client = builder.clientConnector(
78-
port: 1099
79-
)
80-
assert client
82+
RMIConnector client = builder.clientConnector(port: 1099)
8183
client.connect()
8284
}
8385
}
8486

85-
static String getHostAddress() {
87+
//--------------------------------------------------------------------------
88+
89+
private static String getHostAddress() {
8690
try {
8791
Enumeration<NetworkInterface> allNetInterfaces = NetworkInterface.getNetworkInterfaces()
8892
while (allNetInterfaces.hasMoreElements()) {
89-
NetworkInterface netInterface = (NetworkInterface) allNetInterfaces.nextElement()
93+
NetworkInterface netInterface = allNetInterfaces.nextElement()
9094
Enumeration<InetAddress> addresses = netInterface.getInetAddresses()
9195
while (addresses.hasMoreElements()) {
9296
InetAddress ip = (InetAddress) addresses.nextElement()
9397
if (ip != null
9498
&& ip instanceof Inet4Address
9599
&& !ip.isLoopbackAddress()
96-
&& ip.getHostAddress().indexOf(":") == -1) {
100+
&& ip.getHostAddress().indexOf(':') == -1) {
97101
return ip.getHostAddress()
98102
}
99103
}
100104
}
101105
} catch (Exception e) {
102106
e.printStackTrace()
103107
}
104-
return null
105108
}
106-
107109
}

0 commit comments

Comments
 (0)