http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java index 545ac57..e12adf7 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/session/ServerUserAuthService.java @@ -34,6 +34,7 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; import org.apache.sshd.common.Factory; import org.apache.sshd.common.NamedFactory; @@ -108,7 +109,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service, // Verify all required methods are supported for (List<String> l : authMethods) { for (String m : l) { - NamedFactory<UserAuth> factory = NamedResource.Utils.findByName(m, String.CASE_INSENSITIVE_ORDER, userAuthFactories); + NamedFactory<UserAuth> factory = NamedResource.findByName(m, String.CASE_INSENSITIVE_ORDER, userAuthFactories); if (factory == null) { throw new SshException("Configured method is not supported: " + m); } @@ -117,7 +118,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service, if (log.isDebugEnabled()) { log.debug("ServerUserAuthService({}) authorized authentication methods: {}", - s, NamedResource.Utils.getNames(userAuthFactories)); + s, NamedResource.getNames(userAuthFactories)); } } @@ -188,7 +189,7 @@ public class ServerUserAuthService extends AbstractCloseable implements Service, session, username, service, method, nbAuthRequests, maxAuthRequests); } - Factory<UserAuth> factory = NamedResource.Utils.findByName(method, String.CASE_INSENSITIVE_ORDER, userAuthFactories); + Factory<UserAuth> factory = NamedResource.findByName(method, String.CASE_INSENSITIVE_ORDER, userAuthFactories); if (factory != null) { currentAuth = ValidateUtils.checkNotNull(factory.create(), "No authenticator created for method=%s", method); try { @@ -293,17 +294,11 @@ public class ServerUserAuthService extends AbstractCloseable implements Service, session.resetIdleTimeout(); log.info("Session {}@{} authenticated", username, session.getIoSession().getRemoteAddress()); } else { - StringBuilder sb = new StringBuilder(); - for (List<String> l : authMethods) { - if (GenericUtils.size(l) > 0) { - if (sb.length() > 0) { - sb.append(","); - } - sb.append(l.get(0)); - } - } + String remaining = authMethods.stream() + .filter(GenericUtils::isNotEmpty) + .map(l -> l.get(0)) + .collect(Collectors.joining(",")); - String remaining = sb.toString(); if (log.isDebugEnabled()) { log.debug("handleAuthenticationSuccess({}@{}) remaining methods={}", username, session, remaining); }
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java index 0cee65f..f810abd 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/InvertedShellWrapper.java @@ -150,12 +150,7 @@ public class InvertedShellWrapper extends AbstractLoggingBean implements Command shellIn = shell.getInputStream(); shellOut = shell.getOutputStream(); shellErr = shell.getErrorStream(); - executor.execute(new Runnable() { - @Override - public void run() { - pumpStreams(); - } - }); + executor.execute(this::pumpStreams); } @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java index 44b3caf..c10c5ec 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/ProcessShellFactory.java @@ -21,6 +21,7 @@ package org.apache.sshd.server.shell; import java.util.Arrays; import java.util.Collections; import java.util.List; + import org.apache.sshd.common.Factory; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.common.util.OsUtils; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/shell/TtyFilterOutputStream.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/shell/TtyFilterOutputStream.java b/sshd-core/src/main/java/org/apache/sshd/server/shell/TtyFilterOutputStream.java index c9fede8..5ec2ae2 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/shell/TtyFilterOutputStream.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/shell/TtyFilterOutputStream.java @@ -66,11 +66,12 @@ public class TtyFilterOutputStream extends FilterOutputStream { } } + @SuppressWarnings("StatementWithEmptyBody") protected void handleCR() throws IOException { if (ttyOptions.contains(PtyMode.ICRNL)) { writeRawOutput('\n'); // Map CR to NL on input } else if (ttyOptions.contains(PtyMode.IGNCR)) { - return; // Ignore CR on input + // Ignore CR on input } else { writeRawOutput('\r'); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/Handle.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/Handle.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/Handle.java index 9253c4a..4b9547d 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/Handle.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/Handle.java @@ -46,6 +46,7 @@ public abstract class Handle implements java.nio.channels.Channel { @Override public void close() throws IOException { if (!closed.getAndSet(true)) { + //noinspection UnnecessaryReturnStatement return; // debug breakpoint } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java index 8144252..9377172 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystem.java @@ -71,10 +71,13 @@ import java.util.TreeSet; import java.util.concurrent.ExecutorService; import java.util.concurrent.Future; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import org.apache.sshd.common.Factory; import org.apache.sshd.common.FactoryManager; import org.apache.sshd.common.NamedFactory; +import org.apache.sshd.common.NamedResource; import org.apache.sshd.common.OptionalFeature; import org.apache.sshd.common.PropertyResolver; import org.apache.sshd.common.PropertyResolverUtils; @@ -158,7 +161,9 @@ public class SftpSubsystem public static final int LOWER_SFTP_IMPL = SftpConstants.SFTP_V3; // Working implementation from v3 public static final int HIGHER_SFTP_IMPL = SftpConstants.SFTP_V6; // .. up to and including - public static final String ALL_SFTP_IMPL; + public static final String ALL_SFTP_IMPL = IntStream.rangeClosed(LOWER_SFTP_IMPL, HIGHER_SFTP_IMPL) + .mapToObj(Integer::toString) + .collect(Collectors.joining(",")); /** * Force the use of a max. packet length - especially for {@link #doReadDir(Buffer, int)} @@ -186,22 +191,16 @@ public class SftpSubsystem public static final Map<String, OptionalFeature> DEFAULT_SUPPORTED_CLIENT_EXTENSIONS = // TODO text-seek - see http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-13.txt // TODO home-directory - see http://tools.ietf.org/wg/secsh/draft-ietf-secsh-filexfer/draft-ietf-secsh-filexfer-09.txt - Collections.unmodifiableMap( - new LinkedHashMap<String, OptionalFeature>() { - private static final long serialVersionUID = 1L; // we're not serializing it - - private final OptionalFeature anyDigests = OptionalFeature.Utils.any(BuiltinDigests.VALUES); - { - put(SftpConstants.EXT_VERSION_SELECT, OptionalFeature.TRUE); - put(SftpConstants.EXT_COPY_FILE, OptionalFeature.TRUE); - put(SftpConstants.EXT_MD5_HASH, BuiltinDigests.md5); - put(SftpConstants.EXT_MD5_HASH_HANDLE, BuiltinDigests.md5); - put(SftpConstants.EXT_CHECK_FILE_HANDLE, anyDigests); - put(SftpConstants.EXT_CHECK_FILE_NAME, anyDigests); - put(SftpConstants.EXT_COPY_DATA, OptionalFeature.TRUE); - put(SftpConstants.EXT_SPACE_AVAILABLE, OptionalFeature.TRUE); - } - }); + GenericUtils.<String, OptionalFeature>mapBuilder() + .put(SftpConstants.EXT_VERSION_SELECT, OptionalFeature.TRUE) + .put(SftpConstants.EXT_COPY_FILE, OptionalFeature.TRUE) + .put(SftpConstants.EXT_MD5_HASH, BuiltinDigests.md5) + .put(SftpConstants.EXT_MD5_HASH_HANDLE, BuiltinDigests.md5) + .put(SftpConstants.EXT_CHECK_FILE_HANDLE, OptionalFeature.any(BuiltinDigests.VALUES)) + .put(SftpConstants.EXT_CHECK_FILE_NAME, OptionalFeature.any(BuiltinDigests.VALUES)) + .put(SftpConstants.EXT_COPY_DATA, OptionalFeature.TRUE) + .put(SftpConstants.EXT_SPACE_AVAILABLE, OptionalFeature.TRUE) + .immutable(); /** * Comma-separated list of which {@code OpenSSH} extensions are reported and @@ -218,16 +217,7 @@ public class SftpSubsystem )); public static final List<String> DEFAULT_OPEN_SSH_EXTENSIONS_NAMES = - Collections.unmodifiableList(new ArrayList<String>(DEFAULT_OPEN_SSH_EXTENSIONS.size()) { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - for (OpenSSHExtension ext : DEFAULT_OPEN_SSH_EXTENSIONS) { - add(ext.getName()); - } - } - - }); + Collections.unmodifiableList(NamedResource.getNameList(DEFAULT_OPEN_SSH_EXTENSIONS)); public static final List<String> DEFAULT_UNIX_VIEW = Collections.singletonList("unix:*"); @@ -256,29 +246,14 @@ public class SftpSubsystem * effort if not accessible via the file system attributes views */ public static final Map<String, FileInfoExtractor<?>> FILEATTRS_RESOLVERS = - Collections.unmodifiableMap(new TreeMap<String, FileInfoExtractor<?>>(String.CASE_INSENSITIVE_ORDER) { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - put("isRegularFile", FileInfoExtractor.ISREG); - put("isDirectory", FileInfoExtractor.ISDIR); - put("isSymbolicLink", FileInfoExtractor.ISSYMLINK); - put("permissions", FileInfoExtractor.PERMISSIONS); - put("size", FileInfoExtractor.SIZE); - put("lastModifiedTime", FileInfoExtractor.LASTMODIFIED); - } - }); - - static { - StringBuilder sb = new StringBuilder(2 * (1 + (HIGHER_SFTP_IMPL - LOWER_SFTP_IMPL))); - for (int v = LOWER_SFTP_IMPL; v <= HIGHER_SFTP_IMPL; v++) { - if (sb.length() > 0) { - sb.append(','); - } - sb.append(v); - } - ALL_SFTP_IMPL = sb.toString(); - } + GenericUtils.<String, FileInfoExtractor<?>>mapBuilder(String.CASE_INSENSITIVE_ORDER) + .put("isRegularFile", FileInfoExtractor.ISREG) + .put("isDirectory", FileInfoExtractor.ISDIR) + .put("isSymbolicLink", FileInfoExtractor.ISSYMLINK) + .put("permissions", FileInfoExtractor.PERMISSIONS) + .put("size", FileInfoExtractor.SIZE) + .put("lastModifiedTime", FileInfoExtractor.LASTMODIFIED) + .immutable(); protected ExitCallback callback; protected InputStream in; @@ -2851,21 +2826,18 @@ public class SftpSubsystem } else if (supportedViews.contains("unix")) { views = DEFAULT_UNIX_VIEW; } else { - views = new ArrayList<>(supportedViews.size()); - for (String v : supportedViews) { - views.add(v + ":*"); - } + views = GenericUtils.map(supportedViews, v -> v + ":*"); } for (String v : views) { Map<String, Object> ta = readFileAttributes(file, v, options); - if (GenericUtils.size(ta) > 0) { + if (GenericUtils.isNotEmpty(ta)) { attrs.putAll(ta); } } Map<String, Object> completions = resolveMissingFileAttributes(file, flags, attrs, options); - if (GenericUtils.size(completions) > 0) { + if (GenericUtils.isNotEmpty(completions)) { attrs.putAll(completions); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystemFactory.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystemFactory.java b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystemFactory.java index bdc5d2e..3fe2721 100644 --- a/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystemFactory.java +++ b/sshd-core/src/main/java/org/apache/sshd/server/subsystem/sftp/SftpSubsystemFactory.java @@ -19,7 +19,6 @@ package org.apache.sshd.server.subsystem.sftp; -import java.util.Collection; import java.util.concurrent.ExecutorService; import org.apache.sshd.common.subsystem.sftp.SftpConstants; @@ -67,14 +66,7 @@ public class SftpSubsystemFactory extends AbstractSftpEventListenerManager imple factory.setExecutorService(executors); factory.setShutdownOnExit(shutdownExecutor); factory.setUnsupportedAttributePolicy(policy); - - Collection<? extends SftpEventListener> listeners = getRegisteredListeners(); - if (GenericUtils.size(listeners) > 0) { - for (SftpEventListener l : listeners) { - factory.addSftpEventListener(l); - } - } - + GenericUtils.forEach(getRegisteredListeners(), factory::addSftpEventListener); return factory; } } @@ -136,13 +128,7 @@ public class SftpSubsystemFactory extends AbstractSftpEventListenerManager imple @Override public Command create() { SftpSubsystem subsystem = new SftpSubsystem(getExecutorService(), isShutdownOnExit(), getUnsupportedAttributePolicy()); - Collection<? extends SftpEventListener> listeners = getRegisteredListeners(); - if (GenericUtils.size(listeners) > 0) { - for (SftpEventListener l : listeners) { - subsystem.addSftpEventListener(l); - } - } - + GenericUtils.forEach(getRegisteredListeners(), subsystem::addSftpEventListener); return subsystem; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java index 4cffe5e..3ebff89 100644 --- a/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/KeyReExchangeTest.java @@ -23,8 +23,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; import java.lang.reflect.Proxy; import java.nio.charset.StandardCharsets; import java.util.ArrayList; @@ -160,17 +158,14 @@ public class KeyReExchangeTest extends BaseTestSupport { @Override public KeyExchange create() { final KeyExchange proxiedInstance = factory.create(); - return (KeyExchange) Proxy.newProxyInstance(loader, interfaces, new InvocationHandler() { - @Override - public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { - String name = method.getName(); - if ("init".equals(name) && (!successfulInit.get())) { - throw new UnsupportedOperationException("Intentionally failing 'init'"); - } else if ("next".equals(name) && (!successfulNext.get())) { - throw new UnsupportedOperationException("Intentionally failing 'next'"); - } else { - return method.invoke(proxiedInstance, args); - } + return (KeyExchange) Proxy.newProxyInstance(loader, interfaces, (proxy, method, args) -> { + String name = method.getName(); + if ("init".equals(name) && (!successfulInit.get())) { + throw new UnsupportedOperationException("Intentionally failing 'init'"); + } else if ("next".equals(name) && (!successfulNext.get())) { + throw new UnsupportedOperationException("Intentionally failing 'next'"); + } else { + return method.invoke(proxiedInstance, args); } }); } @@ -485,12 +480,6 @@ public class KeyReExchangeTest extends BaseTestSupport { teeOut.write("this is my command\n".getBytes(StandardCharsets.UTF_8)); teeOut.flush(); - StringBuilder sb = new StringBuilder(101 * 10); - for (int i = 0; i < 100; i++) { - sb.append("0123456789"); - } - sb.append('\n'); - final AtomicInteger exchanges = new AtomicInteger(); session.addSessionListener(new SessionListener() { @Override http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/LoadTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java index 2e5566f..4d9b796 100644 --- a/sshd-core/src/test/java/org/apache/sshd/LoadTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/LoadTest.java @@ -22,8 +22,8 @@ import java.io.ByteArrayOutputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.EnumSet; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -96,18 +96,15 @@ public class LoadTest extends BaseTestSupport { final List<Throwable> errors = new ArrayList<>(); final CountDownLatch latch = new CountDownLatch(nbThreads); for (int i = 0; i < nbThreads; i++) { - Runnable r = new Runnable() { - @Override - public void run() { - try { - for (int i = 0; i < nbSessionsPerThread; i++) { - runClient(msg); - } - } catch (Throwable t) { - errors.add(t); - } finally { - latch.countDown(); + Runnable r = () -> { + try { + for (int i1 = 0; i1 < nbSessionsPerThread; i1++) { + runClient(msg); } + } catch (Throwable t) { + errors.add(t); + } finally { + latch.countDown(); } }; new Thread(r).start(); @@ -123,9 +120,8 @@ public class LoadTest extends BaseTestSupport { try (SshClient client = setupTestClient()) { PropertyResolverUtils.updateProperty(client, FactoryManager.MAX_PACKET_SIZE, 1024 * 16); PropertyResolverUtils.updateProperty(client, FactoryManager.WINDOW_SIZE, 1024 * 8); - client.setKeyExchangeFactories(Arrays.asList( - ClientBuilder.DH2KEX.transform(BuiltinDHFactories.dhg1))); - client.setCipherFactories(Arrays.asList(BuiltinCiphers.blowfishcbc)); + client.setKeyExchangeFactories(Collections.singletonList(ClientBuilder.DH2KEX.transform(BuiltinDHFactories.dhg1))); + client.setCipherFactories(Collections.singletonList(BuiltinCiphers.blowfishcbc)); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java b/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java index 61d0345..a4fe2ae 100644 --- a/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/WindowAdjustTest.java @@ -37,11 +37,8 @@ import org.apache.sshd.client.SshClient; import org.apache.sshd.client.channel.ClientChannel; import org.apache.sshd.client.channel.ClientChannelEvent; import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.common.Factory; -import org.apache.sshd.common.future.SshFutureListener; import org.apache.sshd.common.io.IoInputStream; import org.apache.sshd.common.io.IoOutputStream; -import org.apache.sshd.common.io.IoWriteFuture; import org.apache.sshd.common.io.WritePendingException; import org.apache.sshd.common.util.buffer.Buffer; import org.apache.sshd.common.util.buffer.ByteArrayBuffer; @@ -49,7 +46,6 @@ import org.apache.sshd.common.util.io.NoCloseOutputStream; import org.apache.sshd.common.util.logging.AbstractLoggingBean; import org.apache.sshd.common.util.threads.ThreadUtils; import org.apache.sshd.server.AsyncCommand; -import org.apache.sshd.server.Command; import org.apache.sshd.server.Environment; import org.apache.sshd.server.ExitCallback; import org.apache.sshd.server.SshServer; @@ -90,12 +86,7 @@ public class WindowAdjustTest extends BaseTestSupport { final byte[] msg = Files.readAllBytes( Paths.get(getClass().getResource("/big-msg.txt").toURI())); - sshServer.setShellFactory(new Factory<Command>() { - @Override - public Command create() { - return new FloodingAsyncCommand(msg, BIG_MSG_SEND_COUNT, END_FILE); - } - }); + sshServer.setShellFactory(() -> new FloodingAsyncCommand(msg, BIG_MSG_SEND_COUNT, END_FILE)); sshServer.setKeyPairProvider(new SimpleGeneratorHostKeyProvider()); sshServer.start(); @@ -182,7 +173,7 @@ public class WindowAdjustTest extends BaseTestSupport { private static final AtomicInteger POOL_COUNT = new AtomicInteger(0); private final AtomicReference<ExecutorService> executorHolder = new AtomicReference<>(); - private final AtomicReference<Future<?>> futureHolder = new AtomicReference<Future<?>>(); + private final AtomicReference<Future<?>> futureHolder = new AtomicReference<>(); private AsyncInPendingWrapper pendingWrapper; private byte[] msg; @@ -237,17 +228,13 @@ public class WindowAdjustTest extends BaseTestSupport { ExecutorService service = ThreadUtils.newSingleThreadExecutor(getClass().getSimpleName() + "-" + POOL_COUNT.incrementAndGet()); executorHolder.set(service); - futureHolder.set(service.submit(new Runnable() { - @SuppressWarnings("synthetic-access") - @Override - public void run() { - log.info("Start heavy load sending " + sendCount + " messages of " + msg.length + " bytes"); - for (int i = 0; i < sendCount; i++) { - pendingWrapper.write(new ByteArrayBuffer(msg)); - } - log.info("Sending EOF signal"); - pendingWrapper.write(new ByteArrayBuffer(new byte[]{eofSignal})); + futureHolder.set(service.submit((Runnable) () -> { + log.info("Start heavy load sending " + sendCount + " messages of " + msg.length + " bytes"); + for (int i = 0; i < sendCount; i++) { + pendingWrapper.write(new ByteArrayBuffer(msg)); } + log.info("Sending EOF signal"); + pendingWrapper.write(new ByteArrayBuffer(new byte[]{eofSignal})); })); log.info("Started"); } @@ -277,15 +264,7 @@ public class WindowAdjustTest extends BaseTestSupport { private IoOutputStream asyncIn; // Order has to be preserved for queued writes - private final Deque<Buffer> pending = new LinkedList<Buffer>() { - // we don't expect to serialize it - private static final long serialVersionUID = 1L; - - @Override - public boolean add(Buffer o) { - return super.add(o); - } - }; + private final Deque<Buffer> pending = new LinkedList<Buffer>(); AsyncInPendingWrapper(IoOutputStream out) { this.asyncIn = out; @@ -305,19 +284,15 @@ public class WindowAdjustTest extends BaseTestSupport { private void writeWithPendingDetection(final Buffer msg, final boolean wasPending) { try { - asyncIn.write(msg).addListener(new SshFutureListener<IoWriteFuture>() { - @SuppressWarnings("synthetic-access") - @Override - public void operationComplete(IoWriteFuture future) { - if (future.isWritten()) { - if (wasPending) { - pending.remove(); - } - writePendingIfAny(); - } else { - Throwable t = future.getException(); - log.warn("Failed to write message", t); + asyncIn.write(msg).addListener(future -> { + if (future.isWritten()) { + if (wasPending) { + pending.remove(); } + writePendingIfAny(); + } else { + Throwable t = future.getException(); + log.warn("Failed to write message", t); } }); } catch (final WritePendingException e) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java index a7e18fe..d0cc821 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientAuthenticationManagerTest.java @@ -147,7 +147,7 @@ public class ClientAuthenticationManagerTest extends BaseTestSupport { }; assertEquals("Mismatched initial factories list", "", manager.getUserAuthFactoriesNameList()); - String expected = NamedResource.Utils.getNames(BuiltinUserAuthFactories.VALUES); + String expected = NamedResource.getNames(BuiltinUserAuthFactories.VALUES); manager.setUserAuthFactoriesNameList(expected); assertEquals("Mismatched updated factories names", expected, manager.getUserAuthFactoriesNameList()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java index 291099d..dead8c2 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientSessionListenerTest.java @@ -20,8 +20,6 @@ package org.apache.sshd.client; import java.io.IOException; -import java.net.SocketAddress; -import java.security.PublicKey; import java.util.Collections; import java.util.EnumMap; import java.util.List; @@ -125,12 +123,9 @@ public class ClientSessionListenerTest extends BaseTestSupport { @Test public void testSessionListenerCanInfluenceAuthentication() throws IOException { final AtomicInteger verificationCount = new AtomicInteger(); - final ServerKeyVerifier verifier = new ServerKeyVerifier() { - @Override - public boolean verifyServerKey(ClientSession sshClientSession, SocketAddress remoteAddress, PublicKey serverKey) { - verificationCount.incrementAndGet(); - return true; - } + final ServerKeyVerifier verifier = (sshClientSession, remoteAddress, serverKey) -> { + verificationCount.incrementAndGet(); + return true; }; SessionListener listener = new SessionListener() { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java index aaab336..d939b11 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/ClientTest.java @@ -27,10 +27,8 @@ import java.io.OutputStream; import java.io.PipedInputStream; import java.io.PipedOutputStream; import java.net.InetSocketAddress; -import java.net.SocketAddress; import java.nio.charset.StandardCharsets; import java.security.KeyPair; -import java.security.PublicKey; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -60,7 +58,6 @@ import org.apache.sshd.client.channel.ClientChannel; import org.apache.sshd.client.channel.ClientChannelEvent; import org.apache.sshd.client.future.AuthFuture; import org.apache.sshd.client.future.OpenFuture; -import org.apache.sshd.client.keyverifier.ServerKeyVerifier; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.client.subsystem.SubsystemClient; import org.apache.sshd.client.subsystem.sftp.SftpClient; @@ -102,7 +99,6 @@ import org.apache.sshd.server.SshServer; import org.apache.sshd.server.auth.keyboard.DefaultKeyboardInteractiveAuthenticator; import org.apache.sshd.server.auth.keyboard.KeyboardInteractiveAuthenticator; import org.apache.sshd.server.auth.password.RejectAllPasswordAuthenticator; -import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; import org.apache.sshd.server.channel.ChannelSession; import org.apache.sshd.server.channel.ChannelSessionFactory; import org.apache.sshd.server.forward.DirectTcpipFactory; @@ -446,34 +442,25 @@ public class ClientTest extends BaseTestSupport { client.start(); try (final ClientSession session = createTestClientSession()) { - testClientListener(channelHolder, ChannelShell.class, new Factory<ChannelShell>() { - @Override - public ChannelShell create() { - try { - return session.createShellChannel(); - } catch (IOException e) { - throw new RuntimeException(e); - } + testClientListener(channelHolder, ChannelShell.class, () -> { + try { + return session.createShellChannel(); + } catch (IOException e) { + throw new RuntimeException(e); } }); - testClientListener(channelHolder, ChannelExec.class, new Factory<ChannelExec>() { - @Override - public ChannelExec create() { - try { - return session.createExecChannel(getCurrentTestName()); - } catch (IOException e) { - throw new RuntimeException(e); - } + testClientListener(channelHolder, ChannelExec.class, () -> { + try { + return session.createExecChannel(getCurrentTestName()); + } catch (IOException e) { + throw new RuntimeException(e); } }); - testClientListener(channelHolder, SftpClient.class, new Factory<SftpClient>() { - @Override - public SftpClient create() { - try { - return session.createSftpClient(); - } catch (IOException e) { - throw new RuntimeException(e); - } + testClientListener(channelHolder, SftpClient.class, () -> { + try { + return session.createSftpClient(); + } catch (IOException e) { + throw new RuntimeException(e); } }); } finally { @@ -955,7 +942,7 @@ public class ClientTest extends BaseTestSupport { public void testPublicKeyAuth() throws Exception { sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE); sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE); - client.setUserAuthFactories(Arrays.asList(UserAuthPublicKeyFactory.INSTANCE)); + client.setUserAuthFactories(Collections.singletonList(UserAuthPublicKeyFactory.INSTANCE)); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { @@ -974,13 +961,8 @@ public class ClientTest extends BaseTestSupport { provider.setAlgorithm(KeyUtils.RSA_ALGORITHM); final KeyPair pair = createTestHostKeyProvider().loadKey(KeyPairProvider.SSH_RSA); - sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() { - @Override - public boolean authenticate(String username, PublicKey key, ServerSession session) { - return key.equals(pair.getPublic()); - } - }); - client.setUserAuthFactories(Arrays.asList(UserAuthPublicKeyFactory.INSTANCE)); + sshd.setPublickeyAuthenticator((username, key, session) -> key.equals(pair.getPublic())); + client.setUserAuthFactories(Collections.singletonList(UserAuthPublicKeyFactory.INSTANCE)); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { @@ -996,7 +978,7 @@ public class ClientTest extends BaseTestSupport { @Test public void testPasswordAuthNew() throws Exception { - client.setUserAuthFactories(Arrays.asList(UserAuthPasswordFactory.INSTANCE)); + client.setUserAuthFactories(Collections.singletonList(UserAuthPasswordFactory.INSTANCE)); client.start(); try (ClientSession session = createTestClientSession()) { @@ -1009,7 +991,7 @@ public class ClientTest extends BaseTestSupport { @Test public void testPasswordAuthNewWithFailureOnFirstIdentity() throws Exception { - client.setUserAuthFactories(Arrays.asList(UserAuthPasswordFactory.INSTANCE)); + client.setUserAuthFactories(Collections.singletonList(UserAuthPasswordFactory.INSTANCE)); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { @@ -1025,7 +1007,7 @@ public class ClientTest extends BaseTestSupport { @Test public void testKeyboardInteractiveAuthNew() throws Exception { - client.setUserAuthFactories(Arrays.asList(UserAuthKeyboardInteractiveFactory.INSTANCE)); + client.setUserAuthFactories(Collections.singletonList(UserAuthKeyboardInteractiveFactory.INSTANCE)); client.start(); try (ClientSession session = createTestClientSession()) { @@ -1038,7 +1020,7 @@ public class ClientTest extends BaseTestSupport { @Test public void testKeyboardInteractiveAuthNewWithFailureOnFirstIdentity() throws Exception { - client.setUserAuthFactories(Arrays.asList(UserAuthKeyboardInteractiveFactory.INSTANCE)); + client.setUserAuthFactories(Collections.singletonList(UserAuthKeyboardInteractiveFactory.INSTANCE)); client.start(); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { @@ -1055,7 +1037,7 @@ public class ClientTest extends BaseTestSupport { @Test // see SSHD-504 public void testDefaultKeyboardInteractivePasswordPromptLocationIndependence() throws Exception { final Collection<String> mismatchedPrompts = new LinkedList<>(); - client.setUserAuthFactories(Arrays.asList(new UserAuthKeyboardInteractiveFactory() { + client.setUserAuthFactories(Collections.singletonList(new UserAuthKeyboardInteractiveFactory() { @Override public UserAuthKeyboardInteractive create() { return new UserAuthKeyboardInteractive() { @@ -1074,38 +1056,20 @@ public class ClientTest extends BaseTestSupport { })); client.start(); - final Transformer<String, String> stripper = new Transformer<String, String>() { - @Override - public String transform(String input) { - int pos = GenericUtils.isEmpty(input) ? -1 : input.lastIndexOf(':'); - if (pos < 0) { - return input; - } else { - return input.substring(0, pos); - } + final Transformer<String, String> stripper = input -> { + int pos = GenericUtils.isEmpty(input) ? -1 : input.lastIndexOf(':'); + if (pos < 0) { + return input; + } else { + return input.substring(0, pos); } }; final List<Transformer<String, String>> xformers = - Collections.unmodifiableList(Arrays.asList( - new Transformer<String, String>() { // prefixed - @Override - public String transform(String input) { - return getCurrentTestName() + " " + input; - } - }, - new Transformer<String, String>() { // suffixed - @Override - public String transform(String input) { - return stripper.transform(input) + " " + getCurrentTestName() + ":"; - } - }, - new Transformer<String, String>() { // infix - @Override - public String transform(String input) { - return getCurrentTestName() + " " + stripper.transform(input) + " " + getCurrentTestName() + ":"; - } - } - )); + Collections.unmodifiableList(Arrays.<Transformer<String, String>>asList( + input -> getCurrentTestName() + " " + input, + input -> stripper.transform(input) + " " + getCurrentTestName() + ":", + input -> getCurrentTestName() + " " + stripper.transform(input) + " " + getCurrentTestName() + ":" + )); sshd.setKeyboardInteractiveAuthenticator(new DefaultKeyboardInteractiveAuthenticator() { private int xformerIndex; @@ -1356,14 +1320,11 @@ public class ClientTest extends BaseTestSupport { public void testWaitAuth() throws Exception { final AtomicBoolean ok = new AtomicBoolean(); client.setServerKeyVerifier( - new ServerKeyVerifier() { - @Override - public boolean verifyServerKey(ClientSession sshClientSession, SocketAddress remoteAddress, PublicKey serverKey) { - outputDebugMessage("verifyServerKey(%s): %s", remoteAddress, serverKey); - ok.set(true); - return true; - } - } + (sshClientSession, remoteAddress, serverKey) -> { + outputDebugMessage("verifyServerKey(%s): %s", remoteAddress, serverKey); + ok.set(true); + return true; + } ); client.start(); @@ -1394,7 +1355,7 @@ public class ClientTest extends BaseTestSupport { Set<Integer> ids = new HashSet<>(channels.size()); for (ClientChannel c : channels) { int id = c.getId(); - assertTrue("Channel ID repeated: " + id, ids.add(Integer.valueOf(id))); + assertTrue("Channel ID repeated: " + id, ids.add(id)); } } finally { for (Closeable c : channels) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/auth/PasswordIdentityProviderTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/auth/PasswordIdentityProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/client/auth/PasswordIdentityProviderTest.java index bdda762..5078bae 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/auth/PasswordIdentityProviderTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/auth/PasswordIdentityProviderTest.java @@ -54,12 +54,12 @@ public class PasswordIdentityProviderTest extends BaseTestSupport { Collection<String> passwords = Arrays.asList(va); expected.addAll(passwords); - PasswordIdentityProvider p = PasswordIdentityProvider.Utils.wrap(passwords); + PasswordIdentityProvider p = PasswordIdentityProvider.wrap(passwords); assertProviderContents("Wrapped", p, passwords); providers.add(p); } - PasswordIdentityProvider p = PasswordIdentityProvider.Utils.multiProvider(providers); + PasswordIdentityProvider p = PasswordIdentityProvider.multiProvider(providers); assertProviderContents("Multi", p, expected); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecTest.java b/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecTest.java index 2f4c10c..01cfed4 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/channel/ChannelExecTest.java @@ -25,8 +25,6 @@ import java.util.concurrent.TimeUnit; import org.apache.sshd.client.SshClient; import org.apache.sshd.client.session.ClientSession; -import org.apache.sshd.server.Command; -import org.apache.sshd.server.CommandFactory; import org.apache.sshd.server.SshServer; import org.apache.sshd.util.test.BaseTestSupport; import org.apache.sshd.util.test.CommandExecutionHelper; @@ -53,18 +51,13 @@ public class ChannelExecTest extends BaseTestSupport { @BeforeClass public static void setupClientAndServer() throws Exception { sshd = Utils.setupTestServer(ChannelExecTest.class); - sshd.setCommandFactory(new CommandFactory() { + sshd.setCommandFactory(command -> new CommandExecutionHelper(command) { @Override - public Command createCommand(String command) { - return new CommandExecutionHelper(command) { - @Override - protected boolean handleCommandLine(String command) throws Exception { - OutputStream stdout = getOut(); - stdout.write(command.getBytes(StandardCharsets.US_ASCII)); - stdout.flush(); - return false; - } - }; + protected boolean handleCommandLine(String command) throws Exception { + OutputStream stdout = getOut(); + stdout.write(command.getBytes(StandardCharsets.US_ASCII)); + stdout.flush(); + return false; } }); sshd.start(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 ccb874f..9871ed5 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 @@ -26,7 +26,6 @@ import java.net.SocketAddress; import java.nio.file.Path; import java.security.GeneralSecurityException; import java.security.KeyPair; -import java.security.PublicKey; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -48,8 +47,6 @@ import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.common.util.net.SshdSocketAddress; import org.apache.sshd.server.SshServer; import org.apache.sshd.server.auth.password.RejectAllPasswordAuthenticator; -import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; -import org.apache.sshd.server.session.ServerSession; import org.apache.sshd.util.test.BaseTestSupport; import org.apache.sshd.util.test.Utils; import org.junit.After; @@ -93,12 +90,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport { @Test public void testEffectiveHostConfigResolution() throws Exception { final HostConfigEntry entry = new HostConfigEntry(getCurrentTestName(), TEST_LOCALHOST, port, getCurrentTestName()); - client.setHostConfigEntryResolver(new HostConfigEntryResolver() { - @Override - public HostConfigEntry resolveEffectiveHost(String host, int portValue, String username) throws IOException { - return entry; - } - }); + client.setHostConfigEntryResolver((host, portValue, username) -> entry); client.start(); try (ClientSession session = client.connect( @@ -143,15 +135,12 @@ public class HostConfigEntryResolverTest extends BaseTestSupport { final KeyPair identity = Utils.getFirstKeyPair(sshd); 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)) { - return KeyUtils.compareKeys(identity.getPublic(), key); - } - - return false; + sshd.setPublickeyAuthenticator((username, key, session) -> { + if (user.equals(username)) { + return KeyUtils.compareKeys(identity.getPublic(), key); } + + return false; }); sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE); @@ -177,12 +166,7 @@ public class HostConfigEntryResolverTest extends BaseTestSupport { 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 { - return entry; - } - }); + client.setHostConfigEntryResolver((host1, portValue, username) -> entry); client.start(); try (ClientSession session = client.connect( @@ -209,19 +193,16 @@ public class HostConfigEntryResolverTest extends BaseTestSupport { 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() { - @Override - public boolean authenticate(String username, PublicKey key, ServerSession session) { - if (KeyUtils.compareKeys(defaultIdentity.getPublic(), key)) { - defaultClientIdentityAttempted.set(true); - } - - if (user.equals(username)) { - return KeyUtils.compareKeys(specificIdentity.getPublic(), key); - } + sshd.setPublickeyAuthenticator((username, key, session) -> { + if (KeyUtils.compareKeys(defaultIdentity.getPublic(), key)) { + defaultClientIdentityAttempted.set(true); + } - return false; + if (user.equals(username)) { + return KeyUtils.compareKeys(specificIdentity.getPublic(), key); } + + return false; }); sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityTest.java b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityTest.java index e392e86..4618a8c 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/config/keys/ClientIdentityTest.java @@ -79,7 +79,7 @@ public class ClientIdentityTest extends BaseTestSupport { options); assertEquals("Mismatched loaded ids count", GenericUtils.size(expected), GenericUtils.size(ids)); - Collection<KeyPair> pairs = new ArrayList<KeyPair>(ids.size()); + Collection<KeyPair> pairs = new ArrayList<>(ids.size()); for (BuiltinIdentities type : BuiltinIdentities.VALUES) { if (expected.contains(type)) { KeyPair kp = ids.get(type.getName()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 e7f028e..c8666b1 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 @@ -63,7 +63,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> HOST_KEYS = new TreeMap<String, PublicKey>(String.CASE_INSENSITIVE_ORDER); + private static final Map<String, PublicKey> HOST_KEYS = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); private static Map<String, KnownHostEntry> hostsEntries; private static Path entriesFile; @@ -91,13 +91,10 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport { @Test public void testNoUpdatesNoNewHostsAuthentication() throws Exception { final AtomicInteger delegateCount = new AtomicInteger(0); - ServerKeyVerifier delegate = new ServerKeyVerifier() { - @Override - public boolean verifyServerKey(ClientSession clientSession, SocketAddress remoteAddress, PublicKey serverKey) { - delegateCount.incrementAndGet(); - fail("verifyServerKey(" + clientSession + ")[" + remoteAddress + "] unexpected invocation"); - return false; - } + ServerKeyVerifier delegate = (clientSession, remoteAddress, serverKey) -> { + delegateCount.incrementAndGet(); + fail("verifyServerKey(" + clientSession + ")[" + remoteAddress + "] unexpected invocation"); + return false; }; final AtomicInteger updateCount = new AtomicInteger(0); @@ -128,12 +125,9 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport { @Test public void testFileUpdatedOnEveryNewHost() throws Exception { final AtomicInteger delegateCount = new AtomicInteger(0); - ServerKeyVerifier delegate = new ServerKeyVerifier() { - @Override - public boolean verifyServerKey(ClientSession clientSession, SocketAddress remoteAddress, PublicKey serverKey) { - delegateCount.incrementAndGet(); - return true; - } + ServerKeyVerifier delegate = (clientSession, remoteAddress, serverKey) -> { + delegateCount.incrementAndGet(); + return true; }; Path path = getKnownHostCopyPath(); @@ -339,7 +333,7 @@ public class KnownHostsServerKeyVerifierTest extends BaseTestSupport { return Collections.emptyMap(); } - Map<String, KnownHostEntry> hostsMap = new TreeMap<String, KnownHostEntry>(String.CASE_INSENSITIVE_ORDER); + Map<String, KnownHostEntry> hostsMap = new TreeMap<>(String.CASE_INSENSITIVE_ORDER); for (KnownHostEntry entry : entries) { String line = entry.getConfigLine(); outputDebugMessage("loadTestLines(%s) processing %s", file, line); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 2ddc21b..66f17b3 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 @@ -1163,8 +1163,7 @@ public class ScpTest extends BaseTestSupport { } private static String readLine(InputStream in) throws IOException { - OutputStream baos = new ByteArrayOutputStream(); - try { + try (OutputStream baos = new ByteArrayOutputStream()) { for (;;) { int c = in.read(); if (c == '\n') { @@ -1175,8 +1174,6 @@ public class ScpTest extends BaseTestSupport { baos.write(c); } } - } finally { - baos.close(); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java index 9ab4ab3..2b14a4c 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/session/ClientSessionTest.java @@ -84,23 +84,18 @@ public class ClientSessionTest extends BaseTestSupport { public void testDefaultExecuteCommandMethod() throws Exception { final String expectedCommand = getCurrentTestName() + "-CMD"; final String expectedResponse = getCurrentTestName() + "-RSP"; - sshd.setCommandFactory(new CommandFactory() { - @Override - public Command createCommand(String command) { - return new CommandExecutionHelper(command) { - private boolean cmdProcessed; + sshd.setCommandFactory(command -> new CommandExecutionHelper(command) { + private boolean cmdProcessed; - @Override - protected boolean handleCommandLine(String command) throws Exception { - assertEquals("Mismatched incoming command", expectedCommand, command); - assertFalse("Duplicated command call", cmdProcessed); - OutputStream stdout = getOut(); - stdout.write(expectedResponse.getBytes(StandardCharsets.US_ASCII)); - stdout.flush(); - cmdProcessed = true; - return false; - } - }; + @Override + protected boolean handleCommandLine(String command) throws Exception { + assertEquals("Mismatched incoming command", expectedCommand, command); + assertFalse("Duplicated command call", cmdProcessed); + OutputStream stdout = getOut(); + stdout.write(expectedResponse.getBytes(StandardCharsets.US_ASCII)); + stdout.flush(); + cmdProcessed = true; + return false; } }); @@ -118,23 +113,18 @@ public class ClientSessionTest extends BaseTestSupport { public void testExceptionThrownIfRemoteStderrWrittenTo() throws Exception { final String expectedCommand = getCurrentTestName() + "-CMD"; final String expectedErrorMessage = getCurrentTestName() + "-ERR"; - sshd.setCommandFactory(new CommandFactory() { - @Override - public Command createCommand(String command) { - return new CommandExecutionHelper(command) { - private boolean cmdProcessed; + sshd.setCommandFactory(command -> new CommandExecutionHelper(command) { + private boolean cmdProcessed; - @Override - protected boolean handleCommandLine(String command) throws Exception { - assertEquals("Mismatched incoming command", expectedCommand, command); - assertFalse("Duplicated command call", cmdProcessed); - OutputStream stderr = getErr(); - stderr.write(expectedErrorMessage.getBytes(StandardCharsets.US_ASCII)); - stderr.flush(); - cmdProcessed = true; - return false; - } - }; + @Override + protected boolean handleCommandLine(String command) throws Exception { + assertEquals("Mismatched incoming command", expectedCommand, command); + assertFalse("Duplicated command call", cmdProcessed); + OutputStream stderr = getErr(); + stderr.write(expectedErrorMessage.getBytes(StandardCharsets.US_ASCII)); + stderr.flush(); + cmdProcessed = true; + return false; } }); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 929e377..c4bcdbe 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 @@ -21,7 +21,6 @@ package org.apache.sshd.client.simple; import java.io.IOException; import java.security.KeyPair; -import java.security.PublicKey; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; @@ -32,9 +31,7 @@ import org.apache.sshd.common.session.SessionListener; import org.apache.sshd.common.util.ValidateUtils; import org.apache.sshd.server.auth.password.PasswordAuthenticator; import org.apache.sshd.server.auth.password.RejectAllPasswordAuthenticator; -import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; import org.apache.sshd.server.auth.pubkey.RejectAllPublickeyAuthenticator; -import org.apache.sshd.server.session.ServerSession; import org.apache.sshd.util.test.Utils; import org.junit.FixMethodOrder; import org.junit.Test; @@ -64,16 +61,13 @@ public class SimpleSessionClientTest extends BaseSimpleClientTestSupport { public void testLoginSessionWithIdentity() throws Exception { final KeyPair identity = Utils.getFirstKeyPair(createTestHostKeyProvider()); final AtomicBoolean identityQueried = new AtomicBoolean(false); - sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() { - @Override - public boolean authenticate(String username, PublicKey key, ServerSession session) { - if (username.equals(getCurrentTestName())) { - identityQueried.set(true); - return KeyUtils.compareKeys(identity.getPublic(), key); - } - - return false; + sshd.setPublickeyAuthenticator((username, key, session) -> { + if (username.equals(getCurrentTestName())) { + identityQueried.set(true); + return KeyUtils.compareKeys(identity.getPublic(), key); } + + return false; }); // make sure authentication occurs only with public keys sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE); @@ -116,16 +110,13 @@ public class SimpleSessionClientTest extends BaseSimpleClientTestSupport { // make sure authentication occurs only for passwords sshd.setPublickeyAuthenticator(RejectAllPublickeyAuthenticator.INSTANCE); final PasswordAuthenticator delegate = ValidateUtils.checkNotNull(sshd.getPasswordAuthenticator(), "No password authenticator"); - sshd.setPasswordAuthenticator(new PasswordAuthenticator() { - @Override - public boolean authenticate(String username, String password, ServerSession session) { - try { - Thread.sleep(AUTH_TIMEOUT + 150L); - } catch (InterruptedException e) { - // ignored - } - return delegate.authenticate(username, password, session); + sshd.setPasswordAuthenticator((username, password, session) -> { + try { + Thread.sleep(AUTH_TIMEOUT + 150L); + } catch (InterruptedException e) { + // ignored } + return delegate.authenticate(username, password, session); }); client.start(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java index 1fb68e0..57c5998 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/AbstractSftpClientTestSupport.java @@ -88,7 +88,7 @@ public abstract class AbstractSftpClientTestSupport extends BaseTestSupport { sshd.setFileSystemFactory(fileSystemFactory); } - protected static final <E extends SftpClientExtension> E assertExtensionCreated(SftpClient sftp, Class<E> type) { + protected static <E extends SftpClientExtension> E assertExtensionCreated(SftpClient sftp, Class<E> type) { E instance = sftp.getExtension(type); assertNotNull("Extension not created: " + type.getSimpleName(), instance); assertTrue("Extension not supported: " + instance.getName(), instance.isSupported()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandleTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandleTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandleTest.java index fd8d94e..7d14e6c 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandleTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/DefaultCloseableHandleTest.java @@ -31,8 +31,6 @@ import org.junit.Test; import org.junit.runners.MethodSorters; import org.mockito.Matchers; import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.stubbing.Answer; /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> @@ -47,14 +45,11 @@ public class DefaultCloseableHandleTest extends BaseTestSupport { public void testChannelBehavior() throws IOException { final byte[] id = getCurrentTestName().getBytes(StandardCharsets.UTF_8); SftpClient client = Mockito.mock(SftpClient.class); - Mockito.doAnswer(new Answer<Void>() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - Handle handle = (Handle) args[0]; - assertArrayEquals("Mismatched closing handle", id, handle.getIdentifier()); - return null; - } + Mockito.doAnswer(invocation -> { + Object[] args = invocation.getArguments(); + Handle handle = (Handle) args[0]; + assertArrayEquals("Mismatched closing handle", id, handle.getIdentifier()); + return null; }).when(client).close(Matchers.any(Handle.class)); CloseableHandle handle = new DefaultCloseableHandle(client, getCurrentTestName(), id); @@ -72,13 +67,10 @@ public class DefaultCloseableHandleTest extends BaseTestSupport { public void testCloseIdempotent() throws IOException { SftpClient client = Mockito.mock(SftpClient.class); final AtomicBoolean closeCalled = new AtomicBoolean(false); - Mockito.doAnswer(new Answer<Void>() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - Object[] args = invocation.getArguments(); - assertFalse("Close already called on handle=" + args[0], closeCalled.getAndSet(true)); - return null; - } + Mockito.doAnswer(invocation -> { + Object[] args = invocation.getArguments(); + assertFalse("Close already called on handle=" + args[0], closeCalled.getAndSet(true)); + return null; }).when(client).close(Matchers.any(Handle.class)); CloseableHandle handle = new DefaultCloseableHandle(client, getCurrentTestName(), getCurrentTestName().getBytes(StandardCharsets.UTF_8)); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 cf661ef..d97ec36 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 @@ -116,14 +116,10 @@ public class SftpFileSystemTest extends BaseTestSupport { @Test public void testFileSystem() throws Exception { try (FileSystem fs = FileSystems.newFileSystem(createDefaultFileSystemURI(), - new TreeMap<String, Object>() { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - put(SftpFileSystemProvider.READ_BUFFER_PROP_NAME, Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE)); - put(SftpFileSystemProvider.WRITE_BUFFER_PROP_NAME, Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE)); - } - })) { + GenericUtils.<String, Object>mapBuilder() + .put(SftpFileSystemProvider.READ_BUFFER_PROP_NAME, IoUtils.DEFAULT_COPY_SIZE) + .put(SftpFileSystemProvider.WRITE_BUFFER_PROP_NAME, IoUtils.DEFAULT_COPY_SIZE) + .build())) { assertTrue("Not an SftpFileSystem", fs instanceof SftpFileSystem); testFileSystem(fs, ((SftpFileSystem) fs).getVersion()); } @@ -137,8 +133,8 @@ public class SftpFileSystemTest extends BaseTestSupport { params.put("test-name", getCurrentTestName()); int expectedVersion = (SftpSubsystem.LOWER_SFTP_IMPL + SftpSubsystem.HIGHER_SFTP_IMPL) / 2; - params.put(SftpFileSystemProvider.VERSION_PARAM, Integer.valueOf(expectedVersion)); - try (SftpFileSystem fs = (SftpFileSystem) FileSystems.newFileSystem(createDefaultFileSystemURI(params), Collections.emptyMap())) { + params.put(SftpFileSystemProvider.VERSION_PARAM, expectedVersion); + try (SftpFileSystem fs = (SftpFileSystem) FileSystems.newFileSystem(createDefaultFileSystemURI(params), Collections.<String, Object>emptyMap())) { try (SftpClient sftpClient = fs.getClient()) { assertEquals("Mismatched negotiated version", expectedVersion, sftpClient.getVersion()); @@ -164,14 +160,10 @@ public class SftpFileSystemTest extends BaseTestSupport { Utils.deleteRecursive(lclSftp); try (FileSystem fs = FileSystems.newFileSystem(createDefaultFileSystemURI(), - new TreeMap<String, Object>() { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - put(SftpFileSystemProvider.READ_BUFFER_PROP_NAME, Integer.valueOf(SftpClient.MIN_READ_BUFFER_SIZE)); - put(SftpFileSystemProvider.WRITE_BUFFER_PROP_NAME, Integer.valueOf(SftpClient.MIN_WRITE_BUFFER_SIZE)); - } - })) { + GenericUtils.<String, Object>mapBuilder() + .put(SftpFileSystemProvider.READ_BUFFER_PROP_NAME, SftpClient.MIN_READ_BUFFER_SIZE) + .put(SftpFileSystemProvider.WRITE_BUFFER_PROP_NAME, SftpClient.MIN_WRITE_BUFFER_SIZE) + .build())) { Path parentPath = targetPath.getParent(); Path clientFolder = lclSftp.resolve("client"); @@ -183,7 +175,7 @@ public class SftpFileSystemTest extends BaseTestSupport { Map<String, Object> attrs = Files.readAttributes(file, "posix:*"); assertNotNull("No attributes read for " + file, attrs); - Files.setAttribute(file, "basic:size", Long.valueOf(2L)); + Files.setAttribute(file, "basic:size", 2L); Files.setAttribute(file, "posix:permissions", PosixFilePermissions.fromString("rwxr-----")); Files.setAttribute(file, "basic:lastModifiedTime", FileTime.fromMillis(100000L)); @@ -292,28 +284,14 @@ public class SftpFileSystemTest extends BaseTestSupport { @Test public void testSftpVersionSelector() throws Exception { final AtomicInteger selected = new AtomicInteger(-1); - SftpVersionSelector selector = new SftpVersionSelector() { - @Override - public int selectVersion(ClientSession session, int current, List<Integer> available) { - int numAvailable = GenericUtils.size(available); - Integer maxValue = null; - if (numAvailable == 1) { - maxValue = available.get(0); - } else { - for (Integer v : available) { - if (v.intValue() == current) { - continue; - } - - if ((maxValue == null) || (maxValue.intValue() < v.intValue())) { - maxValue = v; - } - } - } - - selected.set(maxValue.intValue()); - return selected.get(); - } + SftpVersionSelector selector = (session, current, available) -> { + int value = GenericUtils.stream(available) + .mapToInt(Integer::intValue) + .filter(v -> v != current) + .max() + .orElseGet(() -> current); + selected.set(value); + return value; }; try (SshClient client = setupTestClient()) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 996036a..79e25ea 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 @@ -51,7 +51,6 @@ 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; @@ -64,10 +63,8 @@ import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.OptionalFeature; import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.channel.WindowClosedException; -import org.apache.sshd.common.file.FileSystemFactory; import org.apache.sshd.common.file.virtualfs.VirtualFileSystemFactory; import org.apache.sshd.common.random.Random; -import org.apache.sshd.common.session.Session; import org.apache.sshd.common.subsystem.sftp.SftpConstants; import org.apache.sshd.common.subsystem.sftp.SftpException; import org.apache.sshd.common.subsystem.sftp.extensions.AclSupportedParser.AclCapabilities; @@ -224,12 +221,7 @@ public class SftpTest extends AbstractSftpClientTestSupport { public void testNavigateBeyondRootFolder() throws Exception { Path rootLocation = Paths.get(OsUtils.isUNIX() ? "/" : "C:\\"); final FileSystem fsRoot = rootLocation.getFileSystem(); - sshd.setFileSystemFactory(new FileSystemFactory() { - @Override - public FileSystem createFileSystem(Session session) throws IOException { - return fsRoot; - } - }); + sshd.setFileSystemFactory(session1 -> fsRoot); try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); @@ -1034,28 +1026,14 @@ public class SftpTest extends AbstractSftpClientTestSupport { @Test public void testSftpVersionSelector() throws Exception { final AtomicInteger selected = new AtomicInteger(-1); - SftpVersionSelector selector = new SftpVersionSelector() { - @Override - public int selectVersion(ClientSession session, int current, List<Integer> available) { - int numAvailable = GenericUtils.size(available); - Integer maxValue = null; - if (numAvailable == 1) { - maxValue = available.get(0); - } else { - for (Integer v : available) { - if (v.intValue() == current) { - continue; - } - - if ((maxValue == null) || (maxValue.intValue() < v.intValue())) { - maxValue = v; - } - } - } - - selected.set(maxValue.intValue()); - return selected.get(); - } + SftpVersionSelector selector = (session, current, available) -> { + int value = GenericUtils.stream(available) + .mapToInt(Integer::intValue) + .filter(v -> v != current) + .max() + .orElseGet(() -> current); + selected.set(value); + return value; }; try (ClientSession session = client.connect(getCurrentTestName(), TEST_LOCALHOST, port).verify(7L, TimeUnit.SECONDS).getSession()) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 ba0d456..3447bdc 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 @@ -48,9 +48,8 @@ public class SftpVersionSelectorTest extends BaseTestSupport { Random rnd = new Random(System.nanoTime()); ClientSession session = Mockito.mock(ClientSession.class); for (int expected = SftpSubsystem.LOWER_SFTP_IMPL; expected <= SftpSubsystem.HIGHER_SFTP_IMPL; expected++) { - assertEquals("Mismatched directly selected for available=" + available, - expected, SftpVersionSelector.CURRENT.selectVersion(session, expected, available)); - available.add(Integer.valueOf(expected)); + assertEquals("Mismatched directly selected for available=" + available, expected, SftpVersionSelector.CURRENT.selectVersion(session, expected, available)); + available.add(expected); } for (int expected = SftpSubsystem.LOWER_SFTP_IMPL; expected <= SftpSubsystem.HIGHER_SFTP_IMPL; expected++) { @@ -65,14 +64,14 @@ public class SftpVersionSelectorTest extends BaseTestSupport { @Test public void testFixedVersionSelector() { final int fixedValue = 7365; - testVersionSelector(SftpVersionSelector.Utils.fixedVersionSelector(fixedValue), fixedValue); + testVersionSelector(SftpVersionSelector.fixedVersionSelector(fixedValue), fixedValue); } @Test public void testPreferredVersionSelector() { List<Integer> available = new ArrayList<>(); for (int version = SftpSubsystem.LOWER_SFTP_IMPL; version <= SftpSubsystem.HIGHER_SFTP_IMPL; version++) { - available.add(Integer.valueOf(version)); + available.add(version); } List<Integer> preferred = new ArrayList<>(available); @@ -81,7 +80,7 @@ public class SftpVersionSelectorTest extends BaseTestSupport { ClientSession session = Mockito.mock(ClientSession.class); for (int index = 0; index < preferred.size(); index++) { Collections.shuffle(preferred, rnd); - SftpVersionSelector selector = SftpVersionSelector.Utils.preferredVersionSelector(preferred); + SftpVersionSelector selector = SftpVersionSelector.preferredVersionSelector(preferred); int expected = preferred.get(0); for (int current = SftpSubsystem.LOWER_SFTP_IMPL; current <= SftpSubsystem.HIGHER_SFTP_IMPL; current++) { @@ -116,7 +115,7 @@ public class SftpVersionSelectorTest extends BaseTestSupport { private static void testVersionSelector(SftpVersionSelector selector, int expected) { List<Integer> available = new ArrayList<>(); for (int version = SftpSubsystem.LOWER_SFTP_IMPL; version <= SftpSubsystem.HIGHER_SFTP_IMPL; version++) { - available.add(Integer.valueOf(version)); + available.add(version); } Random rnd = new Random(System.nanoTime()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionsTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionsTest.java index ad29b74..58d2eed 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionsTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/SftpVersionsTest.java @@ -39,6 +39,8 @@ import java.util.TreeMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; +import java.util.stream.Collectors; +import java.util.stream.IntStream; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.client.subsystem.sftp.SftpClient.Attributes; @@ -71,15 +73,9 @@ import org.junit.runners.Parameterized.Parameters; @RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests public class SftpVersionsTest extends AbstractSftpClientTestSupport { private static final List<Integer> VERSIONS = - Collections.unmodifiableList(new ArrayList<Integer>() { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - for (int version = SftpSubsystem.LOWER_SFTP_IMPL; version <= SftpSubsystem.HIGHER_SFTP_IMPL; version++) { - add(Integer.valueOf(version)); - } - } - }); + Collections.unmodifiableList( + IntStream.rangeClosed(SftpSubsystem.LOWER_SFTP_IMPL, SftpSubsystem.HIGHER_SFTP_IMPL) + .boxed().collect(Collectors.toList())); private final int testVersion; @@ -308,15 +304,11 @@ public class SftpVersionsTest extends AbstractSftpClientTestSupport { @Test // see SSHD-575 public void testSftpExtensionsEncodeDecode() throws Exception { final Class<?> anchor = getClass(); - final Map<String, String> expExtensions = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - put("class", anchor.getSimpleName()); - put("package", anchor.getPackage().getName()); - put("method", getCurrentTestName()); - } - }; + final Map<String, String> expExtensions = GenericUtils.<String, String>mapBuilder() + .put("class", anchor.getSimpleName()) + .put("package", anchor.getPackage().getName()) + .put("method", getCurrentTestName()) + .build(); final AtomicInteger numInvocations = new AtomicInteger(0); SftpSubsystemFactory factory = new SftpSubsystemFactory() { @@ -439,7 +431,7 @@ public class SftpVersionsTest extends AbstractSftpClientTestSupport { assertNull("Unexpected indicator value at iteration #" + index, value); } else { assertNotNull("No indicator returned at iteration #" + index, value); - if (value.booleanValue()) { + if (value) { break; } } @@ -453,7 +445,7 @@ public class SftpVersionsTest extends AbstractSftpClientTestSupport { } else { assertNotNull("No end-of-list indication received at end of entries", value); assertNotNull("No last received entries", entries); - assertTrue("Bad end-of-list value", value.booleanValue()); + assertTrue("Bad end-of-list value", value); } } }
