Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java')
-rwxr-xr-xbundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java61
1 files changed, 17 insertions, 44 deletions
diff --git a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java
index 15480ef54..eaf4b6bb8 100755
--- a/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java
+++ b/bundles/archived/org.eclipse.equinox.console.tests/src/org/eclipse/equinox/console/telnet/TelnetCommandWithConfigAdminTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011, 2012 SAP AG
+ * Copyright (c) 2011, 2017 SAP AG and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -10,35 +10,21 @@
*******************************************************************************/
package org.eclipse.equinox.console.telnet;
-import java.io.File;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
-import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.net.Socket;
-import java.util.Collection;
import java.util.Dictionary;
import java.util.Hashtable;
-import junit.framework.Assert;
-
import org.apache.felix.service.command.CommandProcessor;
import org.apache.felix.service.command.CommandSession;
import org.easymock.EasyMock;
-import org.easymock.IAnswer;
import org.eclipse.equinox.console.common.ConsoleInputStream;
-import org.junit.After;
-import org.junit.Before;
import org.junit.Test;
-import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
-import org.osgi.framework.BundleException;
-import org.osgi.framework.BundleListener;
-import org.osgi.framework.Filter;
-import org.osgi.framework.FrameworkListener;
-import org.osgi.framework.InvalidSyntaxException;
-import org.osgi.framework.ServiceListener;
-import org.osgi.framework.ServiceReference;
import org.osgi.framework.ServiceRegistration;
import org.osgi.service.cm.ManagedService;
@@ -69,7 +55,7 @@ public class TelnetCommandWithConfigAdminTests {
EasyMock.replay(processor);
final ServiceRegistration<?> registration = EasyMock.createMock(ServiceRegistration.class);
- registration.setProperties((Dictionary)EasyMock.anyObject());
+ registration.setProperties((Dictionary<String, ?>)EasyMock.anyObject());
EasyMock.expectLastCall();
EasyMock.replay(registration);
@@ -81,11 +67,9 @@ public class TelnetCommandWithConfigAdminTests {
(String)EasyMock.anyObject(),
(ManagedService)EasyMock.anyObject(),
(Dictionary<String, ?>)EasyMock.anyObject())
- ).andAnswer((IAnswer<ServiceRegistration<?>>) new IAnswer<ServiceRegistration<?>>() {
- public ServiceRegistration<?> answer() {
- configurator = (ManagedService) EasyMock.getCurrentArguments()[1];
- return registration;
- }
+ ).andAnswer(() -> {
+ configurator = (ManagedService) EasyMock.getCurrentArguments()[1];
+ return registration;
});
EasyMock.expect(
context.registerService(
@@ -96,15 +80,13 @@ public class TelnetCommandWithConfigAdminTests {
TelnetCommand command = new TelnetCommand(processor, context);
command.startService();
- Dictionary props = new Hashtable();
+ Dictionary<String, String> props = new Hashtable<>();
props.put("port", TELNET_PORT);
props.put("host", HOST);
props.put("enabled", TRUE);
configurator.updated(props);
- Socket socketClient = null;
- try {
- socketClient = new Socket(HOST, Integer.parseInt(TELNET_PORT));
+ try (Socket socketClient = new Socket(HOST, Integer.parseInt(TELNET_PORT));){
OutputStream outClient = socketClient.getOutputStream();
outClient.write(TEST_CONTENT);
outClient.write('\n');
@@ -117,9 +99,6 @@ public class TelnetCommandWithConfigAdminTests {
// do nothing
}
} finally {
- if (socketClient != null) {
- socketClient.close();
- }
command.telnet(new String[] {STOP_COMMAND});
}
EasyMock.verify(context);
@@ -149,7 +128,7 @@ public class TelnetCommandWithConfigAdminTests {
EasyMock.replay(processor);
final ServiceRegistration<?> registration = EasyMock.createMock(ServiceRegistration.class);
- registration.setProperties((Dictionary)EasyMock.anyObject());
+ registration.setProperties((Dictionary<String, ?>)EasyMock.anyObject());
EasyMock.expectLastCall();
EasyMock.replay(registration);
@@ -161,11 +140,9 @@ public class TelnetCommandWithConfigAdminTests {
(String)EasyMock.anyObject(),
(ManagedService)EasyMock.anyObject(),
(Dictionary<String, ?>)EasyMock.anyObject())
- ).andAnswer((IAnswer<ServiceRegistration<?>>) new IAnswer<ServiceRegistration<?>>() {
- public ServiceRegistration<?> answer() {
- configurator = (ManagedService) EasyMock.getCurrentArguments()[1];
- return registration;
- }
+ ).andAnswer(() -> {
+ configurator = (ManagedService) EasyMock.getCurrentArguments()[1];
+ return registration;
});
EasyMock.expect(
context.registerService(
@@ -176,7 +153,7 @@ public class TelnetCommandWithConfigAdminTests {
TelnetCommand command = new TelnetCommand(processor, context);
command.startService();
- Dictionary props = new Hashtable();
+ Dictionary<String, String> props = new Hashtable<>();
props.put("port", TELNET_PORT);
props.put("host", HOST);
if (isDefault == false) {
@@ -184,16 +161,12 @@ public class TelnetCommandWithConfigAdminTests {
}
configurator.updated(props);
- Socket socketClient = null;
- try {
- socketClient = new Socket(HOST, Integer.parseInt(TELNET_PORT));
- Assert.fail("It should not be possible to open a socket to " + HOST + ":" + TELNET_PORT);
+ try (Socket socketClient = new Socket(HOST, Integer.parseInt(TELNET_PORT))){
+
+ fail("It should not be possible to open a socket to " + HOST + ":" + TELNET_PORT);
} catch (IOException e) {
// this is ok, there should be an exception
} finally {
- if (socketClient != null) {
- socketClient.close();
- }
try {
command.telnet(new String[] {STOP_COMMAND});
} catch (IllegalStateException e) {

Back to the top