http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 9ddeb30..d337244 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 @@ -28,7 +28,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; -import java.util.LinkedList; import java.util.List; import java.util.concurrent.TimeUnit; @@ -68,40 +67,39 @@ public class AbstractCheckFileExtensionTest extends AbstractSftpClientTestSuppor private static final Collection<Integer> DATA_SIZES = Collections.unmodifiableList( Arrays.asList( - Integer.valueOf(Byte.MAX_VALUE), - Integer.valueOf(SftpConstants.MIN_CHKFILE_BLOCKSIZE), - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), - Integer.valueOf(Byte.SIZE * IoUtils.DEFAULT_COPY_SIZE) + (int) Byte.MAX_VALUE, + SftpConstants.MIN_CHKFILE_BLOCKSIZE, + IoUtils.DEFAULT_COPY_SIZE, + Byte.SIZE * IoUtils.DEFAULT_COPY_SIZE )); private static final Collection<Integer> BLOCK_SIZES = Collections.unmodifiableList( Arrays.asList( - Integer.valueOf(0), - Integer.valueOf(SftpConstants.MIN_CHKFILE_BLOCKSIZE), - Integer.valueOf(1024), - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE) + 0, + SftpConstants.MIN_CHKFILE_BLOCKSIZE, + 1024, + IoUtils.DEFAULT_COPY_SIZE )); - @SuppressWarnings("synthetic-access") - private static final Collection<Object[]> PARAMETERS = - Collections.unmodifiableCollection(new LinkedList<Object[]>() { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - for (DigestFactory factory : BuiltinDigests.VALUES) { - if (!factory.isSupported()) { - System.out.println("Skip unsupported digest=" + factory.getAlgorithm()); - continue; - } - - String algorithm = factory.getName(); - for (Number dataSize : DATA_SIZES) { - for (Number blockSize : BLOCK_SIZES) { - add(new Object[]{algorithm, dataSize, blockSize}); - } - } - } + private static final Collection<Object[]> PARAMETERS; + + static { + Collection<Object[]> list = new ArrayList<>(); + for (DigestFactory factory : BuiltinDigests.VALUES) { + if (!factory.isSupported()) { + System.out.println("Skip unsupported digest=" + factory.getAlgorithm()); + continue; + } + + String algorithm = factory.getName(); + for (Number dataSize : DATA_SIZES) { + for (Number blockSize : BLOCK_SIZES) { + list.add(new Object[]{algorithm, dataSize, blockSize}); } - }); + } + } + PARAMETERS = list; + } + private final String algorithm; private final int dataSize;
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 6c63b6f..12ebf4b 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 @@ -63,10 +63,10 @@ public class AbstractMD5HashExtensionTest extends AbstractSftpClientTestSupport private static final List<Integer> DATA_SIZES = Collections.unmodifiableList( Arrays.asList( - Integer.valueOf(Byte.MAX_VALUE), - Integer.valueOf(SftpConstants.MD5_QUICK_HASH_SIZE), - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), - Integer.valueOf(Byte.SIZE * IoUtils.DEFAULT_COPY_SIZE) + (int) Byte.MAX_VALUE, + SftpConstants.MD5_QUICK_HASH_SIZE, + IoUtils.DEFAULT_COPY_SIZE, + Byte.SIZE * IoUtils.DEFAULT_COPY_SIZE )); private final int size; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java b/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java index 9c4bcd6..6f73123 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/AttributeStoreTest.java @@ -30,8 +30,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> @@ -46,67 +44,58 @@ public class AttributeStoreTest extends BaseTestSupport { @Test public void testResolveFactoryManagerAttribute() { - assertNull("Unexpected null factory value", AttributeStore.Utils.resolveAttribute((FactoryManager) null, KEY)); + assertNull("Unexpected null factory value", AttributeStore.resolveAttribute((FactoryManager) null, KEY)); FactoryManager manager = Mockito.mock(FactoryManager.class); String expected = setAttributeValue(manager, getCurrentTestName()); - assertSame("Mismatched resolved value", expected, AttributeStore.Utils.resolveAttribute(manager, KEY)); + assertSame("Mismatched resolved value", expected, AttributeStore.resolveAttribute(manager, KEY)); } @Test public void testResolveSessionAttribute() { - assertNull("Unexpected null session value", AttributeStore.Utils.resolveAttribute((Session) null, KEY)); + assertNull("Unexpected null session value", AttributeStore.resolveAttribute((Session) null, KEY)); Session session = Mockito.mock(Session.class); final AtomicInteger managerCount = new AtomicInteger(0); - Mockito.when(session.getFactoryManager()).then(new Answer<FactoryManager>() { - @Override - public FactoryManager answer(InvocationOnMock invocation) throws Throwable { - managerCount.incrementAndGet(); - return null; - } + Mockito.when(session.getFactoryManager()).then(invocation -> { + managerCount.incrementAndGet(); + return null; }); setAttributeValue(session, null); - assertNull("Unexpected success for empty attribute", AttributeStore.Utils.resolveAttribute(session, KEY)); + assertNull("Unexpected success for empty attribute", AttributeStore.resolveAttribute(session, KEY)); assertEquals("Factory manager not requested", 1, managerCount.getAndSet(0)); String expected = setAttributeValue(session, getCurrentTestName()); - assertSame("Mismatched attribute value", expected, AttributeStore.Utils.resolveAttribute(session, KEY)); + assertSame("Mismatched attribute value", expected, AttributeStore.resolveAttribute(session, KEY)); assertEquals("Unexpected manager request", 0, managerCount.get()); } @Test public void testResolveChannelAttribute() { - assertNull("Unexpected null channek value", AttributeStore.Utils.resolveAttribute((Channel) null, KEY)); + assertNull("Unexpected null channek value", AttributeStore.resolveAttribute((Channel) null, KEY)); final Session session = Mockito.mock(Session.class); final AtomicInteger managerCount = new AtomicInteger(0); - Mockito.when(session.getFactoryManager()).thenAnswer(new Answer<FactoryManager>() { - @Override - public FactoryManager answer(InvocationOnMock invocation) throws Throwable { - managerCount.incrementAndGet(); - return null; - } + Mockito.when(session.getFactoryManager()).thenAnswer(invocation -> { + managerCount.incrementAndGet(); + return null; }); setAttributeValue(session, null); Channel channel = Mockito.mock(Channel.class); final AtomicInteger sessionCount = new AtomicInteger(0); - Mockito.when(channel.getSession()).thenAnswer(new Answer<Session>() { - @Override - public Session answer(InvocationOnMock invocation) throws Throwable { - sessionCount.incrementAndGet(); - return session; - } + Mockito.when(channel.getSession()).thenAnswer(invocation -> { + sessionCount.incrementAndGet(); + return session; }); setAttributeValue(channel, null); - assertNull("Unexpected success for empty attribute", AttributeStore.Utils.resolveAttribute(channel, KEY)); + assertNull("Unexpected success for empty attribute", AttributeStore.resolveAttribute(channel, KEY)); assertEquals("Session not requested", 1, sessionCount.getAndSet(0)); assertEquals("Factory manager not requested", 1, managerCount.getAndSet(0)); String expected = setAttributeValue(channel, getCurrentTestName()); - assertSame("Mismatched attribute value", expected, AttributeStore.Utils.resolveAttribute(channel, KEY)); + assertSame("Mismatched attribute value", expected, AttributeStore.resolveAttribute(channel, KEY)); assertEquals("Unexpected session request", 0, sessionCount.get()); assertEquals("Unexpected manager request", 0, managerCount.get()); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/SshBuilderTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/SshBuilderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/SshBuilderTest.java index c0b7af2..fdbbe4c 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/SshBuilderTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/SshBuilderTest.java @@ -114,7 +114,7 @@ public class SshBuilderTest extends BaseTestSupport { } // make sure order is according to the default preference list - List<String> cipherNames = NamedResource.Utils.getNameList(ciphers); + List<String> cipherNames = NamedResource.getNameList(ciphers); int nameIndex = 0; for (BuiltinCiphers c : BaseBuilder.DEFAULT_CIPHERS_PREFERENCE) { if ((!c.isSupported()) && (!ignoreUnsupported)) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 1393de9..12b15fd 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 @@ -19,10 +19,8 @@ package org.apache.sshd.common.auth; import java.io.IOException; -import java.net.SocketAddress; import java.security.KeyPair; import java.security.PublicKey; -import java.security.cert.X509Certificate; import java.security.spec.InvalidKeySpecException; import java.util.Arrays; import java.util.Collection; @@ -31,7 +29,6 @@ import java.util.EnumSet; import java.util.List; import java.util.Locale; import java.util.Map; -import java.util.TreeMap; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; @@ -40,7 +37,6 @@ import org.apache.sshd.client.auth.hostbased.HostKeyIdentityProvider; import org.apache.sshd.client.auth.keyboard.UserInteraction; import org.apache.sshd.client.auth.password.PasswordIdentityProvider; import org.apache.sshd.client.future.AuthFuture; -import org.apache.sshd.client.keyverifier.ServerKeyVerifier; import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.PropertyResolverUtils; @@ -61,7 +57,6 @@ import org.apache.sshd.common.util.net.SshdSocketAddress; import org.apache.sshd.server.ServerAuthenticationManager; import org.apache.sshd.server.ServerFactoryManager; import org.apache.sshd.server.SshServer; -import org.apache.sshd.server.auth.hostbased.HostBasedAuthenticator; import org.apache.sshd.server.auth.keyboard.DefaultKeyboardInteractiveAuthenticator; import org.apache.sshd.server.auth.keyboard.InteractiveChallenge; import org.apache.sshd.server.auth.keyboard.KeyboardInteractiveAuthenticator; @@ -158,16 +153,12 @@ public class AuthenticationTest extends BaseTestSupport { public void testChangePassword() throws Exception { final PasswordAuthenticator delegate = sshd.getPasswordAuthenticator(); final AtomicInteger attemptsCount = new AtomicInteger(0); - sshd.setPasswordAuthenticator(new PasswordAuthenticator() { - @Override - public boolean authenticate(String username, String password, ServerSession session) - throws PasswordChangeRequiredException { - if (attemptsCount.incrementAndGet() == 1) { - throw new PasswordChangeRequiredException(attemptsCount.toString(), getCurrentTestName(), ServerAuthenticationManager.DEFAULT_WELCOME_BANNER_LANGUAGE); - } - - return delegate.authenticate(username, password, session); + sshd.setPasswordAuthenticator((username, password, session) -> { + if (attemptsCount.incrementAndGet() == 1) { + throw new PasswordChangeRequiredException(attemptsCount.toString(), getCurrentTestName(), ServerAuthenticationManager.DEFAULT_WELCOME_BANNER_LANGUAGE); } + + return delegate.authenticate(username, password, session); }); final AtomicInteger changesCount = new AtomicInteger(0); @@ -383,15 +374,11 @@ 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) { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - put("class", anchor.getSimpleName()); - put("package", anchor.getPackage().getName()); - put("test", getCurrentTestName()); - } - }; + final Map<String, String> rspMap = GenericUtils.<String, String>mapBuilder(String.CASE_INSENSITIVE_ORDER) + .put("class", anchor.getSimpleName()) + .put("package", anchor.getPackage().getName()) + .put("test", getCurrentTestName()) + .build(); for (String prompt : rspMap.keySet()) { challenge.addPrompt(prompt, (GenericUtils.size(challenge.getPrompts()) & 0x1) != 0); } @@ -478,16 +465,12 @@ public class AuthenticationTest extends BaseTestSupport { public void testAuthPasswordChangeRequest() throws Exception { final PasswordAuthenticator delegate = ValidateUtils.checkNotNull(sshd.getPasswordAuthenticator(), "No password authenticator"); final AtomicInteger attemptsCount = new AtomicInteger(0); - sshd.setPasswordAuthenticator(new PasswordAuthenticator() { - @Override - public boolean authenticate(String username, String password, ServerSession session) - throws PasswordChangeRequiredException { - if (attemptsCount.incrementAndGet() == 1) { - throw new PasswordChangeRequiredException(attemptsCount.toString(), getCurrentTestName(), ServerAuthenticationManager.DEFAULT_WELCOME_BANNER_LANGUAGE); - } - - return delegate.authenticate(username, password, session); + sshd.setPasswordAuthenticator((username, password, session) -> { + if (attemptsCount.incrementAndGet() == 1) { + throw new PasswordChangeRequiredException(attemptsCount.toString(), getCurrentTestName(), ServerAuthenticationManager.DEFAULT_WELCOME_BANNER_LANGUAGE); } + + return delegate.authenticate(username, password, session); }); PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.AUTH_METHODS, UserAuthPasswordFactory.NAME); @@ -564,13 +547,10 @@ public class AuthenticationTest extends BaseTestSupport { try (SshClient client = setupTestClient()) { final List<String> passwords = Collections.singletonList(getCurrentTestName()); final AtomicInteger loadCount = new AtomicInteger(0); - PasswordIdentityProvider provider = new PasswordIdentityProvider() { - @Override - public Iterable<String> loadPasswords() { - loadCount.incrementAndGet(); - outputDebugMessage("loadPasswords - count=%s", loadCount); - return passwords; - } + PasswordIdentityProvider provider = () -> { + loadCount.incrementAndGet(); + outputDebugMessage("loadPasswords - count=%s", loadCount); + return passwords; }; client.setPasswordIdentityProvider(provider); @@ -587,7 +567,7 @@ public class AuthenticationTest extends BaseTestSupport { @Test // see SSHD-618 public void testPublicKeyAuthDifferentThanKex() throws Exception { - final KeyPairProvider serverKeys = KeyPairProvider.Utils.wrap( + final KeyPairProvider serverKeys = KeyPairProvider.wrap( Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 1024), Utils.generateKeyPair(KeyUtils.DSS_ALGORITHM, 512), Utils.generateKeyPair(KeyUtils.EC_ALGORITHM, 256)); @@ -596,32 +576,26 @@ public class AuthenticationTest extends BaseTestSupport { sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE); final KeyPair clientIdentity = Utils.generateKeyPair(KeyUtils.EC_ALGORITHM, 256); - sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() { - @Override - public boolean authenticate(String username, PublicKey key, ServerSession session) { - String keyType = KeyUtils.getKeyType(key); - String expType = KeyUtils.getKeyType(clientIdentity); - assertEquals("Mismatched client key types", expType, keyType); - assertKeyEquals("Mismatched authentication public keys", clientIdentity.getPublic(), key); - return true; - } + sshd.setPublickeyAuthenticator((username, key, session) -> { + String keyType = KeyUtils.getKeyType(key); + String expType = KeyUtils.getKeyType(clientIdentity); + assertEquals("Mismatched client key types", expType, keyType); + assertKeyEquals("Mismatched authentication public keys", clientIdentity.getPublic(), key); + return true; }); try (SshClient client = setupTestClient()) { // force server to use only the RSA key final NamedFactory<Signature> kexSignature = BuiltinSignatures.rsa; client.setSignatureFactories(Collections.singletonList(kexSignature)); - client.setServerKeyVerifier(new ServerKeyVerifier() { - @Override - public boolean verifyServerKey(ClientSession sshClientSession, SocketAddress remoteAddress, PublicKey serverKey) { - String keyType = KeyUtils.getKeyType(serverKey); - String expType = kexSignature.getName(); - assertEquals("Mismatched server key type", expType, keyType); + client.setServerKeyVerifier((sshClientSession, remoteAddress, serverKey) -> { + String keyType = KeyUtils.getKeyType(serverKey); + String expType = kexSignature.getName(); + assertEquals("Mismatched server key type", expType, keyType); - KeyPair kp = ValidateUtils.checkNotNull(serverKeys.loadKey(keyType), "No server key for type=%s", keyType); - assertKeyEquals("Mismatched server public keys", kp.getPublic(), serverKey); - return true; - } + KeyPair kp = ValidateUtils.checkNotNull(serverKeys.loadKey(keyType), "No server key for type=%s", keyType); + assertKeyEquals("Mismatched server public keys", kp.getPublic(), serverKey); + return true; }); // allow only EC keys for public key authentication @@ -702,15 +676,11 @@ public class AuthenticationTest extends BaseTestSupport { final String hostClientName = SshdSocketAddress.toAddressString(SshdSocketAddress.getFirstExternalNetwork4Address()); final KeyPair hostClientKey = Utils.generateKeyPair(KeyUtils.RSA_ALGORITHM, 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 hostClienUser.equals(clientUsername) - && hostClientName.equals(clientHostName) - && KeyUtils.compareKeys(hostClientKey.getPublic(), clientHostKey); - } + sshd.setHostBasedAuthenticator((session, username, clientHostKey, clientHostName, clientUsername, certificates) -> { + invocationCount.incrementAndGet(); + return hostClienUser.equals(clientUsername) + && hostClientName.equals(clientHostName) + && KeyUtils.compareKeys(hostClientKey.getPublic(), clientHostKey); }); sshd.setPasswordAuthenticator(RejectAllPasswordAuthenticator.INSTANCE); sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE); @@ -724,7 +694,7 @@ public class AuthenticationTest extends BaseTestSupport { new org.apache.sshd.client.auth.hostbased.UserAuthHostBasedFactory(); // TODO factory.setClientHostname(CLIENT_HOSTNAME); factory.setClientUsername(hostClienUser); - factory.setClientHostKeys(HostKeyIdentityProvider.Utils.wrap(hostClientKey)); + factory.setClientHostKeys(HostKeyIdentityProvider.wrap(hostClientKey)); client.setUserAuthFactories(Collections.singletonList(factory)); client.start(); @@ -742,29 +712,22 @@ public class AuthenticationTest extends BaseTestSupport { final Error thrown = new OutOfMemoryError(getCurrentTestName()); final PasswordAuthenticator authPassword = sshd.getPasswordAuthenticator(); final AtomicInteger passCounter = new AtomicInteger(0); - sshd.setPasswordAuthenticator(new PasswordAuthenticator() { - @Override - public boolean authenticate(String username, String password, ServerSession session) - throws PasswordChangeRequiredException { - int count = passCounter.incrementAndGet(); - if (count == 1) { - throw thrown; - } - return authPassword.authenticate(username, password, session); + sshd.setPasswordAuthenticator((username, password, session) -> { + int count = passCounter.incrementAndGet(); + if (count == 1) { + throw thrown; } + return authPassword.authenticate(username, password, session); }); final PublickeyAuthenticator authPubkey = sshd.getPublickeyAuthenticator(); final AtomicInteger pubkeyCounter = new AtomicInteger(0); - sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() { - @Override - public boolean authenticate(String username, PublicKey key, ServerSession session) { - int count = pubkeyCounter.incrementAndGet(); - if (count == 1) { - throw thrown; - } - return authPubkey.authenticate(username, key, session); + sshd.setPublickeyAuthenticator((username, key, session) -> { + int count = pubkeyCounter.incrementAndGet(); + if (count == 1) { + throw thrown; } + return authPubkey.authenticate(username, key, session); }); sshd.setKeyboardInteractiveAuthenticator(KeyboardInteractiveAuthenticator.NONE); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java b/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java index 96039bd..dc959e7 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/auth/SinglePublicKeyAuthTest.java @@ -31,13 +31,13 @@ import org.apache.sshd.client.session.ClientSession; import org.apache.sshd.common.PropertyResolverUtils; import org.apache.sshd.common.config.keys.KeyUtils; import org.apache.sshd.common.keyprovider.KeyPairProvider; +import org.apache.sshd.common.session.Session; import org.apache.sshd.server.ServerAuthenticationManager; import org.apache.sshd.server.SshServer; import org.apache.sshd.server.auth.pubkey.CachingPublicKeyAuthenticator; import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator; import org.apache.sshd.server.auth.pubkey.UserAuthPublicKeyFactory; import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider; -import org.apache.sshd.server.session.ServerSession; import org.apache.sshd.util.test.BaseTestSupport; import org.junit.After; import org.junit.Before; @@ -69,13 +69,7 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport { public void setUp() throws Exception { sshd = setupTestServer(); PropertyResolverUtils.updateProperty(sshd, ServerAuthenticationManager.AUTH_METHODS, UserAuthPublicKeyFactory.NAME); - sshd.setPublickeyAuthenticator(new PublickeyAuthenticator() { - @SuppressWarnings("synthetic-access") - @Override - public boolean authenticate(String username, PublicKey key, ServerSession session) { - return delegate.authenticate(username, key, session); - } - }); + sshd.setPublickeyAuthenticator((username, key, session) -> delegate.authenticate(username, key, session)); sshd.start(); port = sshd.getPort(); } @@ -89,16 +83,12 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport { @Test public void testPublicKeyAuthWithCache() throws Exception { - final ConcurrentHashMap<String, AtomicInteger> count = new ConcurrentHashMap<String, AtomicInteger>(); - TestCachingPublicKeyAuthenticator auth = new TestCachingPublicKeyAuthenticator(new PublickeyAuthenticator() { - @SuppressWarnings("synthetic-access") - @Override - public boolean authenticate(String username, PublicKey key, ServerSession session) { - String fp = KeyUtils.getFingerPrint(key); - count.putIfAbsent(fp, new AtomicInteger()); - count.get(fp).incrementAndGet(); - return key.equals(pairRsa.getPublic()); - } + final ConcurrentHashMap<String, AtomicInteger> count = new ConcurrentHashMap<>(); + TestCachingPublicKeyAuthenticator auth = new TestCachingPublicKeyAuthenticator((username, key, session) -> { + String fp = KeyUtils.getFingerPrint(key); + count.putIfAbsent(fp, new AtomicInteger()); + count.get(fp).incrementAndGet(); + return key.equals(pairRsa.getPublic()); }); delegate = auth; @@ -129,16 +119,12 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport { @Test public void testPublicKeyAuthWithoutCache() throws Exception { - final ConcurrentHashMap<String, AtomicInteger> count = new ConcurrentHashMap<String, AtomicInteger>(); - delegate = new PublickeyAuthenticator() { - @SuppressWarnings("synthetic-access") - @Override - public boolean authenticate(String username, PublicKey key, ServerSession session) { - String fp = KeyUtils.getFingerPrint(key); - count.putIfAbsent(fp, new AtomicInteger()); - count.get(fp).incrementAndGet(); - return key.equals(pairRsa.getPublic()); - } + final ConcurrentHashMap<String, AtomicInteger> count = new ConcurrentHashMap<>(); + delegate = (username, key, session) -> { + String fp = KeyUtils.getFingerPrint(key); + count.putIfAbsent(fp, new AtomicInteger()); + count.get(fp).incrementAndGet(); + return key.equals(pairRsa.getPublic()); }; try (SshClient client = setupTestClient()) { @@ -174,7 +160,7 @@ public class SinglePublicKeyAuthTest extends BaseTestSupport { super(authenticator); } - public Map<ServerSession, Map<PublicKey, Boolean>> getCache() { + public Map<Session, Map<PublicKey, Boolean>> getCache() { return cache; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java index 6e2cae7..e8d3df8 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedOutputStreamTest.java @@ -30,8 +30,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> @@ -46,23 +44,17 @@ public class ChannelPipedOutputStreamTest extends BaseTestSupport { public void testNioChannelImplementation() throws IOException { ChannelPipedSink sink = Mockito.mock(ChannelPipedSink.class); final AtomicBoolean eofCalled = new AtomicBoolean(false); - Mockito.doAnswer(new Answer<Void>() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - assertFalse("Multiple EOF calls", eofCalled.getAndSet(true)); - return null; - } + Mockito.doAnswer(invocation -> { + assertFalse("Multiple EOF calls", eofCalled.getAndSet(true)); + return null; }).when(sink).eof(); final AtomicInteger receiveCount = new AtomicInteger(0); - Mockito.doAnswer(new Answer<Void>() { - @Override - public Void answer(InvocationOnMock invocation) throws Throwable { - Number len = invocation.getArgumentAt(2, Number.class); - receiveCount.addAndGet(len.intValue()); - return null; - } + Mockito.doAnswer(invocation -> { + Number len = invocation.getArgumentAt(2, Number.class); + receiveCount.addAndGet(len.intValue()); + return null; }).when(sink).receive(Matchers.any(byte[].class), Matchers.anyInt(), Matchers.anyInt()); try (ChannelPipedOutputStream stream = new ChannelPipedOutputStream(sink)) { assertTrue("Stream not marked as initially open", stream.isOpen()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/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 e19c0bb..5620fae 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 @@ -342,9 +342,7 @@ public class WindowTest extends BaseTestSupport { @Override public void destroy() { - if (LATCH != null) { - LATCH.countDown(); - } + LATCH.countDown(); super.destroy(); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java index 7d74d81..cbb80ca 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BuiltinCiphersTest.java @@ -170,7 +170,7 @@ public class BuiltinCiphersTest extends BaseTestSupport { private static <M extends FactoryManager> M testSupportedCiphersConfiguration(M manager) { Collection<? extends NamedResource> factories = manager.getCipherFactories(); - List<String> names = NamedResource.Utils.getNameList(factories); + List<String> names = NamedResource.getNameList(factories); for (BuiltinCiphers c : BuiltinCiphers.VALUES) { if (BuiltinCiphers.none.equals(c)) { continue; // not always included by default + it is a dummy cipher @@ -200,14 +200,14 @@ public class BuiltinCiphersTest extends BaseTestSupport { @Test public void testParseCiphersList() { - List<String> builtin = NamedResource.Utils.getNameList(BuiltinCiphers.VALUES); + List<String> builtin = NamedResource.getNameList(BuiltinCiphers.VALUES); List<String> unknown = Arrays.asList(getClass().getPackage().getName(), getClass().getSimpleName(), getCurrentTestName()); Random rnd = new Random(); for (int index = 0; index < (builtin.size() + unknown.size()); index++) { Collections.shuffle(builtin, rnd); Collections.shuffle(unknown, rnd); - List<String> weavedList = new ArrayList<String>(builtin.size() + unknown.size()); + List<String> weavedList = new ArrayList<>(builtin.size() + unknown.size()); for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size());) { boolean useBuiltin = false; if (bIndex < builtin.size()) { @@ -225,7 +225,7 @@ public class BuiltinCiphersTest extends BaseTestSupport { String fullList = GenericUtils.join(weavedList, ','); ParseResult result = BuiltinCiphers.parseCiphersList(fullList); - List<String> parsed = NamedResource.Utils.getNameList(result.getParsedFactories()); + List<String> parsed = NamedResource.getNameList(result.getParsedFactories()); List<String> missing = result.getUnsupportedFactories(); // makes sure not only that the contents are the same but also the order http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java index c5a76a3..c4b5701 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/CipherTest.java @@ -21,14 +21,14 @@ package org.apache.sshd.common.cipher; import java.io.InputStream; 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.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; import com.jcraft.jsch.JSch; - import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.NamedResource; import org.apache.sshd.common.channel.Channel; @@ -57,7 +57,7 @@ import org.junit.runners.Parameterized.Parameters; @FixMethodOrder(MethodSorters.NAME_ASCENDING) @RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests public class CipherTest extends BaseTestSupport { - private static final Integer NUM_LOADTEST_ROUNDS = Integer.valueOf(100000); + private static final Integer NUM_LOADTEST_ROUNDS = 100000; /* * NOTE !!! order is important since we build from it the C2S/S2C ciphers proposal @@ -75,19 +75,12 @@ public class CipherTest extends BaseTestSupport { @SuppressWarnings("synthetic-access") private static final List<NamedResource> TEST_CIPHERS = - Collections.unmodifiableList(new ArrayList<NamedResource>(PARAMETERS.size()) { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - for (Object[] params : PARAMETERS) { - add((NamedResource) params[0]); - } - - add(BuiltinCiphers.none); - } - }); + Collections.unmodifiableList( + Stream.concat(PARAMETERS.stream().map(params -> (NamedResource) params[0]), + Stream.of(BuiltinCiphers.none)) + .collect(Collectors.toList())); - private static final String CRYPT_NAMES = NamedResource.Utils.getNames(TEST_CIPHERS); + private static final String CRYPT_NAMES = NamedResource.getNames(TEST_CIPHERS); private static SshServer sshd; private static int port; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/compression/BuiltinCompressionsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/compression/BuiltinCompressionsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/compression/BuiltinCompressionsTest.java index a0a2828..a7e5247 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/compression/BuiltinCompressionsTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/compression/BuiltinCompressionsTest.java @@ -76,14 +76,14 @@ public class BuiltinCompressionsTest extends BaseTestSupport { @Test public void testParseCompressionsList() { - List<String> builtin = NamedResource.Utils.getNameList(BuiltinCompressions.VALUES); + List<String> builtin = NamedResource.getNameList(BuiltinCompressions.VALUES); List<String> unknown = Arrays.asList(getClass().getPackage().getName(), getClass().getSimpleName(), getCurrentTestName()); Random rnd = new Random(); for (int index = 0; index < (builtin.size() + unknown.size()); index++) { Collections.shuffle(builtin, rnd); Collections.shuffle(unknown, rnd); - List<String> weavedList = new ArrayList<String>(builtin.size() + unknown.size()); + List<String> weavedList = new ArrayList<>(builtin.size() + unknown.size()); for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size());) { boolean useBuiltin = false; if (bIndex < builtin.size()) { @@ -101,7 +101,7 @@ public class BuiltinCompressionsTest extends BaseTestSupport { String fullList = GenericUtils.join(weavedList, ','); ParseResult result = BuiltinCompressions.parseCompressionsList(fullList); - List<String> parsed = NamedResource.Utils.getNameList(result.getParsedFactories()); + List<String> parsed = NamedResource.getNameList(result.getParsedFactories()); List<String> missing = result.getUnsupportedFactories(); // makes sure not only that the contents are the same but also the order http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java b/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java index b2dec83..79a15e6 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/compression/CompressionTest.java @@ -21,14 +21,12 @@ package org.apache.sshd.common.compression; import java.io.InputStream; import java.io.OutputStream; import java.nio.charset.StandardCharsets; -import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.EnumSet; import java.util.List; import com.jcraft.jsch.JSch; - import org.apache.sshd.common.channel.Channel; import org.apache.sshd.common.kex.KexProposalOption; import org.apache.sshd.common.mac.MacTest; @@ -112,7 +110,7 @@ public class CompressionTest extends BaseTestSupport { @Before public void setUp() throws Exception { - sshd.setCompressionFactories(Arrays.asList(factory)); + sshd.setCompressionFactories(Collections.singletonList(factory)); sshd.addSessionListener(listener); String name = factory.getName(); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java index dddf907..e29153b 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/config/SshConfigFileReaderTest.java @@ -146,7 +146,7 @@ public class SshConfigFileReaderTest extends BaseTestSupport { getCurrentTestName(), false, true); - fail("Unexpected success: " + NamedResource.Utils.getNames(manager.getCipherFactories())); + fail("Unexpected success: " + NamedResource.getNames(manager.getCipherFactories())); } @Test(expected = IllegalArgumentException.class) @@ -161,7 +161,7 @@ public class SshConfigFileReaderTest extends BaseTestSupport { getCurrentTestName(), false, true); - fail("Unexpected success: " + NamedResource.Utils.getNames(manager.getSignatureFactories())); + fail("Unexpected success: " + NamedResource.getNames(manager.getSignatureFactories())); } @Test(expected = IllegalArgumentException.class) @@ -176,7 +176,7 @@ public class SshConfigFileReaderTest extends BaseTestSupport { getCurrentTestName(), false, true); - fail("Unexpected success: " + NamedResource.Utils.getNames(manager.getMacFactories())); + fail("Unexpected success: " + NamedResource.getNames(manager.getMacFactories())); } @Test @@ -285,7 +285,7 @@ public class SshConfigFileReaderTest extends BaseTestSupport { } private static <R extends NamedResource> Properties initNamedResourceProperties(String key, Collection<? extends R> values) { - return initProperties(key, NamedResource.Utils.getNames(values)); + return initProperties(key, NamedResource.getNames(values)); } private static Properties initProperties(String key, String value) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/config/TimeValueConfigTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/TimeValueConfigTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/TimeValueConfigTest.java index 8856415..fbb09e7 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/TimeValueConfigTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/config/TimeValueConfigTest.java @@ -38,11 +38,11 @@ public class TimeValueConfigTest extends BaseTestSupport { @Test public void testDurationOf() { Object[] values = { - "600", Long.valueOf(TimeUnit.SECONDS.toMillis(600L)), - "10m", Long.valueOf(TimeUnit.MINUTES.toMillis(10L)), - "1h30m", Long.valueOf(TimeUnit.MINUTES.toMillis(90L)), - "2d", Long.valueOf(TimeUnit.DAYS.toMillis(2L)), - "3w", Long.valueOf(TimeUnit.DAYS.toMillis(3L * 7L)) + "600", TimeUnit.SECONDS.toMillis(600L), + "10m", TimeUnit.MINUTES.toMillis(10L), + "1h30m", TimeUnit.MINUTES.toMillis(90L), + "2d", TimeUnit.DAYS.toMillis(2L), + "3w", TimeUnit.DAYS.toMillis(3L * 7L) }; for (int index = 0; index < values.length; index += 2) { String s = (String) values[index]; http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeysTestSupport.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeysTestSupport.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeysTestSupport.java index 5a7e2b4..2488b14 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeysTestSupport.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/AuthorizedKeysTestSupport.java @@ -96,7 +96,7 @@ public abstract class AuthorizedKeysTestSupport extends BaseTestSupport { } public static List<String> loadSupportedKeys(BufferedReader rdr) throws IOException { - List<String> keyLines = new ArrayList<String>(); + List<String> keyLines = new ArrayList<>(); boolean eccSupported = SecurityUtils.hasEcc(); for (String l = rdr.readLine(); l != null; l = rdr.readLine()) { l = GenericUtils.trimToEmpty(l); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyRandomArtTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyRandomArtTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyRandomArtTest.java index a0c472c..c7083cb 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyRandomArtTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyRandomArtTest.java @@ -26,7 +26,6 @@ import java.util.LinkedList; import java.util.List; import org.apache.sshd.common.cipher.ECCurves; -import org.apache.sshd.common.keyprovider.KeyIdentityProvider; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.util.test.BaseTestSupport; import org.apache.sshd.util.test.Utils; @@ -74,13 +73,7 @@ public class KeyRandomArtTest extends BaseTestSupport { @AfterClass public static void dumpAllArts() throws Exception { - KeyRandomArt.combine(System.out, ' ', new KeyIdentityProvider() { - @Override - @SuppressWarnings("synthetic-access") - public Iterable<KeyPair> loadKeys() { - return KEYS; - } - }); + KeyRandomArt.combine(System.out, ' ', () -> KEYS); } @Test http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java index 82b61b6..a100aa9 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintCaseSensitivityTest.java @@ -85,6 +85,6 @@ public class KeyUtilsFingerprintCaseSensitivityTest extends BaseTestSupport { @Test public void testCase() throws Exception { - assertEquals("Check failed", new Pair<Boolean, String>(true, expected), KeyUtils.checkFingerPrint(test, key)); + assertEquals("Check failed", new Pair<>(true, expected), KeyUtils.checkFingerPrint(test, key)); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java index 1de26f4..b360cb7 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsFingerprintGenerationTest.java @@ -140,12 +140,12 @@ public class KeyUtilsFingerprintGenerationTest extends BaseTestSupport { ); assertEquals( String.format("Fingerprint check failed for digest %s", name), - new Pair<Boolean, String>(true, expected), + new Pair<>(true, expected), KeyUtils.checkFingerPrint(expected, digestFactory, key) ); assertEquals( String.format("Fingerprint check succeeded for invalid digest %s", name), - new Pair<Boolean, String>(false, expected), + new Pair<>(false, expected), KeyUtils.checkFingerPrint(expected + "A", digestFactory, key) ); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java index 355358d..4b9b465 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/config/keys/KeyUtilsTest.java @@ -63,7 +63,7 @@ public class KeyUtilsTest extends BaseTestSupport { public void testGenerateRSAKeyPairs() throws GeneralSecurityException { GeneralSecurityException err = null; for (Integer size : RSA_SIZES) { - int keySize = size.intValue(); + int keySize = size; try { KeyPair kp = generateKeyPair(KeyPairProvider.SSH_RSA, keySize); testKeyPairCloning(KeyPairProvider.SSH_RSA, keySize, kp); @@ -81,7 +81,7 @@ public class KeyUtilsTest extends BaseTestSupport { public void testGenerateDSSKeyPairs() throws GeneralSecurityException { GeneralSecurityException err = null; for (Integer size : DSS_SIZES) { - int keySize = size.intValue(); + int keySize = size; try { KeyPair kp = generateKeyPair(KeyPairProvider.SSH_DSS, keySize); testKeyPairCloning(KeyPairProvider.SSH_DSS, keySize, kp); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java index be95fcf..c342ea6 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/file/root/RootedFileSystemProviderTest.java @@ -304,13 +304,7 @@ public class RootedFileSystemProviderTest extends AssertableFile { } public static DirectoryStream<Path> readDirectory(Path dir) throws InvalidPathException, IOException { - DirectoryStream<Path> dirStream = fileSystem.provider().newDirectoryStream(dir, - new DirectoryStream.Filter<Path>() { - @Override - public boolean accept(Path entry) throws IOException { - return true; - } - }); + DirectoryStream<Path> dirStream = fileSystem.provider().newDirectoryStream(dir, entry -> true); return dirStream; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java index c788596..625f71d 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingLoadTest.java @@ -39,7 +39,6 @@ import java.util.concurrent.atomic.AtomicInteger; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; - import org.apache.commons.httpclient.HostConfiguration; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpVersion; @@ -237,7 +236,7 @@ public class PortForwardingLoadTest extends BaseTestSupport { } } } - log.info("Finished iteration {}", Integer.valueOf(i)); + log.info("Finished iteration {}", i); iterationsSignal.release(); } log.info("Done"); @@ -252,7 +251,7 @@ public class PortForwardingLoadTest extends BaseTestSupport { byte[] buf = new byte[8192]; byte[] bytes = payload.getBytes(StandardCharsets.UTF_8); for (int i = 0; i < numIterations; i++) { - log.info("Iteration {}", Integer.valueOf(i)); + log.info("Iteration {}", i); try (Socket s = new Socket(TEST_LOCALHOST, sinkPort); OutputStream sockOut = s.getOutputStream()) { @@ -463,8 +462,8 @@ public class PortForwardingLoadTest extends BaseTestSupport { } }; } - for (int i = 0; i < threads.length; i++) { - threads[i].start(); + for (Thread thread : threads) { + thread.start(); } latch.await(); for (Throwable t : errors) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java index cba1951..a0f28f5 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/forward/PortForwardingTest.java @@ -32,7 +32,6 @@ import java.util.Collection; import java.util.HashSet; import java.util.Map; import java.util.Set; -import java.util.TreeMap; import java.util.concurrent.BlockingQueue; import java.util.concurrent.LinkedBlockingDeque; import java.util.concurrent.TimeUnit; @@ -42,7 +41,6 @@ import java.util.concurrent.atomic.AtomicReference; import com.jcraft.jsch.JSch; import com.jcraft.jsch.JSchException; import com.jcraft.jsch.Session; - import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.service.IoAcceptor; import org.apache.mina.core.service.IoHandlerAdapter; @@ -166,14 +164,11 @@ public class PortForwardingTest extends BaseTestSupport { final TcpipForwarderFactory factory = ValidateUtils.checkNotNull(sshd.getTcpipForwarderFactory(), "No TcpipForwarderFactory"); sshd.setTcpipForwarderFactory(new TcpipForwarderFactory() { private final Class<?>[] interfaces = {TcpipForwarder.class}; - private final Map<String, String> method2req = new TreeMap<String, String>(String.CASE_INSENSITIVE_ORDER) { - private static final long serialVersionUID = 1L; // we're not serializing it... - - { - put("localPortForwardingRequested", TcpipForwardHandler.REQUEST); - put("localPortForwardingCancelled", CancelTcpipForwardHandler.REQUEST); - } - }; + private final Map<String, String> method2req = + GenericUtils.<String, String>mapBuilder(String.CASE_INSENSITIVE_ORDER) + .put("localPortForwardingRequested", TcpipForwardHandler.REQUEST) + .put("localPortForwardingCancelled", CancelTcpipForwardHandler.REQUEST) + .build(); @Override public TcpipForwarder create(ConnectionService service) { @@ -773,16 +768,16 @@ public class PortForwardingTest extends BaseTestSupport { return false; } // does it have 'org.apache.sshd.server.session.TcpipForwardSupport.close'? - for (int i = 0; i < stack.length; ++i) { - String clazzName = stack[i].getClassName(); - String methodName = stack[i].getMethodName(); + for (StackTraceElement aStack : stack) { + String clazzName = aStack.getClassName(); + String methodName = aStack.getMethodName(); // log.debug("Class: " + clazzName); // log.debug("Method: " + methodName); if (clazzName.equals("org.apache.sshd.server.session.TcpipForwardSupport") && (methodName.equals("close") || methodName.equals("sessionCreated"))) { log.warn(thread.getName() + " stuck at " + clazzName - + "." + methodName + ": " - + stack[i].getLineNumber()); + + "." + methodName + ": " + + aStack.getLineNumber()); return true; } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/future/DefaultSshFutureTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/future/DefaultSshFutureTest.java b/sshd-core/src/test/java/org/apache/sshd/common/future/DefaultSshFutureTest.java index 35a9e63..4d3edb2 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/future/DefaultSshFutureTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/future/DefaultSshFutureTest.java @@ -62,13 +62,10 @@ public class DefaultSshFutureTest extends BaseTestSupport { final DefaultSshFuture future = new DefaultSshFuture(null); final AtomicInteger listenerCount = new AtomicInteger(0); final Object expected = new Object(); - final SshFutureListener listener = new SshFutureListener() { - @Override - public void operationComplete(SshFuture f) { - assertSame("Mismatched future instance", future, f); - assertSame("Mismatched value object", expected, future.getValue()); - listenerCount.incrementAndGet(); - } + final SshFutureListener listener = f -> { + assertSame("Mismatched future instance", future, f); + assertSame("Mismatched value object", expected, future.getValue()); + listenerCount.incrementAndGet(); }; final int numListeners = Byte.SIZE; @@ -86,13 +83,10 @@ public class DefaultSshFutureTest extends BaseTestSupport { final DefaultSshFuture future = new DefaultSshFuture(null); final AtomicInteger listenerCount = new AtomicInteger(0); final Object expected = new Object(); - final SshFutureListener listener = new SshFutureListener() { - @Override - public void operationComplete(SshFuture f) { - assertSame("Mismatched future instance", future, f); - assertSame("Mismatched value object", expected, future.getValue()); - listenerCount.incrementAndGet(); - } + final SshFutureListener listener = f -> { + assertSame("Mismatched future instance", future, f); + assertSame("Mismatched value object", expected, future.getValue()); + listenerCount.incrementAndGet(); }; future.setValue(expected); @@ -123,13 +117,10 @@ public class DefaultSshFutureTest extends BaseTestSupport { final DefaultSshFuture future = new DefaultSshFuture(null); final AtomicInteger listenerCount = new AtomicInteger(0); final Object expected = new Object(); - final SshFutureListener listener = new SshFutureListener() { - @Override - public void operationComplete(SshFuture f) { - assertSame("Mismatched future instance", future, f); - assertSame("Mismatched value object", expected, future.getValue()); - listenerCount.incrementAndGet(); - } + final SshFutureListener listener = f -> { + assertSame("Mismatched future instance", future, f); + assertSame("Mismatched value object", expected, future.getValue()); + listenerCount.incrementAndGet(); }; future.addListener(listener); future.setValue(expected); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/kex/BuiltinDHFactoriesTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/kex/BuiltinDHFactoriesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/kex/BuiltinDHFactoriesTest.java index 74a7804..211d3ae 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/kex/BuiltinDHFactoriesTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/kex/BuiltinDHFactoriesTest.java @@ -71,14 +71,14 @@ public class BuiltinDHFactoriesTest extends BaseTestSupport { @Test public void testParseDHFactorysList() { - List<String> builtin = NamedResource.Utils.getNameList(BuiltinDHFactories.VALUES); + List<String> builtin = NamedResource.getNameList(BuiltinDHFactories.VALUES); List<String> unknown = Arrays.asList(getClass().getPackage().getName(), getClass().getSimpleName(), getCurrentTestName()); Random rnd = new Random(); for (int index = 0; index < (builtin.size() + unknown.size()); index++) { Collections.shuffle(builtin, rnd); Collections.shuffle(unknown, rnd); - List<String> weavedList = new ArrayList<String>(builtin.size() + unknown.size()); + List<String> weavedList = new ArrayList<>(builtin.size() + unknown.size()); for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size());) { boolean useBuiltin = false; if (bIndex < builtin.size()) { @@ -96,7 +96,7 @@ public class BuiltinDHFactoriesTest extends BaseTestSupport { String fullList = GenericUtils.join(weavedList, ','); ParseResult result = BuiltinDHFactories.parseDHFactoriesList(fullList); - List<String> parsed = NamedResource.Utils.getNameList(result.getParsedFactories()); + List<String> parsed = NamedResource.getNameList(result.getParsedFactories()); List<String> missing = result.getUnsupportedFactories(); // makes sure not only that the contents are the same but also the order http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/kex/KexFactoryManagerTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/kex/KexFactoryManagerTest.java b/sshd-core/src/test/java/org/apache/sshd/common/kex/KexFactoryManagerTest.java index b2a9682..a439027 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/kex/KexFactoryManagerTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/kex/KexFactoryManagerTest.java @@ -52,7 +52,7 @@ public class KexFactoryManagerTest extends BaseTestSupport { KexFactoryManager manager = new TestKexFactoryManager(); assertEquals("Mismatched empty factories name list", "", manager.getCompressionFactoriesNameList()); - String expected = NamedResource.Utils.getNames(BuiltinCompressions.VALUES); + String expected = NamedResource.getNames(BuiltinCompressions.VALUES); manager.setCompressionFactoriesNameList(expected); assertEquals("Mismatched updated factories name list", expected, manager.getCompressionFactoriesNameList()); @@ -69,7 +69,7 @@ public class KexFactoryManagerTest extends BaseTestSupport { KexFactoryManager manager = new TestKexFactoryManager(); assertEquals("Mismatched empty factories name list", "", manager.getCipherFactoriesNameList()); - String expected = NamedResource.Utils.getNames(BuiltinCiphers.VALUES); + String expected = NamedResource.getNames(BuiltinCiphers.VALUES); manager.setCipherFactoriesNameList(expected); assertEquals("Mismatched updated factories name list", expected, manager.getCipherFactoriesNameList()); @@ -86,7 +86,7 @@ public class KexFactoryManagerTest extends BaseTestSupport { KexFactoryManager manager = new TestKexFactoryManager(); assertEquals("Mismatched empty factories name list", "", manager.getMacFactoriesNameList()); - String expected = NamedResource.Utils.getNames(BuiltinMacs.VALUES); + String expected = NamedResource.getNames(BuiltinMacs.VALUES); manager.setMacFactoriesNameList(expected); assertEquals("Mismatched updated factories name list", expected, manager.getMacFactoriesNameList()); @@ -103,7 +103,7 @@ public class KexFactoryManagerTest extends BaseTestSupport { KexFactoryManager manager = new TestKexFactoryManager(); assertEquals("Mismatched empty factories name list", "", manager.getSignatureFactoriesNameList()); - String expected = NamedResource.Utils.getNames(BuiltinSignatures.VALUES); + String expected = NamedResource.getNames(BuiltinSignatures.VALUES); manager.setSignatureFactoriesNameList(expected); assertEquals("Mismatched updated factories name list", expected, manager.getSignatureFactoriesNameList()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/kex/KeyExchangeTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/kex/KeyExchangeTest.java b/sshd-core/src/test/java/org/apache/sshd/common/kex/KeyExchangeTest.java index fa3c8ee..db7c408 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/kex/KeyExchangeTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/kex/KeyExchangeTest.java @@ -22,6 +22,7 @@ package org.apache.sshd.common.kex; import java.util.Map; import org.apache.sshd.common.SshConstants; +import org.apache.sshd.common.kex.KeyExchange.Utils; import org.apache.sshd.common.util.Transformer; import org.apache.sshd.util.test.BaseTestSupport; import org.junit.FixMethodOrder; @@ -39,22 +40,12 @@ public class KeyExchangeTest extends BaseTestSupport { @Test public void testSimpleKexOpcodeName() { - testKexOpcodeName(KeyExchange.Utils.SIMPLE_KEX_OPCODES_MAP, new Transformer<Integer, String>() { - @Override - public String transform(Integer cmd) { - return KeyExchange.Utils.getSimpleKexOpcodeName(cmd); - } - }); + testKexOpcodeName(KeyExchange.SIMPLE_KEX_OPCODES_MAP, Utils::getSimpleKexOpcodeName); } @Test public void testGroupKexOpcodeName() { - testKexOpcodeName(KeyExchange.Utils.GROUP_KEX_OPCODES_MAP, new Transformer<Integer, String>() { - @Override - public String transform(Integer cmd) { - return KeyExchange.Utils.getGroupKexOpcodeName(cmd); - } - }); + testKexOpcodeName(KeyExchange.GROUP_KEX_OPCODES_MAP, Utils::getGroupKexOpcodeName); } private static void testKexOpcodeName(Map<Integer, String> opsMap, Transformer<Integer, String> xformer) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/keyprovider/KeyPairProviderTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/keyprovider/KeyPairProviderTest.java b/sshd-core/src/test/java/org/apache/sshd/common/keyprovider/KeyPairProviderTest.java index 73e3604..256c6f9 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/keyprovider/KeyPairProviderTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/keyprovider/KeyPairProviderTest.java @@ -22,8 +22,9 @@ package org.apache.sshd.common.keyprovider; import java.security.KeyPair; import java.security.PrivateKey; import java.security.PublicKey; +import java.util.Arrays; import java.util.Map; -import java.util.TreeMap; +import java.util.function.Function; import org.apache.sshd.common.util.GenericUtils; import org.apache.sshd.util.test.BaseTestSupport; @@ -57,15 +58,12 @@ public class KeyPairProviderTest extends BaseTestSupport { final PublicKey pubKey = Mockito.mock(PublicKey.class); final PrivateKey prvKey = Mockito.mock(PrivateKey.class); final String[] testKeys = {getCurrentTestName(), getClass().getSimpleName()}; - Map<String, KeyPair> pairsMap = new TreeMap<String, KeyPair>(String.CASE_INSENSITIVE_ORDER) { - private static final long serialVersionUID = 1L; // we're not serializing it + Map<String, KeyPair> pairsMap = GenericUtils.toSortedMap( + Arrays.asList(testKeys), + Function.identity(), + k -> new KeyPair(pubKey, prvKey), + String.CASE_INSENSITIVE_ORDER); - { - for (String keyType : testKeys) { - put(keyType, new KeyPair(pubKey, prvKey)); - } - } - }; KeyPairProvider provider = MappedKeyPairProvider.MAP_TO_KEY_PAIR_PROVIDER.transform(pairsMap); assertEquals("Key types", pairsMap.keySet(), provider.getKeyTypes()); assertEquals("Key pairs", pairsMap.values(), provider.loadKeys()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java index 7972b25..5b6577c 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java @@ -71,14 +71,14 @@ public class BuiltinMacsTest extends BaseTestSupport { @Test public void testParseMacsList() { - List<String> builtin = NamedResource.Utils.getNameList(BuiltinMacs.VALUES); + List<String> builtin = NamedResource.getNameList(BuiltinMacs.VALUES); List<String> unknown = Arrays.asList(getClass().getPackage().getName(), getClass().getSimpleName(), getCurrentTestName()); Random rnd = new Random(); for (int index = 0; index < (builtin.size() + unknown.size()); index++) { Collections.shuffle(builtin, rnd); Collections.shuffle(unknown, rnd); - List<String> weavedList = new ArrayList<String>(builtin.size() + unknown.size()); + List<String> weavedList = new ArrayList<>(builtin.size() + unknown.size()); for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size());) { boolean useBuiltin = false; if (bIndex < builtin.size()) { @@ -96,7 +96,7 @@ public class BuiltinMacsTest extends BaseTestSupport { String fullList = GenericUtils.join(weavedList, ','); ParseResult result = BuiltinMacs.parseMacsList(fullList); - List<String> parsed = NamedResource.Utils.getNameList(result.getParsedFactories()); + List<String> parsed = NamedResource.getNameList(result.getParsedFactories()); List<String> missing = result.getUnsupportedFactories(); // makes sure not only that the contents are the same but also the order http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java index 86e74af..c4eb730 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/mac/MacTest.java @@ -23,11 +23,9 @@ import java.io.InputStream; 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.List; -import java.util.TreeSet; import java.util.concurrent.TimeUnit; import com.jcraft.jsch.JSch; @@ -62,18 +60,8 @@ import ch.ethz.ssh2.ConnectionInfo; @RunWith(Parameterized.class) // see https://github.com/junit-team/junit/wiki/Parameterized-tests public class MacTest extends BaseTestSupport { private static final Collection<String> GANYMEDE_MACS = - Collections.unmodifiableSet(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER) { - private static final long serialVersionUID = 1L; // we're not serializing it - - { - String[] macs = Connection.getAvailableMACs(); - if (GenericUtils.length(macs) > 0) { - for (String m : macs) { - add(m); - } - } - } - }); + Collections.unmodifiableSet( + GenericUtils.asSortedSet(String.CASE_INSENSITIVE_ORDER, Connection.getAvailableMACs())); private static SshServer sshd; private static int port; @@ -144,7 +132,7 @@ public class MacTest extends BaseTestSupport { @Before public void setUp() throws Exception { - sshd.setMacFactories(Arrays.asList(factory)); + sshd.setMacFactories(Collections.singletonList(factory)); } @Test http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java b/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java index 6ece5e7..e4f8e3d 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/session/ReservedSessionMessagesHandlerTest.java @@ -99,18 +99,14 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport { @Override public void sessionEvent(final Session session, Event event) { if (Event.Authenticated.equals(event)) { - service.execute(new Runnable() { - @SuppressWarnings("synthetic-access") - @Override - public void run() { - try { - testReservedSessionMessagesHandler(session, handler); - outputDebugMessage("Release test signal for %s", session); - signal.release(); - } catch (Throwable t) { - outputDebugMessage("Failed (%s) to run test: %s", t.getClass().getSimpleName(), t.getMessage()); - session.exceptionCaught(t); - } + service.execute(() -> { + try { + testReservedSessionMessagesHandler(session, handler); + outputDebugMessage("Release test signal for %s", session); + signal.release(); + } catch (Throwable t) { + outputDebugMessage("Failed (%s) to run test: %s", t.getClass().getSimpleName(), t.getMessage()); + session.exceptionCaught(t); } }); } @@ -172,7 +168,7 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport { sb.setLength(sbLen); sb.append(index); - Pair<String, Boolean> entry = new Pair<>(sb.toString(), Boolean.valueOf((index & 0x01) == 0)); + Pair<String, Boolean> entry = new Pair<>(sb.toString(), (index & 0x01) == 0); expected.add(entry); session.sendDebugMessage(entry.getValue(), entry.getKey(), null); } @@ -225,7 +221,7 @@ public class ReservedSessionMessagesHandlerTest extends BaseTestSupport { @Override public void handleDebugMessage(Session session, boolean display, String msg, String lang, Buffer buffer) throws Exception { - debugMessages.add(new Pair<>(msg, Boolean.valueOf(display))); + debugMessages.add(new Pair<>(msg, display)); super.handleDebugMessage(session, display, msg, lang, buffer); debugSignal.release(); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java b/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java index 41622ca..b0f4a89 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/session/helpers/AbstractSessionTest.java @@ -127,9 +127,8 @@ public class AbstractSessionTest extends BaseTestSupport { @Test(expected = IllegalStateException.class) public void testReadIdentWithNullChar() { - StringBuilder sb = new StringBuilder(Session.MAX_VERSION_LINE_LENGTH + Integer.SIZE); - sb.append("SSH-2.0").append('\0').append("-software\r\n"); - Buffer buf = new ByteArrayBuffer(sb.toString().getBytes(StandardCharsets.UTF_8)); + String id = "SSH-2.0" + '\0' + "-software\r\n"; + Buffer buf = new ByteArrayBuffer(id.getBytes(StandardCharsets.UTF_8)); String ident = readIdentification(session, buf); fail("Unexpected success: " + ident); } @@ -185,12 +184,9 @@ public class AbstractSessionTest extends BaseTestSupport { @Test // see SSHD-652 public void testCloseFutureListenerRegistration() throws Exception { final AtomicInteger closeCount = new AtomicInteger(); - session.addCloseFutureListener(new SshFutureListener<CloseFuture>() { - @Override - public void operationComplete(CloseFuture future) { - assertTrue("Future not marted as closed", future.isClosed()); - assertEquals("Unexpected multiple call to callback", 1, closeCount.incrementAndGet()); - } + session.addCloseFutureListener(future -> { + assertTrue("Future not marted as closed", future.isClosed()); + assertEquals("Unexpected multiple call to callback", 1, closeCount.incrementAndGet()); }); session.close(); assertEquals("Close listener not called", 1, closeCount.get()); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/977b7b52/sshd-core/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java index 356846c..dde8d10 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java @@ -54,14 +54,14 @@ public class BuiltinSignaturesTest extends BaseTestSupport { @Test public void testParseSignaturesList() { - List<String> builtin = NamedResource.Utils.getNameList(BuiltinSignatures.VALUES); + List<String> builtin = NamedResource.getNameList(BuiltinSignatures.VALUES); List<String> unknown = Arrays.asList(getClass().getPackage().getName(), getClass().getSimpleName(), getCurrentTestName()); Random rnd = new Random(); for (int index = 0; index < (builtin.size() + unknown.size()); index++) { Collections.shuffle(builtin, rnd); Collections.shuffle(unknown, rnd); - List<String> weavedList = new ArrayList<String>(builtin.size() + unknown.size()); + List<String> weavedList = new ArrayList<>(builtin.size() + unknown.size()); for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size());) { boolean useBuiltin = false; if (bIndex < builtin.size()) { @@ -79,7 +79,7 @@ public class BuiltinSignaturesTest extends BaseTestSupport { String fullList = GenericUtils.join(weavedList, ','); ParseResult result = BuiltinSignatures.parseSignatureList(fullList); - List<String> parsed = NamedResource.Utils.getNameList(result.getParsedFactories()); + List<String> parsed = NamedResource.getNameList(result.getParsedFactories()); List<String> missing = result.getUnsupportedFactories(); // makes sure not only that the contents are the same but also the order
