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:08:00 UTC
[4/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/client/config/hosts/ConfigFileHostEntryResolverTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
index a75e18f..1a7e319 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/ConfigFileHostEntryResolverTest.java
@@ -65,19 +65,39 @@ public class ConfigFileHostEntryResolverTest extends BaseTestSupport {
resolver, expected, expected);
testConfigFileReload("Wildcard", path, reloadCount,
Arrays.asList(
- new HostConfigEntry(HostPatternsHolder.ALL_HOSTS_PATTERN, getClass().getSimpleName(), 1234, getClass().getSimpleName()),
- new HostConfigEntry(expected.getHost() + String.valueOf(HostPatternsHolder.WILDCARD_PATTERN), expected.getHost(), expected.getPort(), expected.getUsername())),
+ new HostConfigEntry(
+ HostPatternsHolder.ALL_HOSTS_PATTERN,
+ getClass().getSimpleName(),
+ 1234,
+ getClass().getSimpleName()),
+ new HostConfigEntry(
+ expected.getHost() + String.valueOf(HostPatternsHolder.WILDCARD_PATTERN),
+ expected.getHost(),
+ expected.getPort(),
+ expected.getUsername())),
resolver, expected, expected);
testConfigFileReload("Specific", path, reloadCount,
Arrays.asList(
- new HostConfigEntry(HostPatternsHolder.ALL_HOSTS_PATTERN, getClass().getSimpleName(), 1234, getClass().getSimpleName()),
- new HostConfigEntry(getClass().getSimpleName() + String.valueOf(HostPatternsHolder.WILDCARD_PATTERN), getClass().getSimpleName(), 1234, getClass().getSimpleName()),
+ new HostConfigEntry(
+ HostPatternsHolder.ALL_HOSTS_PATTERN,
+ getClass().getSimpleName(),
+ 1234,
+ getClass().getSimpleName()),
+ new HostConfigEntry(
+ getClass().getSimpleName() + String.valueOf(HostPatternsHolder.WILDCARD_PATTERN),
+ getClass().getSimpleName(),
+ 1234,
+ getClass().getSimpleName()),
expected),
resolver, expected, expected);
}
private static void testConfigFileReload(
- String phase, Path path, AtomicInteger reloadCount, Collection<? extends HostConfigEntry> entries, HostConfigEntryResolver resolver, HostConfigEntry query, HostConfigEntry expected)
+ String phase, Path path, AtomicInteger reloadCount,
+ Collection<? extends HostConfigEntry> entries,
+ HostConfigEntryResolver resolver,
+ HostConfigEntry query,
+ HostConfigEntry expected)
throws IOException {
if (entries == null) {
if (Files.exists(path)) {
@@ -90,7 +110,8 @@ public class ConfigFileHostEntryResolverTest extends BaseTestSupport {
reloadCount.set(0);
for (int index = 1; index < Byte.SIZE; index++) {
- HostConfigEntry actual = resolver.resolveEffectiveHost(query.getHostName(), query.getPort(), query.getUsername());
+ HostConfigEntry actual =
+ resolver.resolveEffectiveHost(query.getHostName(), query.getPort(), query.getUsername());
if (entries == null) {
assertEquals(phase + "[" + index + "]: mismatched reload count", 0, reloadCount.get());
@@ -103,9 +124,12 @@ public class ConfigFileHostEntryResolverTest extends BaseTestSupport {
} else {
assertNotNull(phase + "[" + index + "]: No result for " + query, actual);
assertNotSame(phase + "[" + index + "]: No cloned result for " + query, expected, actual);
- assertEquals(phase + "[" + index + "]: Mismatched host for " + query, expected.getHostName(), actual.getHostName());
- assertEquals(phase + "[" + index + "]: Mismatched port for " + query, expected.getPort(), actual.getPort());
- assertEquals(phase + "[" + index + "]: Mismatched user for " + query, expected.getUsername(), actual.getUsername());
+ assertEquals(phase + "[" + index + "]: Mismatched host for " + query,
+ expected.getHostName(), actual.getHostName());
+ assertEquals(phase + "[" + index + "]: Mismatched port for " + query,
+ expected.getPort(), actual.getPort());
+ assertEquals(phase + "[" + index + "]: Mismatched user for " + query,
+ expected.getUsername(), actual.getUsername());
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
index 4296b72..ccb874f 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryResolverTest.java
@@ -101,7 +101,10 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
});
client.start();
- try(ClientSession session = client.connect(getClass().getSimpleName(), getClass().getPackage().getName(), getMovedPortNumber(port)).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(
+ getClass().getSimpleName(),
+ getClass().getPackage().getName(),
+ getMovedPortNumber(port)).verify(7L, TimeUnit.SECONDS).getSession()) {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
assertEffectiveRemoteAddress(session, entry);
@@ -118,10 +121,15 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
positiveEntry.getHostName(),
getMovedPortNumber(positiveEntry.getPort()),
getClass().getPackage().getName());
- client.setHostConfigEntryResolver(HostConfigEntry.toHostConfigEntryResolver(Arrays.asList(negativeEntry, positiveEntry)));
+ client.setHostConfigEntryResolver(
+ HostConfigEntry.toHostConfigEntryResolver(
+ Arrays.asList(negativeEntry, positiveEntry)));
client.start();
- try(ClientSession session = client.connect(negativeEntry.getUsername(), negativeEntry.getHostName(), negativeEntry.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(
+ negativeEntry.getUsername(),
+ negativeEntry.getHostName(),
+ negativeEntry.getPort()).verify(7L, TimeUnit.SECONDS).getSession()) {
session.addPasswordIdentity(getCurrentTestName());
session.auth().verify(5L, TimeUnit.SECONDS);
assertEffectiveRemoteAddress(session, positiveEntry);
@@ -133,12 +141,12 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
@Test
public void testPreloadedIdentities() throws Exception {
final KeyPair identity = Utils.getFirstKeyPair(sshd);
- final String USER = getCurrentTestName();
+ final String user = getCurrentTestName();
// make sure authentication is achieved only via the identity public key
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
@Override
public boolean authenticate(String username, PublicKey key, ServerSession session) {
- if (USER.equals(username)) {
+ if (user.equals(username)) {
return KeyUtils.compareKeys(identity.getPublic(), key);
}
@@ -147,15 +155,16 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
});
sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);
- final String IDENTITY = getCurrentTestName();
+ final String clientIdentity = getCurrentTestName();
client.setClientIdentityLoader(new ClientIdentityLoader() {
@Override
public boolean isValidLocation(String location) throws IOException {
- return IDENTITY.equals(location);
+ return clientIdentity.equals(location);
}
@Override
- public KeyPair loadClientIdentity(String location, FilePasswordProvider provider) throws IOException, GeneralSecurityException {
+ public KeyPair loadClientIdentity(String location, FilePasswordProvider provider)
+ throws IOException, GeneralSecurityException {
if (isValidLocation(location)) {
return identity;
}
@@ -165,9 +174,9 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
});
PropertyResolverUtils.updateProperty(client, ClientFactoryManager.IGNORE_INVALID_IDENTITIES, false);
- final String HOST = getClass().getSimpleName();
- final HostConfigEntry entry = new HostConfigEntry(HOST, TEST_LOCALHOST, port, USER);
- entry.addIdentity(IDENTITY);
+ final String host = getClass().getSimpleName();
+ final HostConfigEntry entry = new HostConfigEntry(host, TEST_LOCALHOST, port, user);
+ entry.addIdentity(clientIdentity);
client.setHostConfigEntryResolver(new HostConfigEntryResolver() {
@Override
public HostConfigEntry resolveEffectiveHost(String host, int portValue, String username) throws IOException {
@@ -176,7 +185,8 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
});
client.start();
- try(ClientSession session = client.connect(USER, HOST, getMovedPortNumber(port)).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(
+ user, host, getMovedPortNumber(port)).verify(7L, TimeUnit.SECONDS).getSession()) {
session.auth().verify(5L, TimeUnit.SECONDS);
assertEffectiveRemoteAddress(session, entry);
} finally {
@@ -187,14 +197,16 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
@Test
public void testUseIdentitiesOnly() throws Exception {
Path clientIdFile = assertHierarchyTargetFolderExists(getTempTargetRelativeFile(getClass().getSimpleName()));
- KeyPairProvider clientIdProvider = Utils.createTestHostKeyProvider(clientIdFile.resolve(getCurrentTestName() + ".pem"));
+ KeyPairProvider clientIdProvider =
+ Utils.createTestHostKeyProvider(clientIdFile.resolve(getCurrentTestName() + ".pem"));
final KeyPair specificIdentity = Utils.getFirstKeyPair(sshd);
final KeyPair defaultIdentity = Utils.getFirstKeyPair(clientIdProvider);
- ValidateUtils.checkTrue(!KeyUtils.compareKeyPairs(specificIdentity, defaultIdentity), "client identity not different then entry one");
+ ValidateUtils.checkTrue(!KeyUtils.compareKeyPairs(specificIdentity, defaultIdentity),
+ "client identity not different then entry one");
client.setKeyPairProvider(clientIdProvider);
- final String USER = getCurrentTestName();
+ final String user = getCurrentTestName();
final AtomicBoolean defaultClientIdentityAttempted = new AtomicBoolean(false);
// make sure authentication is achieved only via the identity public key
sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() {
@@ -204,7 +216,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
defaultClientIdentityAttempted.set(true);
}
- if (USER.equals(username)) {
+ if (user.equals(username)) {
return KeyUtils.compareKeys(specificIdentity.getPublic(), key);
}
@@ -213,19 +225,20 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
});
sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);
- final String IDENTITY = getCurrentTestName();
- HostConfigEntry entry = new HostConfigEntry(TEST_LOCALHOST, TEST_LOCALHOST, port, USER);
- entry.addIdentity(IDENTITY);
+ final String clientIdentity = getCurrentTestName();
+ HostConfigEntry entry = new HostConfigEntry(TEST_LOCALHOST, TEST_LOCALHOST, port, user);
+ entry.addIdentity(clientIdentity);
entry.setIdentitiesOnly(true);
client.setClientIdentityLoader(new ClientIdentityLoader() {
@Override
public boolean isValidLocation(String location) throws IOException {
- return IDENTITY.equals(location);
+ return clientIdentity.equals(location);
}
@Override
- public KeyPair loadClientIdentity(String location, FilePasswordProvider provider) throws IOException, GeneralSecurityException {
+ public KeyPair loadClientIdentity(String location, FilePasswordProvider provider)
+ throws IOException, GeneralSecurityException {
if (isValidLocation(location)) {
return specificIdentity;
}
@@ -245,7 +258,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport {
client.setKeyPairProvider(provider);
client.start();
- try(ClientSession session = client.connect(entry).verify(7L, TimeUnit.SECONDS).getSession()) {
+ try (ClientSession session = client.connect(entry).verify(7L, TimeUnit.SECONDS).getSession()) {
assertSame("Unexpected session key pairs provider", provider, session.getKeyPairProvider());
session.auth().verify(5L, TimeUnit.SECONDS);
assertFalse("Unexpected default client identity attempted", defaultClientIdentityAttempted.get());
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
index 635c6cc..814deb6 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/HostConfigEntryTest.java
@@ -93,7 +93,7 @@ public class HostConfigEntryTest extends BaseTestSupport {
getCurrentTestName(),
getClass().getSimpleName() + "-" + getCurrentTestName(),
getClass().getSimpleName() + "." + getCurrentTestName(),
- }) {
+ }) {
sb.setLength(0); // start from scratch
sb.append(host).append(domain);
@@ -120,7 +120,7 @@ public class HostConfigEntryTest extends BaseTestSupport {
public void testHostSingleCharPatternMatching() {
String value = getCurrentTestName();
StringBuilder sb = new StringBuilder(value);
- for (boolean restoreOriginal : new boolean[] { true, false }) {
+ for (boolean restoreOriginal : new boolean[] {true, false}) {
for (int index = 0; index < value.length(); index++) {
sb.setCharAt(index, HostPatternsHolder.SINGLE_CHAR_PATTERN);
testCaseInsensitivePatternMatching(value, HostPatternsHolder.toPattern(sb.toString()).getFirst(), true);
@@ -170,14 +170,15 @@ public class HostConfigEntryTest extends BaseTestSupport {
assertTrue("Valid character not recognized: " + String.valueOf(ch), HostPatternsHolder.isValidPatternChar(ch));
}
- for (char ch : new char[] { '-', '_', '.', HostPatternsHolder.SINGLE_CHAR_PATTERN, HostPatternsHolder.WILDCARD_PATTERN }) {
+ for (char ch : new char[] {'-', '_', '.', HostPatternsHolder.SINGLE_CHAR_PATTERN, HostPatternsHolder.WILDCARD_PATTERN}) {
assertTrue("Valid character not recognized: " + String.valueOf(ch), HostPatternsHolder.isValidPatternChar(ch));
}
for (char ch : new char[] {
- '(', ')', '{', '}', '[', ']', '@',
- '#', '$', '^', '&', '%', '~', '<', '>',
- ',', '/', '\\', '\'', '"', ':', ';' }) {
+ '(', ')', '{', '}', '[', ']', '@',
+ '#', '$', '^', '&', '%', '~', '<', '>',
+ ',', '/', '\\', '\'', '"', ':', ';'
+ }) {
assertFalse("Unexpected valid character: " + String.valueOf(ch), HostPatternsHolder.isValidPatternChar(ch));
}
@@ -188,23 +189,27 @@ public class HostConfigEntryTest extends BaseTestSupport {
@Test
public void testResolvePort() {
- final int ORIGINAL_PORT = Short.MAX_VALUE;
- final int ENTRY_PORT = 7365;
- assertEquals("Mismatched entry port preference", ENTRY_PORT, HostConfigEntry.resolvePort(ORIGINAL_PORT, ENTRY_PORT));
-
- for (int entryPort : new int[] { -1, 0 }) {
- assertEquals("Non-preferred original port for entry port=" + entryPort, ORIGINAL_PORT, HostConfigEntry.resolvePort(ORIGINAL_PORT, entryPort));
+ final int originalPort = Short.MAX_VALUE;
+ final int preferredPort = 7365;
+ assertEquals("Mismatched entry port preference",
+ preferredPort, HostConfigEntry.resolvePort(originalPort, preferredPort));
+
+ for (int entryPort : new int[] {-1, 0}) {
+ assertEquals("Non-preferred original port for entry port=" + entryPort,
+ originalPort, HostConfigEntry.resolvePort(originalPort, entryPort));
}
}
@Test
public void testResolveUsername() {
- final String ORIGINAL_USER = getCurrentTestName();
- final String ENTRY_USER = getClass().getSimpleName();
- assertSame("Mismatched entry user preference", ENTRY_USER, HostConfigEntry.resolveUsername(ORIGINAL_USER, ENTRY_USER));
-
- for (String entryUser : new String[] { null, "" }) {
- assertSame("Non-preferred original user for entry user='" + entryUser + "'", ORIGINAL_USER, HostConfigEntry.resolveUsername(ORIGINAL_USER, entryUser));
+ final String originalUser = getCurrentTestName();
+ final String preferredUser = getClass().getSimpleName();
+ assertSame("Mismatched entry user preference",
+ preferredUser, HostConfigEntry.resolveUsername(originalUser, preferredUser));
+
+ for (String entryUser : new String[] {null, ""}) {
+ assertSame("Non-preferred original user for entry user='" + entryUser + "'",
+ originalUser, HostConfigEntry.resolveUsername(originalUser, entryUser));
}
}
@@ -241,20 +246,20 @@ public class HostConfigEntryTest extends BaseTestSupport {
@Test
public void testResolveIdentityFilePath() throws Exception {
- final String HOST = getClass().getSimpleName();
- final int PORT = 7365;
- final String USER = getCurrentTestName();
+ final String hostValue = getClass().getSimpleName();
+ final int portValue = 7365;
+ final String userValue = getCurrentTestName();
Exception err = null;
for (String pattern : new String[] {
- "~/.ssh/%h.key",
- "%d/.ssh/%h.key",
- "/home/%u/.ssh/id_rsa_%p",
- "/home/%u/.ssh/id_%r_rsa",
- "/home/%u/.ssh/%h/%l.key"
+ "~/.ssh/%h.key",
+ "%d/.ssh/%h.key",
+ "/home/%u/.ssh/id_rsa_%p",
+ "/home/%u/.ssh/id_%r_rsa",
+ "/home/%u/.ssh/%h/%l.key"
}) {
try {
- String result = HostConfigEntry.resolveIdentityFilePath(pattern, HOST, PORT, USER);
+ String result = HostConfigEntry.resolveIdentityFilePath(pattern, hostValue, portValue, userValue);
System.out.append('\t').append(pattern).append(" => ").println(result);
} catch (Exception e) {
System.err.append("Failed (").append(e.getClass().getSimpleName())
@@ -271,11 +276,11 @@ public class HostConfigEntryTest extends BaseTestSupport {
@Test
public void testFindBestMatch() {
- final String HOST = getCurrentTestName();
- HostConfigEntry expected = new HostConfigEntry(HOST, HOST, 7365, HOST);
+ final String hostValue = getCurrentTestName();
+ HostConfigEntry expected = new HostConfigEntry(hostValue, hostValue, 7365, hostValue);
List<HostConfigEntry> matches = new ArrayList<>();
matches.add(new HostConfigEntry(HostPatternsHolder.ALL_HOSTS_PATTERN, getClass().getSimpleName(), Short.MAX_VALUE, getClass().getSimpleName()));
- matches.add(new HostConfigEntry(HOST + String.valueOf(HostPatternsHolder.WILDCARD_PATTERN), getClass().getSimpleName(), Byte.MAX_VALUE, getClass().getSimpleName()));
+ matches.add(new HostConfigEntry(hostValue + String.valueOf(HostPatternsHolder.WILDCARD_PATTERN), getClass().getSimpleName(), Byte.MAX_VALUE, getClass().getSimpleName()));
matches.add(expected);
for (int index = 0; index < matches.size(); index++) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/KnownHostHashValueTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/KnownHostHashValueTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/KnownHostHashValueTest.java
index 2dcdbff..4fa4943 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/KnownHostHashValueTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/hosts/KnownHostHashValueTest.java
@@ -49,7 +49,7 @@ public class KnownHostHashValueTest extends BaseTestSupport {
@Parameters(name = "host={0}, hash={1}")
public static Collection<Object[]> parameters() {
return Arrays.<Object[]>asList(
- (Object[]) new String[]{ "192.168.1.61", "|1|F1E1KeoE/eEWhi10WpGv4OdiO6Y=|3988QV0VE8wmZL7suNrYQLITLCg=" });
+ (Object[]) new String[]{"192.168.1.61", "|1|F1E1KeoE/eEWhi10WpGv4OdiO6Y=|3988QV0VE8wmZL7suNrYQLITLCg="});
}
@Test
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
index 1a55b6e..9599684 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/BuiltinClientIdentitiesWatcherTest.java
@@ -134,7 +134,7 @@ public class BuiltinClientIdentitiesWatcherTest extends BaseTestSupport {
options = new OpenOption[]{StandardOpenOption.WRITE, StandardOpenOption.APPEND};
}
- try(OutputStream out = Files.newOutputStream(idFile, options)) {
+ try (OutputStream out = Files.newOutputStream(idFile, options)) {
out.write(new Date(System.currentTimeMillis()).toString().getBytes(StandardCharsets.UTF_8));
out.write('\n');
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcherTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcherTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcherTest.java
index 6a6ee3c..a44fad6 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcherTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityFileWatcherTest.java
@@ -102,7 +102,7 @@ public class ClientIdentityFileWatcherTest extends BaseTestSupport {
options = new OpenOption[]{StandardOpenOption.WRITE, StandardOpenOption.APPEND};
}
- try(OutputStream out = Files.newOutputStream(idFile, options)) {
+ try (OutputStream out = Files.newOutputStream(idFile, options)) {
out.write(new Date(System.currentTimeMillis()).toString().getBytes(StandardCharsets.UTF_8));
out.write('\n');
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java b/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
index 97ee2de..28abac5 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/keyverifier/KnownHostsServerKeyVerifierTest.java
@@ -62,7 +62,7 @@ import org.mockito.Mockito;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
private static final String HASHED_HOST = "192.168.1.61";
- private static final Map<String, PublicKey> hostsKeys = new TreeMap<String, PublicKey>(String.CASE_INSENSITIVE_ORDER);
+ private static final Map<String, PublicKey> HOST_KEYS = new TreeMap<String, PublicKey>(String.CASE_INSENSITIVE_ORDER);
private static Map<String, KnownHostEntry> hostsEntries;
private static Path entriesFile;
@@ -83,7 +83,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
KnownHostEntry entry = ke.getValue();
AuthorizedKeyEntry authEntry = ValidateUtils.checkNotNull(entry.getKeyEntry(), "No key extracted from %s", entry);
PublicKey key = authEntry.resolvePublicKey(PublicKeyEntryResolver.FAILING);
- assertNull("Multiple keys for host=" + host, hostsKeys.put(host, key));
+ assertNull("Multiple keys for host=" + host, HOST_KEYS.put(host, key));
}
}
@@ -113,7 +113,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
};
- for (Map.Entry<String, PublicKey> ke : hostsKeys.entrySet()) {
+ for (Map.Entry<String, PublicKey> ke : HOST_KEYS.entrySet()) {
String host = ke.getKey();
PublicKey serverKey = ke.getValue();
KnownHostEntry entry = hostsEntries.get(host);
@@ -151,7 +151,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
};
int verificationCount = 0;
- for (Map.Entry<String, PublicKey> ke : hostsKeys.entrySet()) {
+ for (Map.Entry<String, PublicKey> ke : HOST_KEYS.entrySet()) {
String host = ke.getKey();
PublicKey serverKey = ke.getValue();
KnownHostEntry entry = hostsEntries.get(host);
@@ -205,7 +205,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
ClientSession session = Mockito.mock(ClientSession.class);
Mockito.when(session.getFactoryManager()).thenReturn(manager);
- for (Map.Entry<String, PublicKey> ke : hostsKeys.entrySet()) {
+ for (Map.Entry<String, PublicKey> ke : HOST_KEYS.entrySet()) {
String host = ke.getKey();
PublicKey serverKey = ke.getValue();
KnownHostEntry entry = hostsEntries.get(host);
@@ -225,7 +225,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport {
verifier.setLoadedHostsEntries(keys);
// make sure can still validate the original hosts
- for (Map.Entry<String, PublicKey> ke : hostsKeys.entrySet()) {
+ for (Map.Entry<String, PublicKey> ke : HOST_KEYS.entrySet()) {
String host = ke.getKey();
PublicKey serverKey = ke.getValue();
KnownHostEntry entry = hostsEntries.get(host);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpCommandMain.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpCommandMain.java b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpCommandMain.java
index cd3d75e..75b0454 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpCommandMain.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpCommandMain.java
@@ -19,15 +19,17 @@
package org.apache.sshd.client.scp;
-import org.apache.sshd.client.scp.DefaultScpClient;
-
/**
- * Just a test class used to invoke {@link DefaultScpClient#main(String[])} in
+ * Just a test class used to invoke {@link org.apache.sshd.client.scp.DefaultScpClient#main(String[])} in
* order to have logging - which is in {@code test} scope
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class ScpCommandMain {
+public final class ScpCommandMain {
+ private ScpCommandMain() {
+ throw new UnsupportedOperationException("No instance");
+ }
+
public static void main(String[] args) throws Exception {
DefaultScpClient.main(args);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
index 928ee4c..b797680 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/scp/ScpTest.java
@@ -39,6 +39,10 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
+import com.jcraft.jsch.ChannelExec;
+import com.jcraft.jsch.JSch;
+import com.jcraft.jsch.JSchException;
+
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.Factory;
@@ -72,10 +76,6 @@ import org.junit.FixMethodOrder;
import org.junit.Test;
import org.junit.runners.MethodSorters;
-import com.jcraft.jsch.ChannelExec;
-import com.jcraft.jsch.JSch;
-import com.jcraft.jsch.JSchException;
-
import ch.ethz.ssh2.Connection;
import ch.ethz.ssh2.ConnectionInfo;
import ch.ethz.ssh2.SCPClient;
@@ -118,8 +118,7 @@ public class ScpTest extends BaseTestSupport {
.append('[').append(op).append(']')
.append(' ').append(isFile ? "File" : "Directory").append('=').append(path)
.append(' ').append("length=").append(length)
- .append(' ').append("perms=").append(perms)
- ;
+ .append(' ').append("perms=").append(perms);
if (t != null) {
sb.append(' ').append("ERROR=").append(t.getClass().getSimpleName()).append(": ").append(t.getMessage());
}
@@ -824,11 +823,11 @@ public class ScpTest extends BaseTestSupport {
@Test // see SSHD-628
public void testScpExitStatusPropagation() throws Exception {
- final int TEST_EXIT_VALUE = 7365;
+ final int testExitValue = 7365;
class InternalScpCommand extends ScpCommand implements ExitCallback {
private ExitCallback delegate;
- public InternalScpCommand(String command, ExecutorService executorService, boolean shutdownOnExit,
+ InternalScpCommand(String command, ExecutorService executorService, boolean shutdownOnExit,
int sendSize, int receiveSize, ScpFileOpener opener, ScpTransferEventListener eventListener) {
super(command, executorService, shutdownOnExit, sendSize, receiveSize, opener, eventListener);
}
@@ -836,7 +835,7 @@ public class ScpTest extends BaseTestSupport {
@Override
protected void writeCommandResponseMessage(String command, int exitValue, String exitMessage) throws IOException {
outputDebugMessage("writeCommandResponseMessage(%s) status=%d", command, exitValue);
- super.writeCommandResponseMessage(command, TEST_EXIT_VALUE, exitMessage);
+ super.writeCommandResponseMessage(command, testExitValue, exitMessage);
}
@Override
@@ -854,7 +853,7 @@ public class ScpTest extends BaseTestSupport {
public void onExit(int exitValue, String exitMessage) {
outputDebugMessage("onExit(%s) status=%d", this, exitValue);
if (exitValue == ScpHelper.OK) {
- delegate.onExit(TEST_EXIT_VALUE, exitMessage);
+ delegate.onExit(testExitValue, exitMessage);
} else {
delegate.onExit(exitValue, exitMessage);
}
@@ -895,7 +894,7 @@ public class ScpTest extends BaseTestSupport {
} catch (ScpException e) {
Integer exitCode = e.getExitStatus();
assertNotNull("No upload exit status", exitCode);
- assertEquals("Mismatched upload exit status", TEST_EXIT_VALUE, exitCode.intValue());
+ assertEquals("Mismatched upload exit status", testExitValue, exitCode.intValue());
}
if (Files.deleteIfExists(remoteFile)) {
@@ -912,7 +911,7 @@ public class ScpTest extends BaseTestSupport {
} catch (ScpException e) {
Integer exitCode = e.getExitStatus();
assertNotNull("No download exit status", exitCode);
- assertEquals("Mismatched download exit status", TEST_EXIT_VALUE, exitCode.intValue());
+ assertEquals("Mismatched download exit status", testExitValue, exitCode.intValue());
}
} finally {
client.stop();
@@ -930,11 +929,9 @@ public class ScpTest extends BaseTestSupport {
if (!modSuccess) {
System.err.append("Failed to set last modified time of ").append(file.getAbsolutePath())
.append(" to ").append(String.valueOf(expectedMillis))
- .append(" - ").println(new Date(expectedMillis))
- ;
+ .append(" - ").println(new Date(expectedMillis));
System.err.append("\t\t").append("Current value: ").append(String.valueOf(actualMillis))
- .append(" - ").println(new Date(actualMillis))
- ;
+ .append(" - ").println(new Date(actualMillis));
return;
}
@@ -1031,8 +1028,8 @@ public class ScpTest extends BaseTestSupport {
info.clientToServerMACAlgorithm, info.serverToClientMACAlgorithm);
assertTrue("Failed to authenticate", conn.authenticateWithPassword(getCurrentTestName(), getCurrentTestName()));
- final SCPClient scp_client = new SCPClient(conn);
- try (OutputStream output = scp_client.put(fileName, expected.length, remotePath, mode)) {
+ SCPClient scpClient = new SCPClient(conn);
+ try (OutputStream output = scpClient.put(fileName, expected.length, remotePath, mode)) {
output.write(expected);
}
@@ -1041,11 +1038,11 @@ public class ScpTest extends BaseTestSupport {
assertArrayEquals("Mismatched remote put data", expected, remoteData);
Arrays.fill(remoteData, (byte) 0); // make sure we start with a clean slate
- try (InputStream input = scp_client.get(remotePath + "/" + fileName)) {
+ try (InputStream input = scpClient.get(remotePath + "/" + fileName)) {
int readLen = input.read(remoteData);
assertEquals("Mismatched remote get data size", expected.length, readLen);
// make sure we reached EOF
- assertEquals("Unexpected extra data after read expected size", (-1), input.read());
+ assertEquals("Unexpected extra data after read expected size", -1, input.read());
}
assertArrayEquals("Mismatched remote get data", expected, remoteData);
@@ -1230,7 +1227,7 @@ public class ScpTest extends BaseTestSupport {
private static String readLine(InputStream in) throws IOException {
OutputStream baos = new ByteArrayOutputStream();
try {
- for (; ; ) {
+ for (;;) {
int c = in.read();
if (c == '\n') {
return baos.toString();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleScpClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleScpClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleScpClientTest.java
index f099fb2..ab96bc1 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleScpClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleScpClientTest.java
@@ -60,7 +60,7 @@ public class SimpleScpClientTest extends BaseSimpleClientTestSupport {
@Test
public void testSessionClosedWhenClientClosed() throws Exception {
- try(CloseableScpClient scp = login()) {
+ try (CloseableScpClient scp = login()) {
assertTrue("SCP not open", scp.isOpen());
Session session = scp.getClientSession();
@@ -74,7 +74,7 @@ public class SimpleScpClientTest extends BaseSimpleClientTestSupport {
@Test
public void testScpUploadProxy() throws Exception {
- try(CloseableScpClient scp = login()) {
+ try (CloseableScpClient scp = login()) {
Path scpRoot = Utils.resolve(targetPath, ScpHelper.SCP_COMMAND_PREFIX, getClass().getSimpleName(), getCurrentTestName());
Utils.deleteRecursive(scpRoot);
@@ -95,7 +95,7 @@ public class SimpleScpClientTest extends BaseSimpleClientTestSupport {
@Test
public void testScpDownloadProxy() throws Exception {
- try(CloseableScpClient scp = login()) {
+ try (CloseableScpClient scp = login()) {
Path scpRoot = Utils.resolve(targetPath, ScpHelper.SCP_COMMAND_PREFIX, getClass().getSimpleName(), getCurrentTestName());
Utils.deleteRecursive(scpRoot);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
index 450da6f..bafd8aa 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSessionClientTest.java
@@ -55,7 +55,7 @@ public class SimpleSessionClientTest extends BaseSimpleClientTestSupport {
sshd.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE);
client.start();
- try(ClientSession session = simple.sessionLogin(TEST_LOCALHOST, port, getCurrentTestName(), getCurrentTestName())) {
+ try (ClientSession session = simple.sessionLogin(TEST_LOCALHOST, port, getCurrentTestName(), getCurrentTestName())) {
assertEquals("Mismatched session username", getCurrentTestName(), session.getUsername());
}
}
@@ -79,7 +79,7 @@ public class SimpleSessionClientTest extends BaseSimpleClientTestSupport {
sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);
client.start();
- try(ClientSession session = simple.sessionLogin(TEST_LOCALHOST, port, getCurrentTestName(), identity)) {
+ try (ClientSession session = simple.sessionLogin(TEST_LOCALHOST, port, getCurrentTestName(), identity)) {
assertEquals("Mismatched session username", getCurrentTestName(), session.getUsername());
assertTrue("User identity not queried", identityQueried.get());
}
@@ -115,7 +115,7 @@ public class SimpleSessionClientTest extends BaseSimpleClientTestSupport {
client.start();
long nanoStart = System.nanoTime();
- try(ClientSession session = simple.sessionLogin(TEST_LOCALHOST, port, getCurrentTestName(), getCurrentTestName())) {
+ try (ClientSession session = simple.sessionLogin(TEST_LOCALHOST, port, getCurrentTestName(), getCurrentTestName())) {
fail("Unexpected connection success");
} catch (IOException e) {
long nanoEnd = System.nanoTime();
@@ -145,7 +145,7 @@ public class SimpleSessionClientTest extends BaseSimpleClientTestSupport {
client.start();
long nanoStart = System.nanoTime();
- try(ClientSession session = simple.sessionLogin(TEST_LOCALHOST, port, getCurrentTestName(), getCurrentTestName())) {
+ try (ClientSession session = simple.sessionLogin(TEST_LOCALHOST, port, getCurrentTestName(), getCurrentTestName())) {
fail("Unexpected connection success");
} catch (IOException e) {
long nanoEnd = System.nanoTime();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSftpClientTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSftpClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSftpClientTest.java
index d3748b9..b691a02 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSftpClientTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/simple/SimpleSftpClientTest.java
@@ -69,7 +69,7 @@ public class SimpleSftpClientTest extends BaseSimpleClientTestSupport {
@Test
public void testSessionClosedWhenClientClosed() throws Exception {
- try(SftpClient sftp = login()) {
+ try (SftpClient sftp = login()) {
assertTrue("SFTP not open", sftp.isOpen());
Session session = sftp.getClientSession();
@@ -91,7 +91,7 @@ public class SimpleSftpClientTest extends BaseSimpleClientTestSupport {
String clientFileName = clientFile.getFileName().toString();
String remoteFilePath = remoteFileDir + "/" + clientFileName;
- try(SftpClient sftp = login()) {
+ try (SftpClient sftp = login()) {
sftp.mkdir(remoteFileDir);
byte[] written = (getClass().getSimpleName() + "#" + getCurrentTestName() + IoUtils.EOL).getBytes(StandardCharsets.UTF_8);
@@ -112,7 +112,7 @@ public class SimpleSftpClientTest extends BaseSimpleClientTestSupport {
assertNotNull("No dir entries", dirEntries);
boolean matchFound = false;
- for (Iterator<SftpClient.DirEntry> it = dirEntries.iterator(); it.hasNext(); ) {
+ for (Iterator<SftpClient.DirEntry> it = dirEntries.iterator(); it.hasNext();) {
SftpClient.DirEntry entry = it.next();
String name = entry.getFilename();
if (clientFileName.equals(name)) {
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpCommandMain.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpCommandMain.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpCommandMain.java
index 4b6a8c8..4b34f92 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpCommandMain.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpCommandMain.java
@@ -25,7 +25,11 @@ package org.apache.sshd.client.subsystem.sftp;
*
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
-public class SftpCommandMain {
+public final class SftpCommandMain {
+ private SftpCommandMain() {
+ throw new UnsupportedOperationException("No instance");
+ }
+
public static void main(String[] args) throws Exception {
SftpCommand.main(args);
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
index f21a636..3a9ae43 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpFileSystemTest.java
@@ -369,12 +369,10 @@ public class SftpFileSystemTest extends BaseTestSupport {
assertHierarchyTargetFolderExists(file1.getParent());
String expected = "Hello world: " + getCurrentTestName();
- {
- outputDebugMessage("Write initial data to %s", file1);
- Files.write(file1, expected.getBytes(StandardCharsets.UTF_8));
- String buf = new String(Files.readAllBytes(file1), StandardCharsets.UTF_8);
- assertEquals("Mismatched read test data", expected, buf);
- }
+ outputDebugMessage("Write initial data to %s", file1);
+ Files.write(file1, expected.getBytes(StandardCharsets.UTF_8));
+ String buf = new String(Files.readAllBytes(file1), StandardCharsets.UTF_8);
+ assertEquals("Mismatched read test data", expected, buf);
if (version >= SftpConstants.SFTP_V4) {
outputDebugMessage("getFileAttributeView(%s)", file1);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
index b9a2f78..bf4a458 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpTest.java
@@ -49,6 +49,9 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicReference;
+import com.jcraft.jsch.ChannelSftp;
+import com.jcraft.jsch.JSch;
+
import org.apache.sshd.client.SshClient;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.client.subsystem.sftp.SftpClient.CloseableHandle;
@@ -102,14 +105,12 @@ import org.junit.runners.MethodSorters;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import com.jcraft.jsch.ChannelSftp;
-import com.jcraft.jsch.JSch;
-
/**
* @author <a href="mailto:dev@mina.apache.org">Apache MINA SSHD Project</a>
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class SftpTest extends AbstractSftpClientTestSupport {
+ private static final Map<String, OptionalFeature> EXPECTED_EXTENSIONS = SftpSubsystem.DEFAULT_SUPPORTED_CLIENT_EXTENSIONS;
private com.jcraft.jsch.Session session;
@@ -219,16 +220,17 @@ public class SftpTest extends AbstractSftpClientTestSupport {
int maxAllowed = actual.length / 4;
// allow less than actual
PropertyResolverUtils.updateProperty(sshd, SftpSubsystem.MAX_PACKET_LENGTH_PROP, maxAllowed);
- try(CloseableHandle handle = sftp.open(file, OpenMode.Read)) {
+ try (CloseableHandle handle = sftp.open(file, OpenMode.Read)) {
int readLen = sftp.read(handle, 0L, actual);
assertEquals("Mismatched read len", maxAllowed, readLen);
for (int index = 0; index < readLen; index++) {
- byte expByte = expected[index], actByte = actual[index];
+ byte expByte = expected[index];
+ byte actByte = actual[index];
if (expByte != actByte) {
fail("Mismatched values at index=" + index
- + ": expected=0x" + Integer.toHexString(expByte & 0xFF)
- + ", actual=0x" + Integer.toHexString(actByte & 0xFF));
+ + ": expected=0x" + Integer.toHexString(expByte & 0xFF)
+ + ", actual=0x" + Integer.toHexString(actByte & 0xFF));
}
}
}
@@ -425,7 +427,8 @@ public class SftpTest extends AbstractSftpClientTestSupport {
try (SftpClient.CloseableHandle h = sftp.open(file /* no mode == read */)) {
// NOTE: on Windows files are always readable
- // see https://svn.apache.org/repos/asf/harmony/enhanced/java/branches/java6/classlib/modules/luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java
+ // see https://svn.apache.org/repos/asf/harmony/enhanced/java/branches/java6/classlib/modules/
+ // luni/src/test/api/windows/org/apache/harmony/luni/tests/java/io/WinFileTest.java
assertTrue("Empty read should have failed on " + file, isWindows);
} catch (IOException e) {
if (isWindows) {
@@ -448,8 +451,9 @@ public class SftpTest extends AbstractSftpClientTestSupport {
// NOTE: on Windows files are always readable
int perms = sftp.stat(file).getPermissions();
- int permsMask = SftpConstants.S_IWUSR | (isWindows ? 0 : SftpConstants.S_IRUSR);
- assertEquals("Mismatched permissions for " + file + ": 0x" + Integer.toHexString(perms), 0, (perms & permsMask));
+ int readMask = isWindows ? 0 : SftpConstants.S_IRUSR;
+ int permsMask = SftpConstants.S_IWUSR | readMask;
+ assertEquals("Mismatched permissions for " + file + ": 0x" + Integer.toHexString(perms), 0, perms & permsMask);
javaFile.setWritable(true, false);
@@ -500,6 +504,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
}
@Test
+ @SuppressWarnings({"checkstyle:anoninnerlength", "checkstyle:methodlength"})
public void testClient() throws Exception {
List<NamedFactory<Command>> factories = sshd.getSubsystemFactories();
assertEquals("Mismatched subsystem factories count", 1, GenericUtils.size(factories));
@@ -520,6 +525,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
final AtomicInteger removedCount = new AtomicInteger(0);
final AtomicInteger modifyingCount = new AtomicInteger(0);
final AtomicInteger modifiedCount = new AtomicInteger(0);
+
factory.addSftpEventListener(new SftpEventListener() {
private final Logger log = LoggerFactory.getLogger(SftpEventListener.class);
@@ -822,9 +828,9 @@ public class SftpTest extends AbstractSftpClientTestSupport {
Path target = assertHierarchyTargetFolderExists(lclSftp).resolve("file.txt");
String remotePath = Utils.resolveRelativeRemotePath(targetPath.getParent(), target);
- final int NUM_ITERATIONS = 10;
- StringBuilder sb = new StringBuilder(d.length() * NUM_ITERATIONS * NUM_ITERATIONS);
- for (int j = 1; j <= NUM_ITERATIONS; j++) {
+ final int numIterations = 10;
+ StringBuilder sb = new StringBuilder(d.length() * numIterations * numIterations);
+ for (int j = 1; j <= numIterations; j++) {
if (sb.length() > 0) {
sb.setLength(0);
}
@@ -888,8 +894,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
File dir = baseDir.getParentFile();
Collection<String> expNames = OsUtils.isUNIX()
? new LinkedList<String>()
- : new TreeSet<String>(String.CASE_INSENSITIVE_ORDER)
- ;
+ : new TreeSet<String>(String.CASE_INSENSITIVE_ORDER);
String[] names = dir.list();
if (GenericUtils.length(names) > 0) {
for (String n : names) {
@@ -984,9 +989,9 @@ public class SftpTest extends AbstractSftpClientTestSupport {
try (SftpClient sftp = session.createSftpClient()) {
Map<String, byte[]> extensions = sftp.getServerExtensions();
for (String name : new String[]{
- SftpConstants.EXT_NEWLINE, SftpConstants.EXT_VERSIONS,
- SftpConstants.EXT_VENDOR_ID, SftpConstants.EXT_ACL_SUPPORTED,
- SftpConstants.EXT_SUPPORTED, SftpConstants.EXT_SUPPORTED2
+ SftpConstants.EXT_NEWLINE, SftpConstants.EXT_VERSIONS,
+ SftpConstants.EXT_VENDOR_ID, SftpConstants.EXT_ACL_SUPPORTED,
+ SftpConstants.EXT_SUPPORTED, SftpConstants.EXT_SUPPORTED2
}) {
assertTrue("Missing extension=" + name, extensions.containsKey(name));
}
@@ -1048,7 +1053,6 @@ public class SftpTest extends AbstractSftpClientTestSupport {
}
}
- private static Map<String, OptionalFeature> EXPECTED_EXTENSIONS = SftpSubsystem.DEFAULT_SUPPORTED_CLIENT_EXTENSIONS;
private static void assertSupportedExtensions(String extName, Collection<String> extensionNames) {
assertEquals(extName + "[count]", EXPECTED_EXTENSIONS.size(), GenericUtils.size(extensionNames));
@@ -1180,8 +1184,9 @@ public class SftpTest extends AbstractSftpClientTestSupport {
List<SftpClient.DirEntry> dirEntries = sftp.readDir(h);
assertNotNull("No dir entries", dirEntries);
- boolean dotFiltered = false, dotdotFiltered = false;
- for (Iterator<SftpClient.DirEntry> it = dirEntries.iterator(); it.hasNext(); ) {
+ boolean dotFiltered = false;
+ boolean dotdotFiltered = false;
+ for (Iterator<SftpClient.DirEntry> it = dirEntries.iterator(); it.hasNext();) {
SftpClient.DirEntry entry = it.next();
String name = entry.getFilename();
if (".".equals(name) && (!dotFiltered)) {
@@ -1201,7 +1206,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
sftp.remove(file);
- final int SIZE_FACTOR = Short.SIZE;
+ final int sizeFactor = Short.SIZE;
byte[] workBuf = new byte[IoUtils.DEFAULT_COPY_SIZE * Short.SIZE];
Factory<? extends Random> factory = manager.getRandomFactory();
Random random = factory.create();
@@ -1212,7 +1217,7 @@ public class SftpTest extends AbstractSftpClientTestSupport {
}
// force several internal read cycles to satisfy the full read
- try (InputStream is = sftp.read(file, workBuf.length / SIZE_FACTOR)) {
+ try (InputStream is = sftp.read(file, workBuf.length / sizeFactor)) {
int readLen = is.read(workBuf);
assertEquals("Mismatched read data length", workBuf.length, readLen);
@@ -1227,7 +1232,8 @@ public class SftpTest extends AbstractSftpClientTestSupport {
assertTrue("Test directory not reported as such", attributes.isDirectory());
int nb = 0;
- boolean dotFiltered = false, dotdotFiltered = false;
+ boolean dotFiltered = false;
+ boolean dotdotFiltered = false;
for (SftpClient.DirEntry entry : sftp.readDir(dir)) {
assertNotNull("Unexpected null entry", entry);
String name = entry.getFilename();
@@ -1286,10 +1292,10 @@ public class SftpTest extends AbstractSftpClientTestSupport {
* (see http://epaul.github.io/jsch-documentation/simple.javadoc/com/jcraft/jsch/ChannelSftp.html#current-directory)
*
*
- * This sftp client has the concept of a current local directory and
- * a current remote directory. These are not inherent to the protocol,
- * but are used implicitly for all path-based commands sent to the server
- * for the remote directory) or accessing the local file system (for the local directory).
+ * This sftp client has the concept of a current local directory and
+ * a current remote directory. These are not inherent to the protocol,
+ * but are used implicitly for all path-based commands sent to the server
+ * for the remote directory) or accessing the local file system (for the local directory).
*
* Therefore we are using "absolute" remote files for this test
*/
@@ -1301,9 +1307,9 @@ public class SftpTest extends AbstractSftpClientTestSupport {
ChannelSftp c = (ChannelSftp) session.openChannel(SftpConstants.SFTP_SUBSYSTEM_NAME);
c.connect();
try {
- try (InputStream dataStream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8))) {
- c.put(dataStream, remSrcPath);
- }
+ try (InputStream dataStream = new ByteArrayInputStream(data.getBytes(StandardCharsets.UTF_8))) {
+ c.put(dataStream, remSrcPath);
+ }
assertTrue("Source file not created: " + sourcePath, Files.exists(sourcePath));
assertEquals("Mismatched stored data in " + remSrcPath, data, readFile(remSrcPath));
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelectorTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelectorTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelectorTest.java
index 02a0533..ed2b3e9 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelectorTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionSelectorTest.java
@@ -52,15 +52,16 @@ public class SftpVersionSelectorTest extends BaseTestSupport {
for (int expected = SftpSubsystem.LOWER_SFTP_IMPL; expected <= SftpSubsystem.HIGHER_SFTP_IMPL; expected++) {
for (int index = 0; index < available.size(); index++) {
Collections.shuffle(available, rnd);
- assertEquals("Mismatched suffling selected for current=" + expected + ", available=" + available, expected, SftpVersionSelector.CURRENT.selectVersion(expected, available));
+ assertEquals("Mismatched suffling selected for current=" + expected + ", available=" + available,
+ expected, SftpVersionSelector.CURRENT.selectVersion(expected, available));
}
}
}
@Test
public void testFixedVersionSelector() {
- final int FIXED_VALUE = 7365;
- testVersionSelector(SftpVersionSelector.Utils.fixedVersionSelector(FIXED_VALUE), FIXED_VALUE);
+ final int fixedValue = 7365;
+ testVersionSelector(SftpVersionSelector.Utils.fixedVersionSelector(fixedValue), fixedValue);
}
@Test
@@ -87,7 +88,9 @@ public class SftpVersionSelectorTest extends BaseTestSupport {
int version = unavailable.get(0);
int actual = selector.selectVersion(version, unavailable);
fail("Unexpected selected version (" + actual + ")"
- + " for current= " + version + ", available=" + unavailable + ", preferred=" + preferred);
+ + " for current= " + version
+ + ", available=" + unavailable
+ + ", preferred=" + preferred);
} catch (IllegalStateException e) {
// expected
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java
index 20ce0cd..a47e5d2 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractCheckFileExtensionTest.java
@@ -105,13 +105,9 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor
}
});
- @Parameters(name = "{0} - dataSize={1}, blockSize={2}")
- public static Collection<Object[]> parameters() {
- return PARAMETERS;
- }
-
private final String algorithm;
- private final int dataSize, blockSize;
+ private final int dataSize;
+ private final int blockSize;
public AbstractCheckFileExtensionTest(String algorithm, int dataSize, int blockSize) throws IOException {
this.algorithm = algorithm;
@@ -119,6 +115,11 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor
this.blockSize = blockSize;
}
+ @Parameters(name = "{0} - dataSize={1}, blockSize={2}")
+ public static Collection<Object[]> parameters() {
+ return PARAMETERS;
+ }
+
@Before
public void setUp() throws Exception {
setupServer();
@@ -161,6 +162,7 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor
}
}
+ @SuppressWarnings("checkstyle:nestedtrydepth")
private void testCheckFileExtension(NamedFactory<? extends Digest> factory, byte[] data, int hashBlockSize, byte[] expectedHash) throws Exception {
Path targetPath = detectTargetFolder();
Path lclSftp = Utils.resolve(targetPath, SftpConstants.SFTP_SUBSYSTEM_NAME, getClass().getSimpleName());
@@ -231,8 +233,8 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor
byte[] actualHash = values.iterator().next();
if (!Arrays.equals(expectedHash, actualHash)) {
fail("Mismatched hashes for " + name
- + ": expected=" + BufferUtils.toHex(':', expectedHash)
- + ", actual=" + BufferUtils.toHex(':', expectedHash));
+ + ": expected=" + BufferUtils.toHex(':', expectedHash)
+ + ", actual=" + BufferUtils.toHex(':', expectedHash));
}
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtensionTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtensionTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtensionTest.java
index 8a5fe30..f39bf12 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtensionTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/AbstractMD5HashExtensionTest.java
@@ -71,6 +71,12 @@ public class AbstractMD5HashExtensionTest extends AbstractSftpClientTestSupport
Integer.valueOf(Byte.SIZE * IoUtils.DEFAULT_COPY_SIZE)
));
+ private final int size;
+
+ public AbstractMD5HashExtensionTest(int size) throws IOException {
+ this.size = size;
+ }
+
@Parameters(name = "dataSize={0}")
public static Collection<Object[]> parameters() {
return parameterize(DATA_SIZES);
@@ -81,12 +87,6 @@ public class AbstractMD5HashExtensionTest extends AbstractSftpClientTestSupport
Assume.assumeTrue("MD5 not supported", BuiltinDigests.md5.isSupported());
}
- private final int size;
-
- public AbstractMD5HashExtensionTest(int size) throws IOException {
- this.size = size;
- }
-
@Before
public void setUp() throws Exception {
setupServer();
@@ -113,6 +113,7 @@ public class AbstractMD5HashExtensionTest extends AbstractSftpClientTestSupport
}
}
+ @SuppressWarnings("checkstyle:nestedtrydepth")
private void testMD5HashExtension(byte[] data) throws Exception {
Digest digest = BuiltinDigests.md5.create();
digest.init();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImplTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImplTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImplTest.java
index 713c1a9..2ae45a4 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImplTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/helpers/CopyDataExtensionImplTest.java
@@ -89,12 +89,9 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport {
}
));
- @Parameters(name = "size={0}, readOffset={1}, readLength={2}, writeOffset={3}")
- public static Collection<Object[]> parameters() {
- return PARAMETERS;
- }
-
- private int size, srcOffset, length;
+ private int size;
+ private int srcOffset;
+ private int length;
private long dstOffset;
public CopyDataExtensionImplTest(int size, int srcOffset, int length, long dstOffset) throws IOException {
@@ -104,6 +101,11 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport {
this.dstOffset = dstOffset;
}
+ @Parameters(name = "size={0}, readOffset={1}, readLength={2}, writeOffset={3}")
+ public static Collection<Object[]> parameters() {
+ return PARAMETERS;
+ }
+
@Before
public void setUp() throws Exception {
setupServer();
@@ -183,7 +185,8 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport {
}
}
- int available = data.length, required = readOffset + readLength;
+ int available = data.length;
+ int required = readOffset + readLength;
if (required > available) {
required = available;
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHExtensionsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHExtensionsTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHExtensionsTest.java
index 339594e..7a6223c 100644
--- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHExtensionsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/helpers/OpenSSHExtensionsTest.java
@@ -122,19 +122,18 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport {
final AtomicReference<String> extensionHolder = new AtomicReference<String>(null);
final OpenSSHStatExtensionInfo expected = new OpenSSHStatExtensionInfo();
- {
- expected.f_bavail = Short.MAX_VALUE;
- expected.f_bfree = Integer.MAX_VALUE;
- expected.f_blocks = Short.MAX_VALUE;
- expected.f_bsize = IoUtils.DEFAULT_COPY_SIZE;
- expected.f_favail = Long.MAX_VALUE;
- expected.f_ffree = Byte.MAX_VALUE;
- expected.f_files = 3777347L;
- expected.f_flag = OpenSSHStatExtensionInfo.SSH_FXE_STATVFS_ST_RDONLY;
- expected.f_frsize = 7365L;
- expected.f_fsid = 1L;
- expected.f_namemax = 256;
- }
+ expected.f_bavail = Short.MAX_VALUE;
+ expected.f_bfree = Integer.MAX_VALUE;
+ expected.f_blocks = Short.MAX_VALUE;
+ expected.f_bsize = IoUtils.DEFAULT_COPY_SIZE;
+ expected.f_favail = Long.MAX_VALUE;
+ expected.f_ffree = Byte.MAX_VALUE;
+ expected.f_files = 3777347L;
+ expected.f_flag = OpenSSHStatExtensionInfo.SSH_FXE_STATVFS_ST_RDONLY;
+ expected.f_frsize = 7365L;
+ expected.f_fsid = 1L;
+ expected.f_namemax = 256;
+
sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory() {
@Override
public Command create() {
@@ -185,18 +184,16 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport {
session.auth().verify(5L, TimeUnit.SECONDS);
try (SftpClient sftp = session.createSftpClient()) {
- {
- OpenSSHStatPathExtension pathStat = assertExtensionCreated(sftp, OpenSSHStatPathExtension.class);
- OpenSSHStatExtensionInfo actual = pathStat.stat(srcPath);
- String invokedExtension = extensionHolder.getAndSet(null);
- assertEquals("Mismatched invoked extension", pathStat.getName(), invokedExtension);
- assertOpenSSHStatExtensionInfoEquals(invokedExtension, expected, actual);
- }
+ OpenSSHStatPathExtension pathStat = assertExtensionCreated(sftp, OpenSSHStatPathExtension.class);
+ OpenSSHStatExtensionInfo actual = pathStat.stat(srcPath);
+ String invokedExtension = extensionHolder.getAndSet(null);
+ assertEquals("Mismatched invoked extension", pathStat.getName(), invokedExtension);
+ assertOpenSSHStatExtensionInfoEquals(invokedExtension, expected, actual);
try (CloseableHandle handle = sftp.open(srcPath)) {
OpenSSHStatHandleExtension handleStat = assertExtensionCreated(sftp, OpenSSHStatHandleExtension.class);
- OpenSSHStatExtensionInfo actual = handleStat.stat(handle);
- String invokedExtension = extensionHolder.getAndSet(null);
+ actual = handleStat.stat(handle);
+ invokedExtension = extensionHolder.getAndSet(null);
assertEquals("Mismatched invoked extension", handleStat.getName(), invokedExtension);
assertOpenSSHStatExtensionInfoEquals(invokedExtension, expected, actual);
}
@@ -213,7 +210,9 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport {
if (Modifier.isStatic(mod)) {
continue;
}
- Object expValue = f.get(expected), actValue = f.get(actual);
+
+ Object expValue = f.get(expected);
+ Object actValue = f.get(actual);
assertEquals(extension + "[" + name + "]", expValue, actValue);
}
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
index 303bdbc..4879ee5 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/PropertyResolverUtilsTest.java
@@ -42,16 +42,16 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
@Test
public void testResolveAndUpdateClosestPropertyValue() {
- final String NAME = getCurrentTestName();
- final String ROOT_VALUE = getClass().getPackage().getName();
+ final String propName = getCurrentTestName();
+ final String rootValue = getClass().getPackage().getName();
Session resolver = createMockSession();
FactoryManager root = ValidateUtils.checkNotNull(resolver.getFactoryManager(), "No manager");
- assertNull("Unexpected root previous value", PropertyResolverUtils.updateProperty(root, NAME, ROOT_VALUE));
- assertSame("Mismatched root value", ROOT_VALUE, PropertyResolverUtils.getString(resolver, NAME));
+ assertNull("Unexpected root previous value", PropertyResolverUtils.updateProperty(root, propName, rootValue));
+ assertSame("Mismatched root value", rootValue, PropertyResolverUtils.getString(resolver, propName));
- final String NODE_VALUE = getClass().getSimpleName();
- assertNull("Unexpected node previous value", PropertyResolverUtils.updateProperty(resolver, NAME, NODE_VALUE));
- assertSame("Mismatched node value", NODE_VALUE, PropertyResolverUtils.getString(resolver, NAME));
+ final String nodeValue = getClass().getSimpleName();
+ assertNull("Unexpected node previous value", PropertyResolverUtils.updateProperty(resolver, propName, nodeValue));
+ assertSame("Mismatched node value", nodeValue, PropertyResolverUtils.getString(resolver, propName));
}
@Test
@@ -60,34 +60,34 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
Map<String, ?> props = resolver.getProperties();
assertTrue("Unexpected initial resolver values: " + props, GenericUtils.isEmpty(props));
- final String NAME = getCurrentTestName();
- assertNull("Unexpected initial resolved value", PropertyResolverUtils.getObject(resolver, NAME));
+ final String propName = getCurrentTestName();
+ assertNull("Unexpected initial resolved value", PropertyResolverUtils.getObject(resolver, propName));
- final String PROPKEY = SyspropsMapWrapper.getMappedSyspropKey(NAME);
- assertNull("Unexpected property value for " + PROPKEY, System.getProperty(PROPKEY));
+ final String propKey = SyspropsMapWrapper.getMappedSyspropKey(propName);
+ assertNull("Unexpected property value for " + propKey, System.getProperty(propKey));
try {
long expected = System.currentTimeMillis();
- System.setProperty(PROPKEY, Long.toString(expected));
- testLongProperty(resolver, NAME, expected);
+ System.setProperty(propKey, Long.toString(expected));
+ testLongProperty(resolver, propName, expected);
} finally {
- System.clearProperty(PROPKEY);
+ System.clearProperty(propKey);
}
try {
int expected = 3777347;
- System.setProperty(PROPKEY, Integer.toString(expected));
- testIntegerProperty(resolver, NAME, expected);
+ System.setProperty(propKey, Integer.toString(expected));
+ testIntegerProperty(resolver, propName, expected);
} finally {
- System.clearProperty(PROPKEY);
+ System.clearProperty(propKey);
}
for (final boolean expected : new boolean[]{false, true}) {
try {
- System.setProperty(PROPKEY, Boolean.toString(expected));
- testBooleanProperty(resolver, NAME, expected);
+ System.setProperty(propKey, Boolean.toString(expected));
+ testBooleanProperty(resolver, propName, expected);
} finally {
- System.clearProperty(PROPKEY);
+ System.clearProperty(propKey);
}
}
}
@@ -107,6 +107,7 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
testLongProperty(session, name, expected);
}
+ @SuppressWarnings("checkstyle:avoidnestedblocks")
private void testLongProperty(PropertyResolver resolver, String name, long expected) {
Map<String, ?> props = resolver.getProperties();
Object value = props.get(name);
@@ -145,6 +146,7 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
testIntegerProperty(session, name, expected);
}
+ @SuppressWarnings("checkstyle:avoidnestedblocks")
private void testIntegerProperty(PropertyResolver resolver, String name, int expected) {
Map<String, ?> props = resolver.getProperties();
Object value = props.get(name);
@@ -180,6 +182,7 @@ public class PropertyResolverUtilsTest extends BaseTestSupport {
}
}
+ @SuppressWarnings("checkstyle:avoidnestedblocks")
private void testBooleanProperty(PropertyResolver resolver, String name, boolean expected) {
Map<String, ?> props = resolver.getProperties();
Object value = props.get(name);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/common/SshConstantsTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/SshConstantsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/SshConstantsTest.java
index 552418f..86eb6b4 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/SshConstantsTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/SshConstantsTest.java
@@ -54,7 +54,7 @@ public class SshConstantsTest extends BaseTestSupport {
@Test
public void testAmbiguousOpcodes() throws Exception {
- int[] knownAmbiguities = { 30, 31, 60 };
+ int[] knownAmbiguities = {30, 31, 60};
Collection<Integer> opcodes = SshConstants.getAmbiguousOpcodes();
assertTrue("Not enough ambiguities found", GenericUtils.size(opcodes) >= knownAmbiguities.length);
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
index 09de71d..7e12136 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/auth/AuthenticationTest.java
@@ -388,7 +388,7 @@ public class AuthenticationTest extends BaseTestSupport {
challenge.setInteractionInstruction(anchor.getPackage().getName());
challenge.setLanguageTag(Locale.getDefault().getLanguage());
- final Map<String,String> rspMap = new TreeMap<String,String>(String.CASE_INSENSITIVE_ORDER) {
+ final Map<String, String> rspMap = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) {
private static final long serialVersionUID = 1L; // we're not serializing it
{
@@ -417,7 +417,7 @@ public class AuthenticationTest extends BaseTestSupport {
assertEquals("Mismatched number of responses", GenericUtils.size(rspMap), GenericUtils.size(responses));
int index = 0;
- for (Map.Entry<String,String> re : rspMap.entrySet()) {
+ for (Map.Entry<String, String> re : rspMap.entrySet()) {
String prompt = re.getKey();
String expected = re.getValue();
String actual = responses.get(index);
@@ -728,31 +728,33 @@ public class AuthenticationTest extends BaseTestSupport {
@Test // see SSHD-620
public void testHostBasedAuthentication() throws Exception {
- final String CLIENT_USERNAME = getClass().getSimpleName();
- final String CLIENT_HOSTNAME = SshdSocketAddress.toAddressString(SshdSocketAddress.getFirstExternalNetwork4Address());
- final KeyPair CLIENT_HOSTKEY = Utils.generateKeyPair("RSA", 1024);
+ final String hostClienUser = getClass().getSimpleName();
+ final String hostClientName = SshdSocketAddress.toAddressString(SshdSocketAddress.getFirstExternalNetwork4Address());
+ final KeyPair hostClientKey = Utils.generateKeyPair("RSA", 1024);
final AtomicInteger invocationCount = new AtomicInteger(0);
sshd.setHostBasedAuthenticator(new HostBasedAuthenticator() {
@Override
public boolean authenticate(ServerSession session, String username,
PublicKey clientHostKey, String clientHostName, String clientUsername, List<X509Certificate> certificates) {
invocationCount.incrementAndGet();
- return CLIENT_USERNAME.equals(clientUsername)
- && CLIENT_HOSTNAME.equals(clientHostName)
- && KeyUtils.compareKeys(CLIENT_HOSTKEY.getPublic(), clientHostKey);
+ return hostClienUser.equals(clientUsername)
+ && hostClientName.equals(clientHostName)
+ && KeyUtils.compareKeys(hostClientKey.getPublic(), clientHostKey);
}
});
sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE);
sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE);
sshd.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE);
- sshd.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList(org.apache.sshd.server.auth.hostbased.UserAuthHostBasedFactory.INSTANCE));
+ sshd.setUserAuthFactories(
+ Collections.<NamedFactory<org.apache.sshd.server.auth.UserAuth>>singletonList(
+ org.apache.sshd.server.auth.hostbased.UserAuthHostBasedFactory.INSTANCE));
try (SshClient client = setupTestClient()) {
org.apache.sshd.client.auth.hostbased.UserAuthHostBasedFactory factory =
new org.apache.sshd.client.auth.hostbased.UserAuthHostBasedFactory();
// TODO factory.setClientHostname(CLIENT_HOSTNAME);
- factory.setClientUsername(CLIENT_USERNAME);
- factory.setClientHostKeys(HostKeyIdentityProvider.Utils.wrap(CLIENT_HOSTKEY));
+ factory.setClientUsername(hostClienUser);
+ factory.setClientHostKeys(HostKeyIdentityProvider.Utils.wrap(hostClientKey));
client.setUserAuthFactories(Collections.<NamedFactory<org.apache.sshd.client.auth.UserAuth>>singletonList(factory));
client.start();
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
index 0e11331..3d21f80 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTest.java
@@ -36,8 +36,8 @@ import org.apache.sshd.client.channel.ClientChannel;
import org.apache.sshd.client.future.OpenFuture;
import org.apache.sshd.client.session.ClientSession;
import org.apache.sshd.common.FactoryManager;
-import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.NamedFactory;
+import org.apache.sshd.common.PropertyResolverUtils;
import org.apache.sshd.common.RuntimeSshException;
import org.apache.sshd.common.Service;
import org.apache.sshd.common.io.IoInputStream;
@@ -297,7 +297,7 @@ public class WindowTest extends BaseTestSupport {
}
private static void waitForWindowNotEquals(Window w1, Window w2, String n1, String n2, long maxWait) throws InterruptedException {
- for (long waited = 0L, maxWaitNanos = TimeUnit.MILLISECONDS.toNanos(maxWait); waited < maxWaitNanos; ) {
+ for (long waited = 0L, maxWaitNanos = TimeUnit.MILLISECONDS.toNanos(maxWait); waited < maxWaitNanos;) {
if (w1.getSize() != w2.getSize()) {
return;
}
@@ -314,7 +314,7 @@ public class WindowTest extends BaseTestSupport {
}
private static void waitForWindowEquals(Window w1, Window w2, String n1, String n2, long maxWait) throws InterruptedException {
- for (long waited = 0L, maxWaitNanos = TimeUnit.MILLISECONDS.toNanos(maxWait); waited < maxWaitNanos; ) {
+ for (long waited = 0L, maxWaitNanos = TimeUnit.MILLISECONDS.toNanos(maxWait); waited < maxWaitNanos;) {
if (w1.getSize() == w2.getSize()) {
return;
}
@@ -339,12 +339,12 @@ public class WindowTest extends BaseTestSupport {
public static class TestEchoShell extends EchoShell {
- public static final CountDownLatch latch = new CountDownLatch(1);
+ public static final CountDownLatch LATCH = new CountDownLatch(1);
@Override
public void destroy() {
- if (latch != null) {
- latch.countDown();
+ if (LATCH != null) {
+ LATCH.countDown();
}
super.destroy();
}
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/39a71a15/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
----------------------------------------------------------------------
diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
index 137e53b..d834621 100644
--- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
+++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java
@@ -86,7 +86,7 @@ public class WindowTimeoutTest extends BaseTestSupport {
@Test
public void testWindowWaitForSpaceTimeout() throws Exception {
- try(Window window = channel.getLocalWindow()) {
+ try (Window window = channel.getLocalWindow()) {
window.init(FactoryManager.DEFAULT_WINDOW_SIZE, FactoryManager.DEFAULT_MAX_PACKET_SIZE, null);
window.consume(window.getSize());
assertEquals("Window not empty", 0, window.getSize());
@@ -115,12 +115,11 @@ public class WindowTimeoutTest extends BaseTestSupport {
@Test
public void testWindowWaitAndConsumeTimeout() throws Exception {
- try(Window window = channel.getLocalWindow()) {
+ try (Window window = channel.getLocalWindow()) {
window.init(FactoryManager.DEFAULT_WINDOW_SIZE, FactoryManager.DEFAULT_MAX_PACKET_SIZE, null);
long waitStart = System.nanoTime();
- try
- {
+ try {
window.waitAndConsume(2 * window.getSize(), MAX_WAIT_TIME);
fail("Unexpected timed wait success");
} catch (SocketTimeoutException e) {