Skip to content
Commits on Source (5)
......@@ -20,9 +20,9 @@ Information regarding source code management, builds, coding standards, and more
Contributor License Agreement:
------------------------------
Before your contribution can be accepted by the project, you need to create and electronically sign the Eclipse Foundation Contributor License Agreement (CLA).
Before your contribution can be accepted by the project, you need to create and electronically sign the Eclipse Foundation Contributor License Agreement (ECA).
- http://www.eclipse.org/legal/CLA.php
- http://www.eclipse.org/legal/ECA.php
Contact:
--------
......
......@@ -10,3 +10,4 @@ Import-Package: junit.framework;version="4.8.1",
org.easymock;version="2.4.0",
org.junit;version="4.8.1"
Fragment-Host: org.eclipse.equinox.console.ssh, org.eclipse.equinox.console
Automatic-Module-Name: org.eclipse.equinox.console.ssh.tests
......@@ -14,7 +14,7 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>org.eclipse.equinox.bundles</groupId>
<version>4.7.3-SNAPSHOT</version>
<version>4.8.0-SNAPSHOT</version>
<relativePath>../../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.equinox</groupId>
......
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.junit.JUNIT_CONTAINER/4"/>
<classpathentry kind="output" path="bin"/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.APILeak=warning
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
org.eclipse.jdt.core.compiler.problem.comparingIdentical=warning
org.eclipse.jdt.core.compiler.problem.deadCode=warning
org.eclipse.jdt.core.compiler.problem.deprecation=warning
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
org.eclipse.jdt.core.compiler.problem.emptyStatement=warning
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.5
org.eclipse.jdt.core.compiler.problem.explicitlyClosedAutoCloseable=warning
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=disabled
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=warning
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
org.eclipse.jdt.core.compiler.problem.missingDefaultCase=ignore
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingEnumCaseDespiteDefault=disabled
org.eclipse.jdt.core.compiler.problem.missingHashCodeMethod=ignore
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=warning
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotationForInterfaceMethodImplementation=enabled
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
org.eclipse.jdt.core.compiler.problem.missingSynchronizedOnInheritedMethod=ignore
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
org.eclipse.jdt.core.compiler.problem.redundantSpecificationOfTypeArguments=warning
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=warning
org.eclipse.jdt.core.compiler.problem.reportMethodCanBePotentiallyStatic=ignore
org.eclipse.jdt.core.compiler.problem.reportMethodCanBeStatic=ignore
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
org.eclipse.jdt.core.compiler.problem.unavoidableGenericTypeProblems=enabled
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=warning
org.eclipse.jdt.core.compiler.problem.unclosedCloseable=warning
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentType=warning
org.eclipse.jdt.core.compiler.problem.unlikelyCollectionMethodArgumentTypeStrict=disabled
org.eclipse.jdt.core.compiler.problem.unlikelyEqualsArgumentType=info
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=warning
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
org.eclipse.jdt.core.compiler.problem.unusedExceptionParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
org.eclipse.jdt.core.compiler.problem.unusedObjectAllocation=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=ignore
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
org.eclipse.jdt.core.compiler.source=1.8
......@@ -2,11 +2,12 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Console tests
Bundle-SymbolicName: org.eclipse.equinox.console.tests
Bundle-Version: 1.0.0.qualifier
Bundle-Version: 1.1.0.qualifier
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-RequiredExecutionEnvironment: JavaSE-1.8
Import-Package: junit.framework;version="4.8.1",
org.apache.sshd.client.future,
org.easymock;version="2.4.0",
org.junit;version="4.8.1"
Fragment-Host: org.eclipse.equinox.console
Automatic-Module-Name: org.eclipse.equinox.console.tests
......@@ -14,11 +14,11 @@
<parent>
<artifactId>tests-pom</artifactId>
<groupId>org.eclipse.equinox.bundles</groupId>
<version>4.7.3-SNAPSHOT</version>
<version>4.8.0-SNAPSHOT</version>
<relativePath>../../tests-pom/</relativePath>
</parent>
<groupId>org.eclipse.equinox</groupId>
<artifactId>org.eclipse.equinox.console.tests</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<packaging>eclipse-test-plugin</packaging>
</project>
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -30,7 +30,7 @@ public class ActivatorTests {
@Test
public void testGetCommandMethods() {
Set<String> commandNames = new HashSet<String>();
Set<String> commandNames = new HashSet<>();
commandNames.add("_testMethod1");
commandNames.add("_testMethod2");
commandNames.add("_testMethod3");
......@@ -67,10 +67,7 @@ public class ActivatorTests {
}
private void _method(CommandInterpreter i) {
}
@Override
public String getHelp() {
// TODO Auto-generated method stub
return null;
......
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -29,7 +29,7 @@ public class CommandProviderAdapterTest {
public void testMain() throws Exception {
CommandProvider provider = new TestCommandProvider();
Method[] methods = TestCommandProvider.class.getMethods();
Set<Method> m = new HashSet<Method>();
Set<Method> m = new HashSet<>();
for (Method method : methods) {
if (method.getName().startsWith("_")) {
m.add(method);
......@@ -54,6 +54,7 @@ public class CommandProviderAdapterTest {
return i.nextArgument();
}
@Override
public String getHelp() {
return "this is a test command provider";
}
......
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -22,24 +22,30 @@ public class ConsoleInputStreamTests {
@Test
public void addReadBufferTest() throws Exception {
ConsoleInputStream in = new ConsoleInputStream();
try (ConsoleInputStream in = new ConsoleInputStream()) {
byte[] data = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' };
in.add(data);
byte[] read = new byte[DATA_LENGTH];
for (int i = 0; i < DATA_LENGTH; i++) {
in.read(read, i, 1);
Assert.assertEquals("Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + read[i], read[i], data[i]);
Assert.assertEquals(
"Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + read[i],
read[i], data[i]);
}
}
}
@Test
public void addReadTest() throws Exception {
ConsoleInputStream in = new ConsoleInputStream();
try (ConsoleInputStream in = new ConsoleInputStream()) {
byte[] data = new byte[] { (byte) 'a', (byte) 'b', (byte) 'c', (byte) 'd' };
in.add(data);
for (int i = 0; i < DATA_LENGTH; i++) {
byte symbol = (byte) in.read();
Assert.assertEquals("Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + symbol, symbol, data[i]);
Assert.assertEquals(
"Incorrect char read; position " + i + " expected: " + data[i] + ", actual: " + symbol, symbol,
data[i]);
}
}
}
}
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -23,7 +23,7 @@ public class ConsoleOutputStreamTests {
@Test
public void testWrite() throws Exception {
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ConsoleOutputStream out = new ConsoleOutputStream(byteOut);
try (ConsoleOutputStream out = new ConsoleOutputStream(byteOut)) {
byte[] data = new byte[] { 'a', 'b', 'c', 'd' };
for (byte b : data) {
out.write(b);
......@@ -39,3 +39,4 @@ public class ConsoleOutputStreamTests {
}
}
}
}
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -31,7 +31,7 @@ public class CommandNamesCompleterTests {
@Test
public void testGetCandidates() throws Exception {
Set<String> commands = new HashSet<String>();
Set<String> commands = new HashSet<>();
commands.add("equinox:bundles");
commands.add("equinox:diag");
commands.add("equinox:setprop");
......
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -72,13 +72,13 @@ public class CompletionHandlerTests {
expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{}).anyTimes();
replay(context);
Set<String> variables = new HashSet<String>();
Set<String> variables = new HashSet<>();
variables.add("SCOPE");
variables.add("PROMPT");
variables.add("ECHO_ON");
variables.add("ECHO");
Set<String> commands = new HashSet<String>();
Set<String> commands = new HashSet<>();
commands.add("equinox:bundles");
commands.add("equinox:diag");
commands.add("equinox:setprop");
......@@ -166,10 +166,10 @@ public class CompletionHandlerTests {
private void createFile(File parentDir, String filename) throws IOException {
File file = new File(parentDir.getAbsolutePath() + File.separator + filename);
PrintWriter out = new PrintWriter(new FileOutputStream(file));
try (PrintWriter out = new PrintWriter(new FileOutputStream(file))) {
out.write(filename);
out.flush();
out.close();
}
}
}
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -89,9 +89,9 @@ public class FileNamesCompleterTests {
private void createFile(File parentDir, String filename) throws IOException {
File file = new File(parentDir.getAbsolutePath() + File.separator + filename);
PrintWriter out = new PrintWriter(new FileOutputStream(file));
try (PrintWriter out = new PrintWriter(new FileOutputStream(file))) {
out.write(filename);
out.flush();
out.close();
}
}
}
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -23,7 +23,7 @@ public class StringsCompleterTests {
@Test
public void testGetCandidates() {
Set<String> strings = new HashSet<String>();
Set<String> strings = new HashSet<>();
strings.add("command");
strings.add("SCOPE");
strings.add("equinox:bundles");
......
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -25,7 +25,7 @@ public class VariableNamesCompleterTests {
@Test
public void testGetCandidates() {
Set<String> variables = new HashSet<String>();
Set<String> variables = new HashSet<>();
variables.add("SCOPE");
variables.add("PROMPT");
variables.add("ECHO_ON");
......
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -26,8 +26,7 @@ public class ConsoleInputHandlerTests {
@Test
public void testHandler() throws Exception {
PipedInputStream input = new PipedInputStream();
PipedOutputStream output = new PipedOutputStream(input);
try (PipedInputStream input = new PipedInputStream(); PipedOutputStream output = new PipedOutputStream(input)) {
ConsoleInputStream in = new ConsoleInputStream();
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ConsoleInputHandler handler = new ConsoleInputHandler(input, in, byteOut);
......@@ -46,11 +45,12 @@ public class ConsoleInputHandlerTests {
byte[] read = new byte[expected.length];
in.read(read, 0, expected.length);
for (int i = 0; i < expected.length; i++) {
Assert.assertEquals("Incorrect char read. Position " + i + ", expected " + expected[i] + ", read " + read[i], expected[i], read[i]);
Assert.assertEquals(
"Incorrect char read. Position " + i + ", expected " + expected[i] + ", read " + read[i],
expected[i], read[i]);
}
output.close();
input.close();
}
}
}
/*******************************************************************************
* Copyright (c) 2011 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
......@@ -60,7 +60,7 @@ public class ConsoleInputScannerTests {
@Test
public void test() throws Exception {
Set<TerminalTypeMappings> supportedEscapeSequences = new HashSet<TerminalTypeMappings>();
Set<TerminalTypeMappings> supportedEscapeSequences = new HashSet<>();
supportedEscapeSequences.add(new ANSITerminalTypeMappings());
supportedEscapeSequences.add(new VT100TerminalTypeMappings());
supportedEscapeSequences.add(new VT220TerminalTypeMappings());
......@@ -69,7 +69,7 @@ public class ConsoleInputScannerTests {
for (TerminalTypeMappings ttMappings : supportedEscapeSequences) {
Map<String, KEYS> escapesToKey = ttMappings.getEscapesToKey();
Map<KEYS, byte[]> keysToEscapes = new HashMap<KEYS, byte[]>();
Map<KEYS, byte[]> keysToEscapes = new HashMap<>();
for (Entry<String, KEYS> entry : escapesToKey.entrySet()) {
keysToEscapes.put(entry.getValue(), entry.getKey().getBytes());
}
......@@ -194,7 +194,7 @@ public class ConsoleInputScannerTests {
expect(context.getServiceReferences("org.eclipse.equinox.console.commands.CommandsTracker", null)).andReturn(new ServiceReference[]{});
replay(context);
Set<String> commands = new HashSet<String>();
Set<String> commands = new HashSet<>();
commands.add("equinox:bundles");
commands.add("equinox:bundle");
commands.add("gogo:bundlebylocation");
......
......@@ -37,7 +37,7 @@ public class TelnetCommandTests {
@Test
public void testTelnetCommand() throws Exception {
CommandSession session = EasyMock.createMock(CommandSession.class);
try (CommandSession session = EasyMock.createMock(CommandSession.class)) {
session.put((String)EasyMock.anyObject(), EasyMock.anyObject());
EasyMock.expectLastCall().times(3);
EasyMock.expect(session.execute((String)EasyMock.anyObject())).andReturn(new Object());
......@@ -58,9 +58,7 @@ public class TelnetCommandTests {
TelnetCommand command = new TelnetCommand(processor, context);
command.startService();
Socket socketClient = null;
try {
socketClient = new Socket(HOST, TELNET_PORT);
try (Socket socketClient = new Socket(HOST, TELNET_PORT);){
OutputStream outClient = socketClient.getOutputStream();
outClient.write(TEST_CONTENT);
outClient.write('\n');
......@@ -73,11 +71,9 @@ public class TelnetCommandTests {
// do nothing
}
} finally {
if (socketClient != null) {
socketClient.close();
}
command.telnet(new String[] {STOP_COMMAND});
}
EasyMock.verify(context);
}
}
}
/*******************************************************************************
* 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() {
).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() {
).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) {
......