You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mina.apache.org by lg...@apache.org on 2016/02/26 06:07:58 UTC
[2/5] mina-sshd git commit: [SSHD-655] Apply checkstyle plugin to
test source code as well
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferTest.java
index d5b2d0f..82b16f2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferTest.java
@@ -21,8 +21,6 @@ package org.apache.sshd.common.util.buffer;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
-import org.apache.sshd.common.util.buffer.Buffer;
-import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.FixMethodOrder;
import org.junit.Test;
@@ -39,12 +37,12 @@ public class BufferTest extends BaseTestSupport {
long expected = 1234567890123456789L;
try (ByteArrayOutputStream stream = new ByteArrayOutputStream()) {
- try (DataOutputStream ds = new DataOutputStream(stream)) {
- ds.writeLong(expected);
- }
+ try (DataOutputStream ds = new DataOutputStream(stream)) {
+ ds.writeLong(expected);
+ }
- Buffer buffer = new ByteArrayBuffer(stream.toByteArray());
- assertEquals("Mismatched recovered value", expected, buffer.getLong());
+ Buffer buffer = new ByteArrayBuffer(stream.toByteArray());
+ assertEquals("Mismatched recovered value", expected, buffer.getLong());
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferUtilsTest.java
index 6714202..388ad0f 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/buffer/BufferUtilsTest.java
@@ -53,13 +53,13 @@ public class BufferUtilsTest extends BaseTestSupport {
@Test
public void testGetCompactClone() {
byte[] expected = getCurrentTestName().getBytes(StandardCharsets.UTF_8);
- final int OFFSET = Byte.SIZE / 2;
- byte[] data = new byte[expected.length + 2 * OFFSET];
+ final int testOffset = Byte.SIZE / 2;
+ byte[] data = new byte[expected.length + 2 * testOffset];
Random rnd = new Random(System.nanoTime());
rnd.nextBytes(data);
- System.arraycopy(expected, 0, data, OFFSET, expected.length);
+ System.arraycopy(expected, 0, data, testOffset, expected.length);
- Buffer buf = ByteArrayBuffer.getCompactClone(data, OFFSET, expected.length);
+ Buffer buf = ByteArrayBuffer.getCompactClone(data, testOffset, expected.length);
assertEquals("Mismatched cloned buffer read position", 0, buf.rpos());
assertEquals("Mismatched cloned buffer available size", expected.length, buf.available());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/common/util/io/EmptyInputStreamTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/util/io/EmptyInputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/util/io/EmptyInputStreamTest.java
index ada47a7..adf23b4 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/util/io/EmptyInputStreamTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/util/io/EmptyInputStreamTest.java
@@ -77,7 +77,7 @@ public class EmptyInputStreamTest extends BaseTestSupport {
try {
int data = in.read();
assertFalse(message + ": Unexpected success in read(): " + data, errorExpected);
- assertEquals(message + ": Mismatched read() result", (-1), data);
+ assertEquals(message + ": Mismatched read() result", -1, data);
} catch (IOException e) {
assertTrue(message + ": Unexpected error on read(): " + e.getMessage(), errorExpected);
}
@@ -86,7 +86,7 @@ public class EmptyInputStreamTest extends BaseTestSupport {
try {
int len = in.read(bytes);
assertFalse(message + ": Unexpected success in read([]): " + BufferUtils.toHex(':', bytes), errorExpected);
- assertEquals(message + ": Mismatched read([]) result", (-1), len);
+ assertEquals(message + ": Mismatched read([]) result", -1, len);
} catch (IOException e) {
assertTrue(message + ": Unexpected error on read([]): " + e.getMessage(), errorExpected);
}
@@ -94,7 +94,7 @@ public class EmptyInputStreamTest extends BaseTestSupport {
try {
int len = in.read(bytes, 0, bytes.length);
assertFalse(message + ": Unexpected success in read([],int,int): " + BufferUtils.toHex(':', bytes), errorExpected);
- assertEquals(message + ": Mismatched read([],int,int) result", (-1), len);
+ assertEquals(message + ": Mismatched read([],int,int) result", -1, len);
} catch (IOException e) {
assertTrue(message + ": Unexpected error on read([],int,int): " + e.getMessage(), errorExpected);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
index f4acfc0..b8aa9b5 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/ClientUserAuthServiceOld.java
@@ -38,6 +38,7 @@ import org.apache.sshd.deprecated.UserAuth.Result;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+// CHECKSTYLE:OFF
public class ClientUserAuthServiceOld extends AbstractCloseable implements Service {
public static class Factory implements ServiceFactory {
@@ -205,3 +206,4 @@ public class ClientUserAuthServiceOld extends AbstractCloseable implements Servi
}
}
+// CHECKSTYLE:ON
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
index 5d26ab0..bffbe62 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthAgent.java
@@ -35,6 +35,7 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
/**
* Authentication delegating to an SSH agent
*/
+// CHECKSTYLE:OFF
public class UserAuthAgent extends AbstractUserAuth {
private final SshAgent agent;
@@ -126,3 +127,4 @@ public class UserAuthAgent extends AbstractUserAuth {
}
}
}
+// CHECKSTYLE:ON
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
index 8b62602..bfa6a1d 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthKeyboardInteractive.java
@@ -32,6 +32,7 @@ import org.apache.sshd.common.util.buffer.Buffer;
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
* @author <a href="mailto:j.kapitza@schwarze-allianz.de">Jens Kapitza</a>
*/
+// CHECKSTYLE:OFF
public class UserAuthKeyboardInteractive extends AbstractUserAuth {
private final String password;
@@ -117,5 +118,5 @@ public class UserAuthKeyboardInteractive extends AbstractUserAuth {
}
}
}
-
-}
\ No newline at end of file
+}
+// CHECKSTYLE:ON
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
index accdb1a..df420b8 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPassword.java
@@ -30,6 +30,7 @@ import org.apache.sshd.common.util.buffer.Buffer;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+// CHECKSTYLE:OFF
public class UserAuthPassword extends AbstractUserAuth {
private final String password;
@@ -76,3 +77,4 @@ public class UserAuthPassword extends AbstractUserAuth {
}
}
+// CHECKSTYLE:ON
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
index 3c1ddca..1f9be26 100644
--- a/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
+++ b/sshd-core/src/test/java/org/apache/sshd/deprecated/UserAuthPublicKey.java
@@ -36,6 +36,7 @@ import org.apache.sshd.common.util.buffer.ByteArrayBuffer;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
+// CHECKSTYLE:OFF
public class UserAuthPublicKey extends AbstractUserAuth {
private final KeyPair key;
@@ -111,3 +112,4 @@ public class UserAuthPublicKey extends AbstractUserAuth {
}
}
}
+// CHECKSTYLE:ON
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/PublickeyAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/PublickeyAuthenticatorTest.java b/sshd-core/src/test/java/org/apache/sshd/server/PublickeyAuthenticatorTest.java
index 88767ec..813f5a3 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/PublickeyAuthenticatorTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/PublickeyAuthenticatorTest.java
@@ -67,9 +67,9 @@ public class PublickeyAuthenticatorTest extends BaseTestSupport {
Mockito.when(key.getPublicExponent()).thenReturn(BigInteger.ONE);
ServerSession session = Mockito.mock(ServerSession.class);
- Object[] invArgs = new Object[] { null /* username */, null /* key */, null /* server session */ };
+ Object[] invArgs = new Object[] {null /* username */, null /* key */, null /* server session */};
boolean expected = authenticator.isAccepted();
- boolean[] flags = new boolean[] { false, true };
+ boolean[] flags = new boolean[] {false, true};
for (boolean useUsername : flags) {
invArgs[0] = useUsername ? getCurrentTestName() : null;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/ServerMain.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerMain.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerMain.java
deleted file mode 100644
index d8af833..0000000
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerMain.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
-package org.apache.sshd.server;
-
-/**
- * An activator for the {@link SshServer#main(String[])} - the reason it is
- * here is because the logging configuration is available only for test scope
- *
- * @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
- */
-public class ServerMain {
- public static void main(String[] args) throws Throwable {
- SshServer.main(args);
- }
-}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
index 2187f92..8357be5 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerSessionListenerTest.java
@@ -131,7 +131,8 @@ public class ServerSessionListenerTest extends BaseTestSupport {
int curCount = 0;
for (int retryCount = 0; retryCount < Byte.SIZE; retryCount++) {
synchronized (eventsMap) {
- if ((curCount = eventsMap.size()) >= 3) {
+ curCount = eventsMap.size();
+ if (curCount >= 3) {
return;
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
index b125de9..7b86595 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/ServerTest.java
@@ -57,6 +57,7 @@ import org.apache.sshd.common.auth.UserAuthMethodFactory;
import org.apache.sshd.common.channel.Channel;
import org.apache.sshd.common.channel.ChannelListener;
import org.apache.sshd.common.channel.TestChannelListener;
+import org.apache.sshd.common.channel.Window;
import org.apache.sshd.common.channel.WindowClosedException;
import org.apache.sshd.common.io.IoSession;
import org.apache.sshd.common.kex.KexProposalOption;
@@ -124,8 +125,8 @@ public class ServerTest extends BaseTestSupport {
*/
@Test
public void testFailAuthenticationWithWaitFor() throws Exception {
- final int MAX_AUTH_REQUESTS = 10;
- PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, MAX_AUTH_REQUESTS);
+ final int maxAllowedAuths = 10;
+ PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, maxAllowedAuths);
sshd.start();
client.setServiceFactories(Arrays.asList(
@@ -146,7 +147,7 @@ public class ServerTest extends BaseTestSupport {
res = s.waitFor(mask, TimeUnit.SECONDS.toMillis(5L));
assertFalse("Timeout signalled", res.contains(ClientSession.ClientSessionEvent.TIMEOUT));
}
- assertTrue("Number trials (" + nbTrials + ") below min.=" + MAX_AUTH_REQUESTS, nbTrials > MAX_AUTH_REQUESTS);
+ assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths);
} finally {
client.stop();
}
@@ -154,8 +155,8 @@ public class ServerTest extends BaseTestSupport {
@Test
public void testFailAuthenticationWithFuture() throws Exception {
- final int MAX_AUTH_REQUESTS = 10;
- PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, MAX_AUTH_REQUESTS);
+ final int maxAllowedAuths = 10;
+ PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.MAX_AUTH_REQUESTS, maxAllowedAuths);
sshd.start();
@@ -179,7 +180,7 @@ public class ServerTest extends BaseTestSupport {
Throwable t = authFuture.getException();
assertNotNull("Missing auth future exception", t);
- assertTrue("Number trials (" + nbTrials + ") below min.=" + MAX_AUTH_REQUESTS, nbTrials > MAX_AUTH_REQUESTS);
+ assertTrue("Number trials (" + nbTrials + ") below min.=" + maxAllowedAuths, nbTrials > maxAllowedAuths);
} finally {
client.stop();
}
@@ -187,13 +188,13 @@ public class ServerTest extends BaseTestSupport {
@Test
public void testAuthenticationTimeout() throws Exception {
- final long AUTH_TIMEOUT = TimeUnit.SECONDS.toMillis(5L);
- PropertyResolverUtils.updateProperty(sshd, FactoryManager.AUTH_TIMEOUT, AUTH_TIMEOUT);
+ final long testAuthTimeout = TimeUnit.SECONDS.toMillis(5L);
+ PropertyResolverUtils.updateProperty(sshd, FactoryManager.AUTH_TIMEOUT, testAuthTimeout);
sshd.start();
client.start();
try (ClientSession s = client.connect(getCurrentTestName(), TEST_LOCALHOST, sshd.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) {
- Collection<ClientSession.ClientSessionEvent> res = s.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED), 2L * AUTH_TIMEOUT);
+ Collection<ClientSession.ClientSessionEvent> res = s.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED), 2L * testAuthTimeout);
assertTrue("Session should be closed: " + res,
res.containsAll(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.WAIT_AUTH)));
} finally {
@@ -205,8 +206,8 @@ public class ServerTest extends BaseTestSupport {
public void testIdleTimeout() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);
TestEchoShell.latch = new CountDownLatch(1);
- final long IDLE_TIMEOUT = 2500;
- PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, IDLE_TIMEOUT);
+ final long testIdleTimeout = 2500L;
+ PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, testIdleTimeout);
sshd.addSessionListener(new SessionListener() {
@Override
@@ -250,7 +251,7 @@ public class ServerTest extends BaseTestSupport {
assertTrue("No open server side channels", GenericUtils.size(channelListener.getOpenChannels()) > 0);
Collection<ClientSession.ClientSessionEvent> res =
- s.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED), 2L * IDLE_TIMEOUT);
+ s.waitFor(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED), 2L * testIdleTimeout);
assertTrue("Session should be closed and authenticated: " + res,
res.containsAll(EnumSet.of(ClientSession.ClientSessionEvent.CLOSED, ClientSession.ClientSessionEvent.AUTHED)));
} finally {
@@ -274,11 +275,11 @@ public class ServerTest extends BaseTestSupport {
sshd.setCommandFactory(new StreamCommand.Factory());
- final long IDLE_TIMEOUT_VALUE = TimeUnit.SECONDS.toMillis(5L);
- PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, IDLE_TIMEOUT_VALUE);
+ final long idleTimeoutValue = TimeUnit.SECONDS.toMillis(5L);
+ PropertyResolverUtils.updateProperty(sshd, FactoryManager.IDLE_TIMEOUT, idleTimeoutValue);
- final long DISCONNECT_TIMEOUT_VALUE = TimeUnit.SECONDS.toMillis(2L);
- PropertyResolverUtils.updateProperty(sshd, FactoryManager.DISCONNECT_TIMEOUT, DISCONNECT_TIMEOUT_VALUE);
+ final long disconnectTimeoutValue = TimeUnit.SECONDS.toMillis(2L);
+ PropertyResolverUtils.updateProperty(sshd, FactoryManager.DISCONNECT_TIMEOUT, disconnectTimeoutValue);
sshd.addSessionListener(new SessionListener() {
@Override
@@ -327,24 +328,27 @@ public class ServerTest extends BaseTestSupport {
Collection<? extends Channel> channels = service.getChannels();
try (Channel channel = channels.iterator().next()) {
- final long MAX_TIMEOUT_VALUE = IDLE_TIMEOUT_VALUE + DISCONNECT_TIMEOUT_VALUE + TimeUnit.SECONDS.toMillis(3L);
- for (long totalNanoTime = 0L; channel.getRemoteWindow().getSize() > 0; ) {
+ final long maxTimeoutValue = idleTimeoutValue + disconnectTimeoutValue + TimeUnit.SECONDS.toMillis(3L);
+ final long maxWaitNanos = TimeUnit.MILLISECONDS.toNanos(maxTimeoutValue);
+ Window wRemote = channel.getRemoteWindow();
+ for (long totalNanoTime = 0L; wRemote.getSize() > 0;) {
long nanoStart = System.nanoTime();
Thread.sleep(1L);
long nanoEnd = System.nanoTime();
long nanoDuration = nanoEnd - nanoStart;
totalNanoTime += nanoDuration;
- assertTrue("Waiting for too long on remote window size to reach zero", totalNanoTime < TimeUnit.MILLISECONDS.toNanos(MAX_TIMEOUT_VALUE));
+ assertTrue("Waiting for too long on remote window size to reach zero", totalNanoTime < maxWaitNanos);
}
LoggerFactory.getLogger(getClass()).info("Waiting for session idle timeouts");
long t0 = System.currentTimeMillis();
- latch.await(1, TimeUnit.MINUTES);
- long t1 = System.currentTimeMillis(), diff = t1 - t0;
- assertTrue("Wait time too low: " + diff, diff > IDLE_TIMEOUT_VALUE);
- assertTrue("Wait time too high: " + diff, diff < MAX_TIMEOUT_VALUE);
+ latch.await(1L, TimeUnit.MINUTES);
+ long t1 = System.currentTimeMillis();
+ long diff = t1 - t0;
+ assertTrue("Wait time too low: " + diff, diff > idleTimeoutValue);
+ assertTrue("Wait time too high: " + diff, diff < maxTimeoutValue);
}
}
} finally {
@@ -381,7 +385,9 @@ public class ServerTest extends BaseTestSupport {
@Override
public void sessionEvent(Session session, Event event) {
if (Event.KeyEstablished.equals(event)) {
- for (KexProposalOption option : new KexProposalOption[]{ KexProposalOption.S2CLANG, KexProposalOption.C2SLANG}) {
+ for (KexProposalOption option : new KexProposalOption[]{
+ KexProposalOption.S2CLANG, KexProposalOption.C2SLANG
+ }) {
assertNull("Unexpected negotiated language for " + option, session.getNegotiatedKexParameter(option));
}
@@ -734,7 +740,9 @@ public class ServerTest extends BaseTestSupport {
Map<String, String> vars = cmdEnv.getEnv();
assertTrue("Mismatched vars count", GenericUtils.size(vars) >= GenericUtils.size(expected));
for (Map.Entry<String, String> ee : expected.entrySet()) {
- String key = ee.getKey(), expValue = ee.getValue(), actValue = vars.get(key);
+ String key = ee.getKey();
+ String expValue = ee.getValue();
+ String actValue = vars.get(key);
assertEquals("Mismatched value for " + key, expValue, actValue);
}
}
@@ -759,7 +767,8 @@ public class ServerTest extends BaseTestSupport {
});
sshd.start();
- String authMethods = GenericUtils.join( // order is important
+ // order is important
+ String authMethods = GenericUtils.join(
Arrays.asList(UserAuthMethodFactory.KB_INTERACTIVE, UserAuthMethodFactory.PUBLIC_KEY, UserAuthMethodFactory.PUBLIC_KEY), ',');
PropertyResolverUtils.updateProperty(client, ClientAuthenticationManager.PREFERRED_AUTHS, authMethods);
@@ -800,11 +809,12 @@ public class ServerTest extends BaseTestSupport {
});
sshd.start();
- String authMethods = GenericUtils.join( // order is important
+ // order is important
+ String authMethods = GenericUtils.join(
Arrays.asList(UserAuthMethodFactory.KB_INTERACTIVE, UserAuthMethodFactory.PUBLIC_KEY, UserAuthMethodFactory.PUBLIC_KEY), ',');
PropertyResolverUtils.updateProperty(client, ClientAuthenticationManager.PREFERRED_AUTHS, authMethods);
final AtomicInteger clientCount = new AtomicInteger(0);
- final String[] replies = { getCurrentTestName() };
+ final String[] replies = {getCurrentTestName()};
client.setUserInteraction(new UserInteraction() {
@Override
public void welcome(ClientSession session, String banner, String lang) {
@@ -868,8 +878,9 @@ public class ServerTest extends BaseTestSupport {
}
public static class TestEchoShell extends EchoShell {
-
+ // CHECKSTYLE:OFF
public static CountDownLatch latch;
+ // CHECKSTYLE:ON
public TestEchoShell() {
super();
@@ -885,6 +896,9 @@ public class ServerTest extends BaseTestSupport {
}
public static class StreamCommand implements Command, Runnable {
+ // CHECKSTYLE:OFF
+ public static CountDownLatch latch;
+ // CHECKSTYLE:ON
public static class Factory implements CommandFactory {
@Override
@@ -893,8 +907,6 @@ public class ServerTest extends BaseTestSupport {
}
}
- public static CountDownLatch latch;
-
private final String name;
private OutputStream out;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/SshServerMain.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/SshServerMain.java b/sshd-core/src/test/java/org/apache/sshd/server/SshServerMain.java
index ef4e231..d4f3c60 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/SshServerMain.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/SshServerMain.java
@@ -25,7 +25,11 @@ package org.apache.sshd.server;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class SshServerMain {
+public final class SshServerMain {
+ private SshServerMain() {
+ throw new UnsupportedOperationException("No instance");
+ }
+
public static void main(String[] args) throws Exception {
SshServer.main(args);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
index a000104..13ce2a9 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/channel/ChannelSessionTest.java
@@ -53,7 +53,7 @@ public class ChannelSessionTest extends BaseTestSupport {
try (ChannelSession channelSession = new ChannelSession() {
{
Window wRemote = getRemoteWindow();
- wRemote.init(PropertyResolverUtils.toPropertyResolver(Collections.<String,Object>emptyMap()));
+ wRemote.init(PropertyResolverUtils.toPropertyResolver(Collections.<String, Object>emptyMap()));
}
}) {
final AtomicBoolean expanded = new AtomicBoolean(false);
@@ -75,7 +75,7 @@ public class ChannelSessionTest extends BaseTestSupport {
try (ChannelSession session = new ChannelSession() {
{
Window wRemote = getRemoteWindow();
- wRemote.init(PropertyResolverUtils.toPropertyResolver(Collections.<String,Object>emptyMap()));
+ wRemote.init(PropertyResolverUtils.toPropertyResolver(Collections.<String, Object>emptyMap()));
}
}) {
session.addCloseFutureListener(new SshFutureListener<CloseFuture>() {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java b/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java
index 5bcc437..0143790 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/command/ScpCommandFactoryTest.java
@@ -60,7 +60,8 @@ public class ScpCommandFactoryTest extends BaseTestSupport {
public void testBuilderCorrectlyInitializesFactory() {
CommandFactory delegate = dummyFactory();
ExecutorService service = dummyExecutor();
- int receiveSize = Short.MAX_VALUE, sendSize = receiveSize + Long.SIZE;
+ int receiveSize = Short.MAX_VALUE;
+ int sendSize = receiveSize + Long.SIZE;
ScpCommandFactory factory = new ScpCommandFactory.Builder()
.withDelegate(delegate)
.withExecutorService(service)
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java
index 33d895e..5ba159c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/config/keys/AuthorizedKeysAuthenticatorTest.java
@@ -71,13 +71,12 @@ public class AuthorizedKeysAuthenticatorTest extends AuthorizedKeysTestSupport {
List<String> keyLines = loadDefaultSupportedKeys();
assertHierarchyTargetFolderExists(file.getParent());
- while(keyLines.size() > 0) {
+ while (keyLines.size() > 0) {
try (Writer w = Files.newBufferedWriter(file, StandardCharsets.UTF_8)) {
w.append(PublicKeyEntry.COMMENT_CHAR)
- .append(' ').append(getCurrentTestName())
- .append(' ').append(String.valueOf(keyLines.size())).append(" remaining keys")
- .append(IoUtils.EOL)
- ;
+ .append(' ').append(getCurrentTestName())
+ .append(' ').append(String.valueOf(keyLines.size())).append(" remaining keys")
+ .append(IoUtils.EOL);
for (String l : keyLines) {
w.append(l).append(IoUtils.EOL);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java b/sshd-core/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java
index 8e45310..3ac6e28 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/jaas/JaasPasswordAuthenticatorTest.java
@@ -18,6 +18,10 @@
*/
package org.apache.sshd.server.jaas;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
import javax.security.auth.Subject;
import javax.security.auth.callback.Callback;
import javax.security.auth.callback.CallbackHandler;
@@ -28,9 +32,6 @@ import javax.security.auth.login.AppConfigurationEntry;
import javax.security.auth.login.Configuration;
import javax.security.auth.login.LoginException;
import javax.security.auth.spi.LoginModule;
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.Map;
import org.apache.sshd.util.test.BaseTestSupport;
import org.junit.After;
@@ -46,6 +47,9 @@ import org.junit.runners.MethodSorters;
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class JaasPasswordAuthenticatorTest extends BaseTestSupport {
+ public JaasPasswordAuthenticatorTest() {
+ super();
+ }
@Before
public void setUp() {
@@ -53,9 +57,9 @@ public class JaasPasswordAuthenticatorTest extends BaseTestSupport {
@Override
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
return new AppConfigurationEntry[]{
- new AppConfigurationEntry(DummyLoginModule.class.getName(),
- AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
- new HashMap<String, Object>())
+ new AppConfigurationEntry(DummyLoginModule.class.getName(),
+ AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
+ new HashMap<String, Object>())
};
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProviderTest.java
index 873c17c..96ddfc6 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProviderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/AbstractGeneratorHostKeyProviderTest.java
@@ -54,7 +54,7 @@ public class AbstractGeneratorHostKeyProviderTest extends BaseTestSupport {
assertEquals("Mismatched load write count", 0, provider.getWriteCount());
}
- private static class TestProvider extends AbstractGeneratorHostKeyProvider {
+ private static final class TestProvider extends AbstractGeneratorHostKeyProvider {
private final AtomicInteger writes = new AtomicInteger(0);
private TestProvider(File file) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
index 4a84c6b..815b545 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/PEMGeneratorHostKeyProviderTest.java
@@ -60,21 +60,21 @@ public class PEMGeneratorHostKeyProviderTest extends BaseTestSupport {
}
@Test
- public void testEC_NISTP256() throws IOException {
+ public void testECnistp256() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
Assume.assumeTrue("ECC not supported", SecurityUtils.hasEcc());
testPEMGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP256, -1, new ECGenParameterSpec("prime256v1"));
}
@Test
- public void testEC_NISTP384() throws IOException {
+ public void testECnistp384() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
Assume.assumeTrue("ECC not supported", SecurityUtils.hasEcc());
testPEMGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP384, -1, new ECGenParameterSpec("P-384"));
}
@Test
- public void testEC_NISTP521() throws IOException {
+ public void testECnistp521() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
Assume.assumeTrue("ECC not supported", SecurityUtils.hasEcc());
testPEMGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP521, -1, new ECGenParameterSpec("P-521"));
@@ -86,7 +86,8 @@ public class PEMGeneratorHostKeyProviderTest extends BaseTestSupport {
assertTrue("Key file not generated: " + path, Files.exists(path, IoUtils.EMPTY_LINK_OPTIONS));
KeyPair kpRead = invokePEMGeneratorHostKeyProvider(path, algorithm, keyType, keySize, keySpec);
- PublicKey pubWrite = kpWrite.getPublic(), pubRead = kpRead.getPublic();
+ PublicKey pubWrite = kpWrite.getPublic();
+ PublicKey pubRead = kpRead.getPublic();
if (pubWrite instanceof ECPublicKey) {
// The algorithm is reported as ECDSA instead of EC
assertECPublicKeyEquals("Mismatched EC public key", ECPublicKey.class.cast(pubWrite), ECPublicKey.class.cast(pubRead));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
index a66959a..8897c97 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/keyprovider/SimpleGeneratorHostKeyProviderTest.java
@@ -56,19 +56,19 @@ public class SimpleGeneratorHostKeyProviderTest extends BaseTestSupport {
}
@Test
- public void testEC_NISTP256() throws IOException {
+ public void testECnistp256() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
testSimpleGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP256, -1, new ECGenParameterSpec("prime256v1"));
}
@Test
- public void testEC_NISTP384() throws IOException {
+ public void testECnistp384() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
testSimpleGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP384, -1, new ECGenParameterSpec("P-384"));
}
@Test
- public void testEC_NISTP521() throws IOException {
+ public void testECnistp521() throws IOException {
Assume.assumeTrue("BouncyCastle not registered", SecurityUtils.isBouncyCastleRegistered());
testSimpleGeneratorHostKeyProvider("EC", KeyPairProvider.ECDSA_SHA2_NISTP521, -1, new ECGenParameterSpec("P-521"));
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java b/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
index 1746d38..2a627fd 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/shell/InvertedShellWrapperTest.java
@@ -76,7 +76,7 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
final BogusInvertedShell bogusShell = newShell("out", "err");
bogusShell.setAlive(false);
- final int DESTROYED_EXIT_VALUE = 7365;
+ final int destroyedExitValue = 7365;
InvertedShell shell = new InvertedShell() {
private boolean destroyed;
@@ -112,7 +112,7 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
@Override
public int exitValue() {
- return destroyed ? DESTROYED_EXIT_VALUE : bogusShell.exitValue();
+ return destroyed ? destroyedExitValue : bogusShell.exitValue();
}
@Override
@@ -126,22 +126,22 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
try (ByteArrayOutputStream out = new ByteArrayOutputStream();
ByteArrayOutputStream err = new ByteArrayOutputStream();
InputStream stdin = new InputStream() {
- private final byte[] data = getCurrentTestName().getBytes(StandardCharsets.UTF_8);
- private int readPos;
-
- @Override
- public int read() throws IOException {
- if (readPos >= data.length) {
- throw new EOFException("Data exhausted");
- }
-
- return data[readPos++];
- }
-
- @Override
- public int available() throws IOException {
- return data.length;
- }
+ private final byte[] data = getCurrentTestName().getBytes(StandardCharsets.UTF_8);
+ private int readPos;
+
+ @Override
+ public int read() throws IOException {
+ if (readPos >= data.length) {
+ throw new EOFException("Data exhausted");
+ }
+
+ return data[readPos++];
+ }
+
+ @Override
+ public int available() throws IOException {
+ return data.length;
+ }
}) {
BogusExitCallback exitCallback = new BogusExitCallback();
@@ -159,22 +159,22 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
wrapper.destroy();
}
- assertEquals("Mismatched exit value", DESTROYED_EXIT_VALUE, exitCallback.getExitValue());
+ assertEquals("Mismatched exit value", destroyedExitValue, exitCallback.getExitValue());
assertEquals("Mismatched exit message", EOFException.class.getSimpleName(), exitCallback.getExitMessage());
}
}
@Test // see SSHD-576
public void testShellDiesBeforeAllDataExhausted() throws Exception {
- final String IN_CONTENT = "shellInput";
- final String OUT_CONTENT = "shellOutput";
- final String ERR_CONTENT = "shellError";
- try (final InputStream stdin = newDelayedInputStream(Long.SIZE, IN_CONTENT);
+ final String inputContent = "shellInput";
+ final String outputContent = "shellOutput";
+ final String errorContent = "shellError";
+ try (final InputStream stdin = newDelayedInputStream(Long.SIZE, inputContent);
final ByteArrayOutputStream shellIn = new ByteArrayOutputStream(Byte.MAX_VALUE);
- final InputStream shellOut = newDelayedInputStream(Byte.SIZE, OUT_CONTENT);
- ByteArrayOutputStream stdout = new ByteArrayOutputStream(OUT_CONTENT.length() + Byte.SIZE);
- final InputStream shellErr = newDelayedInputStream(Short.SIZE, ERR_CONTENT);
- ByteArrayOutputStream stderr = new ByteArrayOutputStream(ERR_CONTENT.length() + Byte.SIZE)) {
+ final InputStream shellOut = newDelayedInputStream(Byte.SIZE, outputContent);
+ ByteArrayOutputStream stdout = new ByteArrayOutputStream(outputContent.length() + Byte.SIZE);
+ final InputStream shellErr = newDelayedInputStream(Short.SIZE, errorContent);
+ ByteArrayOutputStream stderr = new ByteArrayOutputStream(errorContent.length() + Byte.SIZE)) {
InvertedShell shell = new InvertedShell() {
@Override
@@ -233,9 +233,9 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
wrapper.destroy();
}
- assertEquals("Mismatched STDIN value", IN_CONTENT, shellIn.toString(StandardCharsets.UTF_8.name()));
- assertEquals("Mismatched STDOUT value", OUT_CONTENT, stdout.toString(StandardCharsets.UTF_8.name()));
- assertEquals("Mismatched STDERR value", ERR_CONTENT, stderr.toString(StandardCharsets.UTF_8.name()));
+ assertEquals("Mismatched STDIN value", inputContent, shellIn.toString(StandardCharsets.UTF_8.name()));
+ assertEquals("Mismatched STDOUT value", outputContent, stdout.toString(StandardCharsets.UTF_8.name()));
+ assertEquals("Mismatched STDERR value", errorContent, stderr.toString(StandardCharsets.UTF_8.name()));
}
}
@@ -245,7 +245,7 @@ public class InvertedShellWrapperTest extends BaseTestSupport {
private static InputStream newDelayedInputStream(final int callsCount, byte ... data) {
return new ByteArrayInputStream(data) {
- private int delayCount = 0;
+ private int delayCount;
@Override
public synchronized int read() {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/shell/TtyFilterOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/shell/TtyFilterOutputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/server/shell/TtyFilterOutputStreamTest.java
index b234f72..e15aa44 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/shell/TtyFilterOutputStreamTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/shell/TtyFilterOutputStreamTest.java
@@ -68,18 +68,19 @@ public class TtyFilterOutputStreamTest extends BaseTestSupport {
final AtomicInteger crCount = new AtomicInteger(0);
final AtomicInteger lfCount = new AtomicInteger(0);
try (OutputStream output = new OutputStream() {
- @Override
- public void write(int b) throws IOException {
- if (b == '\r') {
- crCount.incrementAndGet();
- } else if (b == '\n') {
- lfCount.incrementAndGet();
- }
+ @Override
+ public void write(int b) throws IOException {
+ if (b == '\r') {
+ crCount.incrementAndGet();
+ } else if (b == '\n') {
+ lfCount.incrementAndGet();
}
- };
- TtyFilterOutputStream ttyOut = new TtyFilterOutputStream(
- output, null, PtyMode.ECHO.equals(mode) ? Collections.<PtyMode>emptySet(): EnumSet.of(mode));
- Writer writer = new OutputStreamWriter(ttyOut, StandardCharsets.UTF_8)) {
+ }
+ };
+ TtyFilterOutputStream ttyOut = new TtyFilterOutputStream(
+ output, null, PtyMode.ECHO.equals(mode) ? Collections.<PtyMode>emptySet() : EnumSet.of(mode));
+ Writer writer = new OutputStreamWriter(ttyOut, StandardCharsets.UTF_8)) {
+
for (String l : lines) {
writer.append(l).append("\r\n");
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java b/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java
index 1b4127f..35cfece 100644
--- a/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java
+++ b/sshd-core/src/test/java/org/apache/sshd/server/subsystem/sftp/SshFsMounter.java
@@ -62,13 +62,15 @@ import org.apache.sshd.util.test.Utils;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class SshFsMounter {
+public final class SshFsMounter {
public static class MounterCommand extends AbstractLoggingBean implements Command, SessionAware, Runnable {
- private final String command, cmdName;
+ private final String command;
+ private final String cmdName;
private final List<String> args;
private String username;
private InputStream stdin;
- private PrintStream stdout, stderr;
+ private PrintStream stdout;
+ private PrintStream stderr;
private ExitCallback callback;
private ExecutorService executor;
private Future<?> future;
@@ -123,7 +125,7 @@ public class SshFsMounter {
} catch (Exception e) {
log.error("run(" + username + ")[" + command + "] " + e.getClass().getSimpleName() + ": " + e.getMessage(), e);
stderr.append(e.getClass().getSimpleName()).append(": ").println(e.getMessage());
- callback.onExit((-1), e.toString());
+ callback.onExit(-1, e.toString());
}
}
@@ -234,6 +236,12 @@ public class SshFsMounter {
}
}
+ private SshFsMounter() {
+ throw new UnsupportedOperationException("No instance");
+ }
+
+ //////////////////////////////////////////////////////////////////////////
+
public static void main(String[] args) throws Exception {
int port = SshConfigFileReader.DEFAULT_PORT;
boolean error = false;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java b/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
index d1478e8..9c04133 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/BaseTestSupport.java
@@ -59,7 +59,7 @@ import org.junit.rules.TestWatcher;
import org.junit.runner.Description;
/**
- * TODO Add javadoc
+ * Helper used as base class for all test classes
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
@@ -68,6 +68,9 @@ public abstract class BaseTestSupport extends Assert {
// can be used to override the 'localhost' with an address other than 127.0.0.1 in case it is required
public static final String TEST_LOCALHOST = System.getProperty("org.apache.sshd.test.localhost", SshdSocketAddress.LOCALHOST_IP);
public static final boolean OUTPUT_DEBUG_MESSAGES = Boolean.parseBoolean(System.getProperty("org.apache.sshd.test.outputDebugMessages", "false"));
+ public static final String MAIN_SUBFOLDER = "main";
+ public static final String TEST_SUBFOLDER = "test";
+ public static final String RESOURCES_SUBFOLDER = "resources";
// useful test sizes for keys
@SuppressWarnings("boxing")
@@ -97,7 +100,7 @@ public abstract class BaseTestSupport extends Assert {
};
@Rule
- public final TestName TEST_NAME_HOLDER = new TestName();
+ public final TestName testNameHilder = new TestName();
private Path targetFolder;
private Path tempFolder;
@@ -106,7 +109,7 @@ public abstract class BaseTestSupport extends Assert {
}
public final String getCurrentTestName() {
- return TEST_NAME_HOLDER.getMethodName();
+ return testNameHilder.getMethodName();
}
protected SshServer setupTestServer() {
@@ -154,7 +157,7 @@ public abstract class BaseTestSupport extends Assert {
* associated with the project - never {@code null}
*/
protected Path getTempTargetFolder() {
- synchronized(TEMP_SUBFOLDER_NAME) {
+ synchronized (TEMP_SUBFOLDER_NAME) {
if (tempFolder == null) {
tempFolder = ValidateUtils.checkNotNull(detectTargetFolder(), "No target folder detected").resolve(TEMP_SUBFOLDER_NAME);
}
@@ -210,9 +213,6 @@ public abstract class BaseTestSupport extends Assert {
return parent.resolve("src");
}
- public static final String MAIN_SUBFOLDER = "main", TEST_SUBFOLDER = "test";
- public static final String RESOURCES_SUBFOLDER = "resources";
-
protected Path getClassResourcesFolder(String resType /* test or main */) {
return getClassResourcesFolder(resType, getClass());
}
@@ -300,7 +300,8 @@ public abstract class BaseTestSupport extends Assert {
for (int index = 0; expected.hasNext(); index++) {
assertTrue(message + "[next actual index=" + index + "]", actual.hasNext());
- T expValue = expected.next(), actValue = actual.next();
+ T expValue = expected.next();
+ T actValue = actual.next();
assertEquals(message + "[iterator index=" + index + "]", expValue, actValue);
}
@@ -338,11 +339,13 @@ public abstract class BaseTestSupport extends Assert {
}
public static <E> void assertListEquals(String message, List<? extends E> expected, List<? extends E> actual) {
- int expSize = GenericUtils.size(expected), actSize = GenericUtils.size(actual);
+ int expSize = GenericUtils.size(expected);
+ int actSize = GenericUtils.size(actual);
assertEquals(message + "[size]", expSize, actSize);
for (int index = 0; index < expSize; index++) {
- E expValue = expected.get(index), actValue = actual.get(index);
+ E expValue = expected.get(index);
+ E actValue = actual.get(index);
assertEquals(message + "[" + index + "]", expValue, actValue);
}
}
@@ -366,7 +369,7 @@ public abstract class BaseTestSupport extends Assert {
assertKeyEquals(message + "[private]", expected.getPrivate(), actual.getPrivate());
}
- public static final <T extends Key> void assertKeyEquals(String message, T expected, T actual) {
+ public static <T extends Key> void assertKeyEquals(String message, T expected, T actual) {
if (expected == actual) {
return;
}
@@ -387,7 +390,7 @@ public abstract class BaseTestSupport extends Assert {
assertArrayEquals(message + "[encdoded-data]", expected.getEncoded(), actual.getEncoded());
}
- public static final void assertRSAPublicKeyEquals(String message, RSAPublicKey expected, RSAPublicKey actual) {
+ public static void assertRSAPublicKeyEquals(String message, RSAPublicKey expected, RSAPublicKey actual) {
if (expected == actual) {
return;
}
@@ -396,7 +399,7 @@ public abstract class BaseTestSupport extends Assert {
assertEquals(message + "[n]", expected.getModulus(), actual.getModulus());
}
- public static final void assertDSAPublicKeyEquals(String message, DSAPublicKey expected, DSAPublicKey actual) {
+ public static void assertDSAPublicKeyEquals(String message, DSAPublicKey expected, DSAPublicKey actual) {
if (expected == actual) {
return;
}
@@ -405,7 +408,7 @@ public abstract class BaseTestSupport extends Assert {
assertDSAParamsEquals(message + "[params]", expected.getParams(), actual.getParams());
}
- public static final void assertECPublicKeyEquals(String message, ECPublicKey expected, ECPublicKey actual) {
+ public static void assertECPublicKeyEquals(String message, ECPublicKey expected, ECPublicKey actual) {
if (expected == actual) {
return;
}
@@ -414,7 +417,7 @@ public abstract class BaseTestSupport extends Assert {
assertECParameterSpecEquals(message, expected, actual);
}
- public static final void assertRSAPrivateKeyEquals(String message, RSAPrivateKey expected, RSAPrivateKey actual) {
+ public static void assertRSAPrivateKeyEquals(String message, RSAPrivateKey expected, RSAPrivateKey actual) {
if (expected == actual) {
return;
}
@@ -423,7 +426,7 @@ public abstract class BaseTestSupport extends Assert {
assertEquals(message + "[n]", expected.getModulus(), actual.getModulus());
}
- public static final void assertDSAPrivateKeyEquals(String message, DSAPrivateKey expected, DSAPrivateKey actual) {
+ public static void assertDSAPrivateKeyEquals(String message, DSAPrivateKey expected, DSAPrivateKey actual) {
if (expected == actual) {
return;
}
@@ -432,7 +435,7 @@ public abstract class BaseTestSupport extends Assert {
assertDSAParamsEquals(message + "[params]", expected.getParams(), actual.getParams());
}
- public static final void assertDSAParamsEquals(String message, DSAParams expected, DSAParams actual) {
+ public static void assertDSAParamsEquals(String message, DSAParams expected, DSAParams actual) {
if (expected == actual) {
return;
}
@@ -442,7 +445,7 @@ public abstract class BaseTestSupport extends Assert {
assertEquals(message + "[q]", expected.getQ(), actual.getQ());
}
- public static final void assertECPrivateKeyEquals(String message, ECPrivateKey expected, ECPrivateKey actual) {
+ public static void assertECPrivateKeyEquals(String message, ECPrivateKey expected, ECPrivateKey actual) {
if (expected == actual) {
return;
}
@@ -451,14 +454,14 @@ public abstract class BaseTestSupport extends Assert {
assertECParameterSpecEquals(message, expected, actual);
}
- public static final void assertECParameterSpecEquals(String message, ECKey expected, ECKey actual) {
+ public static void assertECParameterSpecEquals(String message, ECKey expected, ECKey actual) {
if (expected == actual) {
return;
}
assertECParameterSpecEquals(message, expected.getParams(), actual.getParams());
}
- public static final void assertECParameterSpecEquals(String message, ECParameterSpec expected, ECParameterSpec actual) {
+ public static void assertECParameterSpecEquals(String message, ECParameterSpec expected, ECParameterSpec actual) {
if (expected == actual) {
return;
}
@@ -469,7 +472,7 @@ public abstract class BaseTestSupport extends Assert {
assertCurveEquals(message + "[curve]", expected.getCurve(), actual.getCurve());
}
- public static final void assertCurveEquals(String message, EllipticCurve expected, EllipticCurve actual) {
+ public static void assertCurveEquals(String message, EllipticCurve expected, EllipticCurve actual) {
if (expected == actual) {
return;
}
@@ -480,7 +483,7 @@ public abstract class BaseTestSupport extends Assert {
assertECFieldEquals(message + "[field]", expected.getField(), actual.getField());
}
- public static final void assertECFieldEquals(String message, ECField expected, ECField actual) {
+ public static void assertECFieldEquals(String message, ECField expected, ECField actual) {
if (expected == actual) {
return;
}
@@ -488,7 +491,7 @@ public abstract class BaseTestSupport extends Assert {
assertEquals(message + "[size]", expected.getFieldSize(), actual.getFieldSize());
}
- public static final void assertECPointEquals(String message, ECPoint expected, ECPoint actual) {
+ public static void assertECPointEquals(String message, ECPoint expected, ECPoint actual) {
if (expected == actual) {
return;
}
@@ -526,7 +529,8 @@ public abstract class BaseTestSupport extends Assert {
long sleepStart = System.nanoTime();
Thread.sleep(sleepTime);
- long sleepEnd = System.nanoTime(), nanoSleep = sleepEnd - sleepStart;
+ long sleepEnd = System.nanoTime();
+ long nanoSleep = sleepEnd - sleepStart;
sleepTime = TimeUnit.NANOSECONDS.toMillis(nanoSleep);
timeout -= sleepTime;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/util/test/BogusInvertedShell.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/BogusInvertedShell.java b/sshd-core/src/test/java/org/apache/sshd/util/test/BogusInvertedShell.java
index c99f4ce..ca7ae2c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/BogusInvertedShell.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/BogusInvertedShell.java
@@ -38,9 +38,9 @@ public class BogusInvertedShell implements InvertedShell, ServerSessionHolder {
// for test assertions
private ServerSession session;
- private boolean started = false;
+ private boolean started;
private boolean alive = true;
- private Map<String, String> env = null;
+ private Map<String, String> env;
public BogusInvertedShell(OutputStream in, InputStream out, InputStream err) {
this.in = in;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/util/test/EchoShell.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/EchoShell.java b/sshd-core/src/test/java/org/apache/sshd/util/test/EchoShell.java
index 89fa159..4d12093 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/EchoShell.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/EchoShell.java
@@ -99,7 +99,7 @@ public class EchoShell implements Command, Runnable {
public void run() {
BufferedReader r = new BufferedReader(new InputStreamReader(in));
try {
- for (; ; ) {
+ for (;;) {
String s = r.readLine();
if (s == null) {
return;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/util/test/JSchLogger.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/JSchLogger.java b/sshd-core/src/test/java/org/apache/sshd/util/test/JSchLogger.java
index c8ec459..09124c1 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/JSchLogger.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/JSchLogger.java
@@ -20,17 +20,13 @@ package org.apache.sshd.util.test;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.Logger;
+
import org.slf4j.LoggerFactory;
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
public class JSchLogger implements Logger {
-
- public static void init() {
- JSch.setLogger(new JSchLogger());
- }
-
private final org.slf4j.Logger log = LoggerFactory.getLogger(JSch.class);
public JSchLogger() {
@@ -72,4 +68,8 @@ public class JSchLogger implements Logger {
log.error("[LEVEL=" + level + "]: " + message);
}
}
+
+ public static void init() {
+ JSch.setLogger(new JSchLogger());
+ }
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java b/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java
index 1dcfd12..be121dd 100644
--- a/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java
+++ b/sshd-core/src/test/java/org/apache/sshd/util/test/Utils.java
@@ -66,13 +66,58 @@ import org.apache.sshd.server.SshServer;
import org.apache.sshd.server.auth.pubkey.AcceptAllPublickeyAuthenticator;
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider;
-public class Utils {
- // uses a cached instance to avoid re-creating the keys as it is a time-consuming effort
- private static final AtomicReference<KeyPairProvider> keyPairProviderHolder = new AtomicReference<KeyPairProvider>();
+public final class Utils {
+ /**
+ * URL/URI scheme that refers to a file
+ */
+ public static final String FILE_URL_SCHEME = "file";
+ /**
+ * Prefix used in URL(s) that reference a file resource
+ */
+ public static final String FILE_URL_PREFIX = FILE_URL_SCHEME + ":";
+
+ /**
+ * Separator used in URL(s) that reference a resource inside a JAR
+ * to denote the sub-path inside the JAR
+ */
+ public static final char RESOURCE_SUBPATH_SEPARATOR = '!';
+
+ /**
+ * Suffix of JAR files
+ */
+ public static final String JAR_FILE_SUFFIX = ".jar";
+
+ /**
+ * URL/URI scheme that refers to a JAR
+ */
+ public static final String JAR_URL_SCHEME = "jar";
+
+ /**
+ * Prefix used in URL(s) that reference a resource inside a JAR
+ */
+ public static final String JAR_URL_PREFIX = JAR_URL_SCHEME + ":";
+
+ /**
+ * Suffix of compile Java class files
+ */
+ public static final String CLASS_FILE_SUFFIX = ".class";
+
+ public static final List<String> TARGET_FOLDER_NAMES = // NOTE: order is important
+ Collections.unmodifiableList(
+ Arrays.asList("target" /* Maven */, "build" /* Gradle */));
+
public static final String DEFAULT_TEST_HOST_KEY_PROVIDER_ALGORITHM = "RSA";
+ // uses a cached instance to avoid re-creating the keys as it is a time-consuming effort
+ private static final AtomicReference<KeyPairProvider> KEYPAIR_PROVIDER_HOLDER = new AtomicReference<KeyPairProvider>();
+ // uses a cached instance to avoid re-creating the keys as it is a time-consuming effort
+ private static final Map<String, AbstractFileKeyPairProvider> PROVIDERS_MAP = new ConcurrentHashMap<String, AbstractFileKeyPairProvider>();
+
+ private Utils() {
+ throw new UnsupportedOperationException("No instance");
+ }
public static KeyPairProvider createTestHostKeyProvider(Class<?> anchor) {
- KeyPairProvider provider = keyPairProviderHolder.get();
+ KeyPairProvider provider = KEYPAIR_PROVIDER_HOLDER.get();
if (provider != null) {
return provider;
}
@@ -81,7 +126,7 @@ public class Utils {
File file = new File(targetFolder, "hostkey." + DEFAULT_TEST_HOST_KEY_PROVIDER_ALGORITHM.toLowerCase());
provider = createTestHostKeyProvider(file);
- KeyPairProvider prev = keyPairProviderHolder.getAndSet(provider);
+ KeyPairProvider prev = KEYPAIR_PROVIDER_HOLDER.getAndSet(provider);
if (prev != null) { // check if somebody else beat us to it
return prev;
} else {
@@ -127,13 +172,10 @@ public class Utils {
return gen.generateKeyPair();
}
- // uses a cached instance to avoid re-creating the keys as it is a time-consuming effort
- private static final Map<String, AbstractFileKeyPairProvider> providersMap = new ConcurrentHashMap<String, AbstractFileKeyPairProvider>();
-
public static AbstractFileKeyPairProvider createTestKeyPairProvider(String resource) {
File file = getFile(resource);
String filePath = file.getAbsolutePath();
- AbstractFileKeyPairProvider provider = providersMap.get(filePath);
+ AbstractFileKeyPairProvider provider = PROVIDERS_MAP.get(filePath);
if (provider != null) {
return provider;
}
@@ -142,7 +184,7 @@ public class Utils {
provider.setFiles(Collections.singletonList(file));
provider = validateKeyPairProvider(provider);
- AbstractFileKeyPairProvider prev = providersMap.put(filePath, provider);
+ AbstractFileKeyPairProvider prev = PROVIDERS_MAP.put(filePath, provider);
if (prev != null) { // check if somebody else beat us to it
return prev;
} else {
@@ -303,7 +345,7 @@ public class Utils {
* @return The "target" <U>folder</U> - {@code null} if not found
* @see #detectTargetFolder(File)
*/
- public static final File detectTargetFolder(Class<?> anchor) {
+ public static File detectTargetFolder(Class<?> anchor) {
return detectTargetFolder(getClassContainerLocationFile(anchor));
}
@@ -317,7 +359,7 @@ public class Utils {
* @see #getClassContainerLocationURI(Class)
* @see #toFileSource(URI)
*/
- public static final File getClassContainerLocationFile(Class<?> clazz)
+ public static File getClassContainerLocationFile(Class<?> clazz)
throws IllegalArgumentException {
try {
URI uri = getClassContainerLocationURI(clazz);
@@ -335,7 +377,7 @@ public class Utils {
* @throws URISyntaxException if location is not a valid URI
* @see #getClassContainerLocationURL(Class)
*/
- public static final URI getClassContainerLocationURI(Class<?> clazz) throws URISyntaxException {
+ public static URI getClassContainerLocationURI(Class<?> clazz) throws URISyntaxException {
URL url = getClassContainerLocationURL(clazz);
return (url == null) ? null : url.toURI();
}
@@ -346,12 +388,13 @@ public class Utils {
* - e.g., the root folder, the containing JAR, etc.. Returns
* {@code null} if location could not be resolved
*/
- public static final URL getClassContainerLocationURL(Class<?> clazz) {
+ public static URL getClassContainerLocationURL(Class<?> clazz) {
ProtectionDomain pd = clazz.getProtectionDomain();
CodeSource cs = (pd == null) ? null : pd.getCodeSource();
URL url = (cs == null) ? null : cs.getLocation();
if (url == null) {
- if ((url = getClassBytesURL(clazz)) == null) {
+ url = getClassBytesURL(clazz);
+ if (url == null) {
return null;
}
@@ -398,15 +441,6 @@ public class Utils {
}
/**
- * URL/URI scheme that refers to a file
- */
- public static final String FILE_URL_SCHEME = "file";
- /**
- * Prefix used in URL(s) that reference a file resource
- */
- public static final String FILE_URL_PREFIX = FILE_URL_SCHEME + ":";
-
- /**
* Converts a {@link URI} that may refer to an internal resource to
* a {@link File} representing is "source" container (e.g.,
* if it is a resource in a JAR, then the result is the JAR's path)
@@ -442,7 +476,7 @@ public class Utils {
* any sub-resource are stripped
* @see #getURLSource(String)
*/
- public static final String getURLSource(URI uri) {
+ public static String getURLSource(URI uri) {
return getURLSource((uri == null) ? null : uri.toString());
}
@@ -452,23 +486,17 @@ public class Utils {
* any sub-resource are stripped
* @see #getURLSource(String)
*/
- public static final String getURLSource(URL url) {
+ public static String getURLSource(URL url) {
return getURLSource((url == null) ? null : url.toExternalForm());
}
/**
- * Separator used in URL(s) that reference a resource inside a JAR
- * to denote the sub-path inside the JAR
- */
- public static final char RESOURCE_SUBPATH_SEPARATOR = '!';
-
- /**
* @param externalForm The {@link URL#toExternalForm()} string - ignored if
* {@code null}/empty
* @return The URL(s) source path where {@link #JAR_URL_PREFIX} and
* any sub-resource are stripped
*/
- public static final String getURLSource(String externalForm) {
+ public static String getURLSource(String externalForm) {
String url = externalForm;
if (GenericUtils.isEmpty(url)) {
return url;
@@ -493,7 +521,7 @@ public class Utils {
* is not '/' itself
* @see #adjustURLPathValue(String)
*/
- public static final String adjustURLPathValue(URL url) {
+ public static String adjustURLPathValue(URL url) {
return adjustURLPathValue((url == null) ? null : url.getPath());
}
@@ -502,7 +530,7 @@ public class Utils {
* @return The path after stripping any trailing '/' provided the path
* is not '/' itself
*/
- public static final String adjustURLPathValue(final String path) {
+ public static String adjustURLPathValue(final String path) {
final int pathLen = (path == null) ? 0 : path.length();
if ((pathLen <= 1) || (path.charAt(pathLen - 1) != '/')) {
return path;
@@ -511,20 +539,7 @@ public class Utils {
return path.substring(0, pathLen - 1);
}
- /**
- * Suffix of JAR files
- */
- public static final String JAR_FILE_SUFFIX = ".jar";
- /**
- * URL/URI scheme that refers to a JAR
- */
- public static final String JAR_URL_SCHEME = "jar";
- /**
- * Prefix used in URL(s) that reference a resource inside a JAR
- */
- public static final String JAR_URL_PREFIX = JAR_URL_SCHEME + ":";
-
- public static final String stripJarURLPrefix(String externalForm) {
+ public static String stripJarURLPrefix(String externalForm) {
String url = externalForm;
if (GenericUtils.isEmpty(url)) {
return url;
@@ -538,21 +553,17 @@ public class Utils {
}
/**
- * Suffix of compile Java class files
- */
- public static final String CLASS_FILE_SUFFIX = ".class";
-
- /**
* @param clazz The request {@link Class}
* @return A {@link URL} to the location of the <code>.class</code> file
* - {@code null} if location could not be resolved
*/
- public static final URL getClassBytesURL(Class<?> clazz) {
+ public static URL getClassBytesURL(Class<?> clazz) {
String className = clazz.getName();
int sepPos = className.indexOf('$');
// if this is an internal class, then need to use its parent as well
if (sepPos > 0) {
- if ((sepPos = className.lastIndexOf('.')) > 0) {
+ sepPos = className.lastIndexOf('.');
+ if (sepPos > 0) {
className = className.substring(sepPos + 1);
}
} else {
@@ -562,7 +573,7 @@ public class Utils {
return clazz.getResource(className + CLASS_FILE_SUFFIX);
}
- public static final String getClassBytesResourceName(Class<?> clazz) {
+ public static String getClassBytesResourceName(Class<?> clazz) {
return getClassBytesResourceName((clazz == null) ? null : clazz.getName());
}
@@ -570,29 +581,24 @@ public class Utils {
* @param name The fully qualified class name - ignored if {@code null}/empty
* @return The relative path of the class file byte-code resource
*/
- public static final String getClassBytesResourceName(String name) {
+ public static String getClassBytesResourceName(String name) {
if (GenericUtils.isEmpty(name)) {
return name;
} else {
return new StringBuilder(name.length() + CLASS_FILE_SUFFIX.length())
.append(name.replace('.', '/'))
.append(CLASS_FILE_SUFFIX)
- .toString()
- ;
+ .toString();
}
}
- public static final List<String> TARGET_FOLDER_NAMES = // NOTE: order is important
- Collections.unmodifiableList(
- Arrays.asList("target" /* Maven */, "build" /* Gradle */));
-
/**
* @param anchorFile An anchor {@link File} we want to use
* as the starting point for the "target" or "build" folder
* lookup up the hierarchy
* @return The "target" <U>folder</U> - {@code null} if not found
*/
- public static final File detectTargetFolder(File anchorFile) {
+ public static File detectTargetFolder(File anchorFile) {
for (File file = anchorFile; file != null; file = file.getParentFile()) {
if (!file.isDirectory()) {
continue;
@@ -607,12 +613,12 @@ public class Utils {
return null;
}
- public static final String resolveRelativeRemotePath(Path root, Path file) {
+ public static String resolveRelativeRemotePath(Path root, Path file) {
Path relPath = root.relativize(file);
return relPath.toString().replace(File.separatorChar, '/');
}
- public static final SshClient setupTestClient(Class<?> anchor) {
+ public static SshClient setupTestClient(Class<?> anchor) {
SshClient client = SshClient.setUpDefaultClient();
client.setServerKeyVerifier(AcceptAllServerKeyVerifier.INSTANCE);
client.setHostConfigEntryResolver(HostConfigEntryResolver.EMPTY);
@@ -620,7 +626,7 @@ public class Utils {
return client;
}
- public static final SshServer setupTestServer(Class<?> anchor) {
+ public static SshServer setupTestServer(Class<?> anchor) {
SshServer sshd = SshServer.setUpDefaultServer();
sshd.setKeyPairProvider(createTestHostKeyProvider(anchor));
sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java b/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java
index 07ee4b2..37b79fe 100644
--- a/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java
+++ b/sshd-git/src/test/java/org/apache/sshd/git/pack/GitPackCommandTest.java
@@ -22,6 +22,8 @@ import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
+import com.jcraft.jsch.JSch;
+
import org.apache.sshd.common.NamedFactory;
import org.apache.sshd.git.transport.GitSshdSessionFactory;
import org.apache.sshd.server.Command;
@@ -39,8 +41,6 @@ import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
-import com.jcraft.jsch.JSch;
-
/**
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@@ -59,7 +59,7 @@ public class GitPackCommandTest extends BaseTestSupport {
Path targetParent = detectTargetFolder().getParent();
Path gitRootDir = getTempTargetRelativeFile(getClass().getSimpleName());
- try(SshServer sshd = setupTestServer()) {
+ try (SshServer sshd = setupTestServer()) {
Path serverRootDir = gitRootDir.resolve("server");
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
sshd.setCommandFactory(new GitPackCommandFactory(Utils.resolveRelativeRemotePath(targetParent, serverRootDir)));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java
----------------------------------------------------------------------
diff --git a/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java b/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java
index a6be166..77c14db 100644
--- a/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java
+++ b/sshd-git/src/test/java/org/apache/sshd/git/pgm/GitPgmCommandTest.java
@@ -59,7 +59,7 @@ public class GitPgmCommandTest extends BaseTestSupport {
// TODO: because it's quite limited for now
//
- try(SshServer sshd = setupTestServer()) {
+ try (SshServer sshd = setupTestServer()) {
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory()));
sshd.setCommandFactory(new GitPgmCommandFactory(Utils.resolveRelativeRemotePath(targetParent, serverDir)));
sshd.start();
@@ -68,10 +68,10 @@ public class GitPgmCommandTest extends BaseTestSupport {
try {
Utils.deleteRecursive(serverDir);
- try(SshClient client = setupTestClient()) {
+ try (SshClient client = setupTestClient()) {
client.start();
- try(ClientSession session = client.connect(getCurrentTestName(), SshdSocketAddress.LOCALHOST_IP, port).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(getCurrentTestName(), SshdSocketAddress.LOCALHOST_IP, port).verify(7L, TimeUnit.SECONDS).getSession()) {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
@@ -95,7 +95,7 @@ public class GitPgmCommandTest extends BaseTestSupport {
}
private void execute(ClientSession session, String command) throws Exception {
- try(ChannelExec channel = session.createExecChannel(command)) {
+ try (ChannelExec channel = session.createExecChannel(command)) {
channel.setOut(System.out);
channel.setErr(System.err);
channel.open().verify(11L, TimeUnit.SECONDS);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
index f60ca32..0d48b61 100644
--- a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
+++ b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/BaseAuthenticatorTest.java
@@ -61,7 +61,7 @@ import org.slf4j.LoggerFactory;
*/
public abstract class BaseAuthenticatorTest extends BaseTestSupport {
public static final int PORT = Integer.parseInt(System.getProperty("org.apache.sshd.test.ldap.port", "11389"));
- public static String BASE_DN_TEST = "ou=People,dc=sshd,dc=apache,dc=org";
+ public static final String BASE_DN_TEST = "ou=People,dc=sshd,dc=apache,dc=org";
protected BaseAuthenticatorTest() {
super();
@@ -94,6 +94,7 @@ public abstract class BaseAuthenticatorTest extends BaseTestSupport {
// see http://javlog.cacek.cz/2014/09/speed-up-apacheds-ldap-server.html
// see https://cwiki.apache.org/confluence/display/DIRxSRVx11/4.1.+Embedding+ApacheDS+into+an+application
// see http://stackoverflow.com/questions/1560230/running-apache-ds-embedded-in-my-application
+ @SuppressWarnings("checkstyle:avoidnestedblocks")
public static Pair<LdapServer, DirectoryService> startApacheDs(Class<?> anchor) throws Exception {
Logger log = LoggerFactory.getLogger(anchor);
File targetFolder = ValidateUtils.checkNotNull(Utils.detectTargetFolder(anchor), "Failed to detect target folder");
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java
----------------------------------------------------------------------
diff --git a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java
index b7c2f2b..a942b79 100644
--- a/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java
+++ b/sshd-ldap/src/test/java/org/apache/sshd/server/auth/password/LdapPasswordAuthenticatorTest.java
@@ -40,7 +40,7 @@ import org.mockito.Mockito;
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class LdapPasswordAuthenticatorTest extends BaseAuthenticatorTest {
- private static final AtomicReference<Pair<LdapServer, DirectoryService>> ldapContextHolder = new AtomicReference<>();
+ private static final AtomicReference<Pair<LdapServer, DirectoryService>> LDAP_CONTEX_HOLDER = new AtomicReference<>();
private static Map<String, String> usersMap;
public LdapPasswordAuthenticatorTest() {
@@ -49,19 +49,19 @@ public class LdapPasswordAuthenticatorTest extends BaseAuthenticatorTest {
@BeforeClass
public static void startApacheDs() throws Exception {
- ldapContextHolder.set(startApacheDs(LdapPasswordAuthenticatorTest.class));
- usersMap = populateUsers(ldapContextHolder.get().getSecond(), LdapPasswordAuthenticatorTest.class, LdapPasswordAuthenticator.DEFAULT_PASSWORD_ATTR_NAME);
+ LDAP_CONTEX_HOLDER.set(startApacheDs(LdapPasswordAuthenticatorTest.class));
+ usersMap = populateUsers(LDAP_CONTEX_HOLDER.get().getSecond(), LdapPasswordAuthenticatorTest.class, LdapPasswordAuthenticator.DEFAULT_PASSWORD_ATTR_NAME);
assertFalse("No users retrieved", GenericUtils.isEmpty(usersMap));
}
@AfterClass
public static void stopApacheDs() throws Exception {
- stopApacheDs(ldapContextHolder.getAndSet(null));
+ stopApacheDs(LDAP_CONTEX_HOLDER.getAndSet(null));
}
@Test // the user's password is compared with the LDAP stored one
public void testPasswordComparison() throws Exception {
- Pair<LdapServer, DirectoryService> ldapContext = ldapContextHolder.get();
+ Pair<LdapServer, DirectoryService> ldapContext = LDAP_CONTEX_HOLDER.get();
LdapPasswordAuthenticator auth = new LdapPasswordAuthenticator();
auth.setHost(getHost(ldapContext));
auth.setPort(getPort(ldapContext));