From c883c87963425a8b856f3490c8d571d23f8b4589 Mon Sep 17 00:00:00 2001
From: Jeroen van Erp
Date: Mon, 23 Jan 2017 09:55:04 +0100
Subject: [PATCH] Fixed a few warnings
---
.../forwarded/RemotePortForwarderTest.java | 20 +++++++-------
.../sshj/test/BaseAlgorithmTest.java | 26 +++++++------------
.../userauth/method/AuthPasswordTest.java | 3 ++-
.../net/schmizz/sshj/sftp/PathHelperTest.java | 4 +--
4 files changed, 23 insertions(+), 30 deletions(-)
diff --git a/src/test/java/com/hierynomus/sshj/connection/channel/forwarded/RemotePortForwarderTest.java b/src/test/java/com/hierynomus/sshj/connection/channel/forwarded/RemotePortForwarderTest.java
index c6b77c5d..a99a2dde 100644
--- a/src/test/java/com/hierynomus/sshj/connection/channel/forwarded/RemotePortForwarderTest.java
+++ b/src/test/java/com/hierynomus/sshj/connection/channel/forwarded/RemotePortForwarderTest.java
@@ -50,7 +50,7 @@ public class RemotePortForwarderTest {
public HttpServer httpServer = new HttpServer();
@Before
- public void setup() throws IOException {
+ public void setUp() throws IOException {
fixture.getServer().setTcpipForwardingFilter(new AcceptAllForwardingFilter());
File file = httpServer.getDocRoot().newFile("index.html");
FileUtil.writeToFile(file, "
Hi!
");
@@ -59,49 +59,49 @@ public class RemotePortForwarderTest {
@Test
public void shouldHaveWorkingHttpServer() throws IOException {
// Just to check that we have a working http server...
- httpGet("127.0.0.1", 8080);
+ assertThat(httpGet("127.0.0.1", 8080), equalTo(200));
}
@Test
public void shouldDynamicallyForwardPortForLocalhost() throws IOException {
SSHClient sshClient = getFixtureClient();
RemotePortForwarder.Forward bind = forwardPort(sshClient, "127.0.0.1", new SinglePort(0));
- httpGet("127.0.0.1", bind.getPort());
+ assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
}
@Test
public void shouldDynamicallyForwardPortForAllIPv4() throws IOException {
SSHClient sshClient = getFixtureClient();
RemotePortForwarder.Forward bind = forwardPort(sshClient, "0.0.0.0", new SinglePort(0));
- httpGet("127.0.0.1", bind.getPort());
+ assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
}
@Test
public void shouldDynamicallyForwardPortForAllProtocols() throws IOException {
SSHClient sshClient = getFixtureClient();
RemotePortForwarder.Forward bind = forwardPort(sshClient, "", new SinglePort(0));
- httpGet("127.0.0.1", bind.getPort());
+ assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
}
@Test
public void shouldForwardPortForLocalhost() throws IOException {
SSHClient sshClient = getFixtureClient();
RemotePortForwarder.Forward bind = forwardPort(sshClient, "127.0.0.1", RANGE);
- httpGet("127.0.0.1", bind.getPort());
+ assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
}
@Test
public void shouldForwardPortForAllIPv4() throws IOException {
SSHClient sshClient = getFixtureClient();
RemotePortForwarder.Forward bind = forwardPort(sshClient, "0.0.0.0", RANGE);
- httpGet("127.0.0.1", bind.getPort());
+ assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
}
@Test
public void shouldForwardPortForAllProtocols() throws IOException {
SSHClient sshClient = getFixtureClient();
RemotePortForwarder.Forward bind = forwardPort(sshClient, "", RANGE);
- httpGet("127.0.0.1", bind.getPort());
+ assertThat(httpGet("127.0.0.1", bind.getPort()), equalTo(200));
}
private RemotePortForwarder.Forward forwardPort(SSHClient sshClient, String address, PortRange portRange) throws IOException {
@@ -122,12 +122,12 @@ public class RemotePortForwarderTest {
}
}
- private void httpGet(String server, int port) throws IOException {
+ private int httpGet(String server, int port) throws IOException {
HttpClient client = HttpClientBuilder.create().build();
String urlString = "http://" + server + ":" + port;
System.out.println("Trying: GET " + urlString);
HttpResponse execute = client.execute(new HttpGet(urlString));
- assertThat(execute.getStatusLine().getStatusCode(), equalTo(200));
+ return execute.getStatusLine().getStatusCode();
}
private SSHClient getFixtureClient() throws IOException {
diff --git a/src/test/java/com/hierynomus/sshj/test/BaseAlgorithmTest.java b/src/test/java/com/hierynomus/sshj/test/BaseAlgorithmTest.java
index d2f6ac7c..7567ac24 100644
--- a/src/test/java/com/hierynomus/sshj/test/BaseAlgorithmTest.java
+++ b/src/test/java/com/hierynomus/sshj/test/BaseAlgorithmTest.java
@@ -42,25 +42,17 @@ public abstract class BaseAlgorithmTest {
@Test
public void shouldVerifyAlgorithm() throws IOException {
- attempt(100);
- }
-
- private void attempt(int times) throws IOException {
- for (int i = 0; i < times; i++) {
+ for (int i = 0; i < 100; i++) {
logger.info("--> Attempt {}", i);
- verify();
- }
- }
-
- private void verify() throws IOException {
- configureServer(fixture.getServer());
- fixture.start();
- Config config = getClientConfig(new DefaultConfig());
- SSHClient sshClient = fixture.connectClient(fixture.setupClient(config));
- assertThat("should be connected", sshClient.isConnected());
- sshClient.disconnect();
+ configureServer(fixture.getServer());
+ fixture.start();
+ Config config = getClientConfig(new DefaultConfig());
+ SSHClient sshClient = fixture.connectClient(fixture.setupClient(config));
+ assertThat("should be connected", sshClient.isConnected());
+ sshClient.disconnect();
// fixture.stopServer();
- fixture.stopClient();
+ fixture.stopClient();
+ }
}
protected abstract Config getClientConfig(DefaultConfig defaultConfig);
diff --git a/src/test/java/com/hierynomus/sshj/userauth/method/AuthPasswordTest.java b/src/test/java/com/hierynomus/sshj/userauth/method/AuthPasswordTest.java
index 9277edf4..1e61e45a 100644
--- a/src/test/java/com/hierynomus/sshj/userauth/method/AuthPasswordTest.java
+++ b/src/test/java/com/hierynomus/sshj/userauth/method/AuthPasswordTest.java
@@ -69,7 +69,7 @@ public class AuthPasswordTest {
fixture.getServer().setPasswordAuthenticator(new PasswordAuthenticator() {
@Override
public boolean authenticate(String username, String password, ServerSession session) {
- if (password.equals("changeme")) {
+ if ("changeme".equals(password)) {
throw new PasswordChangeRequiredException("Password was changeme", "Please provide your updated password", "en_US");
} else {
return password.equals(username);
@@ -84,6 +84,7 @@ public class AuthPasswordTest {
SSHClient sshClient = fixture.setupConnectedDefaultClient();
expectedException.expect(UserAuthException.class);
sshClient.authPassword("jeroen", "changeme");
+ assertThat("Should not have authenticated", !sshClient.isAuthenticated());
}
@Test
diff --git a/src/test/java/net/schmizz/sshj/sftp/PathHelperTest.java b/src/test/java/net/schmizz/sshj/sftp/PathHelperTest.java
index f5465978..5c4f129f 100644
--- a/src/test/java/net/schmizz/sshj/sftp/PathHelperTest.java
+++ b/src/test/java/net/schmizz/sshj/sftp/PathHelperTest.java
@@ -30,9 +30,9 @@ public class PathHelperTest {
@Override
public String canonicalize(String path)
throws IOException {
- if (path.equals("") || path.equals(".") || path.equals("./"))
+ if ("".equals(path) || ".".equals(path) || "./".equals(path))
return "/home/me";
- if (path.equals("..") || path.equals("../"))
+ if ("..".equals(path) || "../".equals(path))
return "/home";
return path;
}