Skip to content

Commit a227b6f

Browse files
Just cleaning things up.
1 parent 20c52dc commit a227b6f

File tree

2 files changed

+26
-53
lines changed

2 files changed

+26
-53
lines changed

java/BUILDING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ To build the Android test controller from the command line:
121121
- Once the test controller is running, open a terminal, change to the java subdirectory, and execute:
122122

123123
```shell
124-
python allTests --android --all
124+
python allTests.py --android --all
125125
```
126126

127127
## Generating the API reference

java/test/android/controller/src/main/java/com/zeroc/testcontroller/ControllerApp.java

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ private static class TestSuiteBundle {
3535
_class = (Class<? extends test.TestHelper>) _loader.loadClass(name);
3636
}
3737

38-
test.TestHelper newInstance() throws IllegalAccessException, InstantiationException {
38+
test.TestHelper newInstance() throws ReflectiveOperationException {
3939
if (_class == null) {
4040
return null;
4141
}
42-
return _class.newInstance();
42+
return _class.getDeclaredConstructor().newInstance();
4343
}
4444

4545
ClassLoader getClassLoader() {
@@ -119,22 +119,20 @@ public synchronized void setIpv6Address(String address) {
119119
public List<String> getAddresses(boolean ipv6) {
120120
List<String> addresses = new java.util.ArrayList<>();
121121
try {
122-
java.util.Enumeration<java.net.NetworkInterface> ifaces =
123-
java.net.NetworkInterface.getNetworkInterfaces();
122+
java.util.Enumeration<java.net.NetworkInterface> ifaces = java.net.NetworkInterface.getNetworkInterfaces();
124123
while (ifaces.hasMoreElements()) {
125124
java.net.NetworkInterface iface = ifaces.nextElement();
126125
java.util.Enumeration<java.net.InetAddress> addrs = iface.getInetAddresses();
127126
while (addrs.hasMoreElements()) {
128127
java.net.InetAddress addr = addrs.nextElement();
129-
if ((ipv6 && addr instanceof java.net.Inet6Address)
130-
|| (!ipv6 && !(addr instanceof java.net.Inet6Address))) {
128+
boolean isInet6Address = addr instanceof java.net.Inet6Address;
129+
if ((ipv6 && isInet6Address) || (!ipv6 && !isInet6Address)) {
131130
addresses.add(addr.getHostAddress());
132131
}
133132
}
134133
}
135134
} catch (java.net.SocketException ex) {
136-
// Ignore, if we are not able to retrieve the network interfaces, we return an empty
137-
// list.
135+
// Ignore, if we are not able to retrieve the network interfaces, we return an empty list.
138136
}
139137
return addresses;
140138
}
@@ -186,27 +184,22 @@ public ControllerI(boolean bluetooth) {
186184
}
187185
else
188186
{
189-
initData.properties.setProperty(
190-
"ControllerAdapter.AdapterId", java.util.UUID.randomUUID().toString());
187+
initData.properties.setProperty("ControllerAdapter.AdapterId", java.util.UUID.randomUUID().toString());
191188
initData.properties.setProperty("ControllerAdapter.Endpoints", "tcp");
192189
if (bluetooth) {
193-
initData.properties.setProperty(
194-
"Ice.Plugin.IceBT", "com.zeroc.IceBT.PluginFactory");
190+
initData.properties.setProperty("Ice.Plugin.IceBT", "com.zeroc.IceBT.PluginFactory");
195191
}
196-
initData.properties.setProperty(
197-
"Ice.Plugin.IceDiscovery", "com.zeroc.IceDiscovery.PluginFactory");
192+
initData.properties.setProperty("Ice.Plugin.IceDiscovery", "com.zeroc.IceDiscovery.PluginFactory");
198193
initData.properties.setProperty("IceDiscovery.DomainId", "TestController");
199194
}
200195

201196
_communicator = new com.zeroc.Ice.Communicator(initData);
202-
com.zeroc.Ice.ObjectAdapter adapter =
203-
_communicator.createObjectAdapter("ControllerAdapter");
197+
com.zeroc.Ice.ObjectAdapter adapter = _communicator.createObjectAdapter("ControllerAdapter");
204198
ProcessControllerPrx processController =
205199
ProcessControllerPrx.uncheckedCast(
206200
adapter.add(
207201
new ProcessControllerI(),
208-
com.zeroc.Ice.Util.stringToIdentity(
209-
"Android/ProcessController")));
202+
com.zeroc.Ice.Util.stringToIdentity("Android/ProcessController")));
210203
adapter.activate();
211204

212205
if (!isEmulator())
@@ -228,14 +221,11 @@ public void registerProcessController(
228221
if (e1 != null) {
229222
handleException(e1, adapter, registry, processController);
230223
} else {
231-
com.zeroc.Ice.Connection connection =
232-
registry.ice_getConnection();
224+
com.zeroc.Ice.Connection connection = registry.ice_getConnection();
233225
connection.setAdapter(adapter);
234226
connection.setCloseCallback(
235227
con -> {
236-
println(
237-
"connection with process controller"
238-
+ " registry closed");
228+
println("connection with process controller registry closed");
239229
while (true) {
240230
try {
241231
Thread.sleep(500);
@@ -244,19 +234,14 @@ public void registerProcessController(
244234
// Ignore and try again.
245235
}
246236
}
247-
registerProcessController(
248-
adapter, registry, processController);
237+
registerProcessController(adapter, registry, processController);
249238
});
250239

251240
registry.setProcessControllerAsync(processController)
252241
.whenCompleteAsync(
253242
(r2, e2) -> {
254243
if (e2 != null) {
255-
handleException(
256-
e2,
257-
adapter,
258-
registry,
259-
processController);
244+
handleException(e2, adapter, registry, processController);
260245
}
261246
});
262247
}
@@ -268,8 +253,7 @@ public void handleException(
268253
final com.zeroc.Ice.ObjectAdapter adapter,
269254
final ProcessControllerRegistryPrx registry,
270255
final ProcessControllerPrx processController) {
271-
if (ex instanceof com.zeroc.Ice.ConnectFailedException
272-
|| ex instanceof com.zeroc.Ice.TimeoutException) {
256+
if (ex instanceof com.zeroc.Ice.ConnectFailedException || ex instanceof com.zeroc.Ice.TimeoutException) {
273257
while (true) {
274258
try {
275259
Thread.sleep(500);
@@ -300,20 +284,12 @@ public ControllerHelperI(TestSuiteBundle bundle, String[] args) {
300284
public void communicatorInitialized(Communicator communicator) {}
301285

302286
public java.io.InputStream loadResource(String path) {
303-
switch (path) {
304-
case "server.p12" -> {
305-
return getResources().openRawResource(R.raw.server);
306-
}
307-
case "client.p12" -> {
308-
return getResources().openRawResource(R.raw.client);
309-
}
310-
case "ca.p12" -> {
311-
return getResources().openRawResource(R.raw.ca);
312-
}
313-
default -> {
314-
return null;
315-
}
316-
}
287+
return switch (path) {
288+
case "server.p12" -> getResources().openRawResource(R.raw.server);
289+
case "client.p12" -> getResources().openRawResource(R.raw.client);
290+
case "ca.p12" -> getResources().openRawResource(R.raw.ca);
291+
default -> null;
292+
};
317293
}
318294

319295
public void run() {
@@ -371,8 +347,7 @@ private synchronized void waitReady(int timeout) throws Test.Common.ProcessFaile
371347
try {
372348
wait(timeout * 1000L);
373349
if (Time.currentMonotonicTimeMillis() - now > timeout * 1000L) {
374-
throw new Test.Common.ProcessFailedException(
375-
"timed out waiting for the process to be ready");
350+
throw new Test.Common.ProcessFailedException("timed out waiting for the process to be ready");
376351
}
377352
} catch (InterruptedException ex) {
378353
// Ignore and try again.
@@ -390,8 +365,7 @@ private synchronized int waitSuccess(int timeout) throws Test.Common.ProcessFail
390365
try {
391366
wait(timeout * 1000L);
392367
if (Time.currentMonotonicTimeMillis() - now > timeout * 1000L) {
393-
throw new Test.Common.ProcessFailedException(
394-
"timed out waiting for the process to complete");
368+
throw new Test.Common.ProcessFailedException("timed out waiting for the process to complete");
395369
}
396370
} catch (InterruptedException ex) {
397371
// Ignore and try again.
@@ -428,8 +402,7 @@ public Test.Common.ProcessPrx start(
428402
TestSuiteBundle bundle = new TestSuiteBundle(className, getClassLoader());
429403
ControllerHelperI mainHelper = new ControllerHelperI(bundle, args);
430404
mainHelper.start();
431-
return Test.Common.ProcessPrx.uncheckedCast(
432-
current.adapter.addWithUUID(new ProcessI(mainHelper)));
405+
return Test.Common.ProcessPrx.uncheckedCast(current.adapter.addWithUUID(new ProcessI(mainHelper)));
433406
} catch (Exception ex) {
434407
throw new Test.Common.ProcessFailedException(
435408
"testsuite `" + testsuite + "' exe ` " + exe + "' start failed:\n" + ex);

0 commit comments

Comments
 (0)