http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java index b9597d7..dc7f94a 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyDataExtensionImplTest.java @@ -63,31 +63,31 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport { private static final List<Object[]> PARAMETERS = Collections.unmodifiableList( Arrays.<Object[]>asList( - new Object[] { - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), - Integer.valueOf(0), - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), - Long.valueOf(0L) - }, - new Object[] { - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE / 2), - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE / 4), - Long.valueOf(0L) - }, - new Object[] { - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE / 2), - Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE / 4), - Long.valueOf(IoUtils.DEFAULT_COPY_SIZE / 2) - }, - new Object[] { - Integer.valueOf(Byte.MAX_VALUE), - Integer.valueOf(Byte.MAX_VALUE / 2), - Integer.valueOf(Byte.MAX_VALUE), // attempt to read more than available - Long.valueOf(0L) - } - )); + new Object[]{ + Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), + Integer.valueOf(0), + Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), + Long.valueOf(0L) + }, + new Object[]{ + Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), + Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE / 2), + Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE / 4), + Long.valueOf(0L) + }, + new Object[]{ + Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE), + Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE / 2), + Integer.valueOf(IoUtils.DEFAULT_COPY_SIZE / 4), + Long.valueOf(IoUtils.DEFAULT_COPY_SIZE / 2) + }, + new Object[]{ + Integer.valueOf(Byte.MAX_VALUE), + Integer.valueOf(Byte.MAX_VALUE / 2), + Integer.valueOf(Byte.MAX_VALUE), // attempt to read more than available + Long.valueOf(0L) + } + )); @Parameters(name = "size={0}, readOffset={1}, readLength={2}, writeOffset={3}") public static Collection<Object[]> parameters() { @@ -121,16 +121,15 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport { private void testCopyDataExtension(int dataSize, int readOffset, int readLength, long writeOffset) throws Exception { byte[] seed = (getClass().getName() + "#" + getCurrentTestName() - + "-" + dataSize - + "-" + readOffset + "/" + readLength + "/" + writeOffset - + System.getProperty("line.separator")) - .getBytes(StandardCharsets.UTF_8) - ; - try(ByteArrayOutputStream baos=new ByteArrayOutputStream(dataSize + seed.length)) { + + "-" + dataSize + + "-" + readOffset + "/" + readLength + "/" + writeOffset + + System.getProperty("line.separator")) + .getBytes(StandardCharsets.UTF_8); + try (ByteArrayOutputStream baos = new ByteArrayOutputStream(dataSize + seed.length)) { while (baos.size() < dataSize) { baos.write(seed); } - + testCopyDataExtension(baos.toByteArray(), readOffset, readLength, writeOffset); } } @@ -151,7 +150,7 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport { } String dstPath = Utils.resolveRelativeRemotePath(parentPath, dstFile); - try(SshClient client = SshClient.setUpDefaultClient()) { + try (SshClient client = SshClient.setUpDefaultClient()) { client.start(); if (writeOffset > 0L) { @@ -159,8 +158,8 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport { Random randomizer = factory.create(); long totalLength = writeOffset + readLength; byte[] workBuf = new byte[(int) Math.min(totalLength, IoUtils.DEFAULT_COPY_SIZE)]; - try(OutputStream output = Files.newOutputStream(dstFile, IoUtils.EMPTY_OPEN_OPTIONS)) { - while(totalLength > 0L) { + try (OutputStream output = Files.newOutputStream(dstFile, IoUtils.EMPTY_OPEN_OPTIONS)) { + while (totalLength > 0L) { randomizer.fill(workBuf); output.write(workBuf); totalLength -= workBuf.length; @@ -171,11 +170,11 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport { try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); - - try(SftpClient sftp = session.createSftpClient()) { + + try (SftpClient sftp = session.createSftpClient()) { CopyDataExtension ext = assertExtensionCreated(sftp, CopyDataExtension.class); - try(CloseableHandle readHandle = sftp.open(srcPath, SftpClient.OpenMode.Read); - CloseableHandle writeHandle = sftp.open(dstPath, SftpClient.OpenMode.Write, SftpClient.OpenMode.Create)) { + try (CloseableHandle readHandle = sftp.open(srcPath, SftpClient.OpenMode.Read); + CloseableHandle writeHandle = sftp.open(dstPath, SftpClient.OpenMode.Write, SftpClient.OpenMode.Create)) { ext.copyData(readHandle, readOffset, readLength, writeHandle, writeOffset); } } @@ -183,16 +182,16 @@ public class CopyDataExtensionImplTest extends AbstractSftpClientTestSupport { client.stop(); } } - + int available = data.length, required = readOffset + readLength; if (required > available) { - required = available; + required = available; } byte[] expected = new byte[required - readOffset]; System.arraycopy(data, readOffset, expected, 0, expected.length); - + byte[] actual = new byte[expected.length]; - try(FileChannel channel = FileChannel.open(dstFile, IoUtils.EMPTY_OPEN_OPTIONS)) { + try (FileChannel channel = FileChannel.open(dstFile, IoUtils.EMPTY_OPEN_OPTIONS)) { int readLen = channel.read(ByteBuffer.wrap(actual), writeOffset); assertEquals("Mismatched read data size", expected.length, readLen); }
http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java index 36312b0..e105e63 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/CopyFileExtensionImplTest.java @@ -74,30 +74,30 @@ public class CopyFileExtensionImplTest extends AbstractSftpClientTestSupport { String srcPath = Utils.resolveRelativeRemotePath(parentPath, srcFile); Path dstFile = lclSftp.resolve("dst.txt"); String dstPath = Utils.resolveRelativeRemotePath(parentPath, dstFile); - + LinkOption[] options = IoUtils.getLinkOptions(false); assertFalse("Destination file unexpectedly exists", Files.exists(dstFile, options)); - try(SshClient client = SshClient.setUpDefaultClient()) { + try (SshClient client = SshClient.setUpDefaultClient()) { client.start(); - + try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); - - try(SftpClient sftp = session.createSftpClient()) { + + try (SftpClient sftp = session.createSftpClient()) { CopyFileExtension ext = assertExtensionCreated(sftp, CopyFileExtension.class); ext.copyFile(srcPath, dstPath, false); assertTrue("Source file not preserved", Files.exists(srcFile, options)); assertTrue("Destination file not created", Files.exists(dstFile, options)); - + byte[] actual = Files.readAllBytes(dstFile); assertArrayEquals("Mismatched copied data", data, actual); - + try { ext.copyFile(srcPath, dstPath, false); fail("Unexpected success to overwrite existing destination: " + dstFile); - } catch(IOException e) { + } catch (IOException e) { assertTrue("Not an SftpException", e instanceof SftpException); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java index 08c561d..446525b 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/impl/SpaceAvailableExtensionImplTest.java @@ -73,29 +73,29 @@ public class SpaceAvailableExtensionImplTest extends AbstractSftpClientTestSuppo final String queryPath = Utils.resolveRelativeRemotePath(parentPath, lclSftp); final SpaceAvailableExtensionInfo expected = new SpaceAvailableExtensionInfo(store); sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory() { - @Override - public Command create() { - return new SftpSubsystem(getExecutorService(), isShutdownOnExit(), getUnsupportedAttributePolicy()) { - @Override - protected SpaceAvailableExtensionInfo doSpaceAvailable(int id, String path) throws IOException { - if (!queryPath.equals(path)) { - throw new StreamCorruptedException("Mismatched query paths: expected=" + queryPath + ", actual=" + path); - } - - return expected; + @Override + public Command create() { + return new SftpSubsystem(getExecutorService(), isShutdownOnExit(), getUnsupportedAttributePolicy()) { + @Override + protected SpaceAvailableExtensionInfo doSpaceAvailable(int id, String path) throws IOException { + if (!queryPath.equals(path)) { + throw new StreamCorruptedException("Mismatched query paths: expected=" + queryPath + ", actual=" + path); } - }; - } - })); - try(SshClient client = SshClient.setUpDefaultClient()) { + return expected; + } + }; + } + })); + + try (SshClient client = SshClient.setUpDefaultClient()) { client.start(); - + try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); - - try(SftpClient sftp = session.createSftpClient()) { + + try (SftpClient sftp = session.createSftpClient()) { SpaceAvailableExtension ext = assertExtensionCreated(sftp, SpaceAvailableExtension.class); SpaceAvailableExtensionInfo actual = ext.available(queryPath); assertEquals("Mismatched information", expected, actual); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java index b6910af..067637b 100644 --- a/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/client/subsystem/sftp/extensions/openssh/impl/OpenSSHExtensionsTest.java @@ -19,8 +19,6 @@ package org.apache.sshd.client.subsystem.sftp.extensions.openssh.impl; -import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_EXTENDED_REPLY; - import java.io.IOException; import java.io.StreamCorruptedException; import java.lang.reflect.Field; @@ -61,6 +59,8 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; +import static org.apache.sshd.common.subsystem.sftp.SftpConstants.SSH_FXP_EXTENDED_REPLY; + /** * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ @@ -85,25 +85,25 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport { Path targetPath = detectTargetFolder().toPath(); Path lclSftp = Utils.resolve(targetPath, SftpConstants.SFTP_SUBSYSTEM_NAME, getClass().getSimpleName()); Path srcFile = assertHierarchyTargetFolderExists(lclSftp).resolve(getCurrentTestName() + ".txt"); - byte[] expected=(getClass().getName() + "#" + getCurrentTestName()).getBytes(StandardCharsets.UTF_8); + byte[] expected = (getClass().getName() + "#" + getCurrentTestName()).getBytes(StandardCharsets.UTF_8); Path parentPath = targetPath.getParent(); String srcPath = Utils.resolveRelativeRemotePath(parentPath, srcFile); - try(SshClient client = SshClient.setUpDefaultClient()) { + try (SshClient client = SshClient.setUpDefaultClient()) { client.start(); - + try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); - - try(SftpClient sftp = session.createSftpClient()) { + + try (SftpClient sftp = session.createSftpClient()) { OpenSSHFsyncExtension fsync = assertExtensionCreated(sftp, OpenSSHFsyncExtension.class); - try(CloseableHandle fileHandle = sftp.open(srcPath, SftpClient.OpenMode.Write, SftpClient.OpenMode.Create)) { + try (CloseableHandle fileHandle = sftp.open(srcPath, SftpClient.OpenMode.Write, SftpClient.OpenMode.Create)) { sftp.write(fileHandle, 0L, expected); fsync.fsync(fileHandle); byte[] actual = Files.readAllBytes(srcFile); - assertArrayEquals("Mismatched written data", expected, actual); + assertArrayEquals("Mismatched written data", expected, actual); } } } finally { @@ -123,69 +123,69 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport { final AtomicReference<String> extensionHolder = new AtomicReference<String>(null); final OpenSSHStatExtensionInfo expected = new OpenSSHStatExtensionInfo(); - { - expected.f_bavail = Short.MAX_VALUE; - expected.f_bfree = Integer.MAX_VALUE; - expected.f_blocks = Short.MAX_VALUE; - expected.f_bsize = IoUtils.DEFAULT_COPY_SIZE; - expected.f_favail = Long.MAX_VALUE; - expected.f_ffree = Byte.MAX_VALUE; - expected.f_files = 3777347L; - expected.f_flag = OpenSSHStatExtensionInfo.SSH_FXE_STATVFS_ST_RDONLY; - expected.f_frsize = 7365L; - expected.f_fsid = 1L; - expected.f_namemax = 256; - } + { + expected.f_bavail = Short.MAX_VALUE; + expected.f_bfree = Integer.MAX_VALUE; + expected.f_blocks = Short.MAX_VALUE; + expected.f_bsize = IoUtils.DEFAULT_COPY_SIZE; + expected.f_favail = Long.MAX_VALUE; + expected.f_ffree = Byte.MAX_VALUE; + expected.f_files = 3777347L; + expected.f_flag = OpenSSHStatExtensionInfo.SSH_FXE_STATVFS_ST_RDONLY; + expected.f_frsize = 7365L; + expected.f_fsid = 1L; + expected.f_namemax = 256; + } sshd.setSubsystemFactories(Arrays.<NamedFactory<Command>>asList(new SftpSubsystemFactory() { - @Override - public Command create() { - return new SftpSubsystem(getExecutorService(), isShutdownOnExit(), getUnsupportedAttributePolicy()) { - @Override - protected List<OpenSSHExtension> resolveOpenSSHExtensions() { - List<OpenSSHExtension> original = super.resolveOpenSSHExtensions(); - int numOriginal = GenericUtils.size(original); - List<OpenSSHExtension> result = new ArrayList<OpenSSHExtension>(numOriginal + 2); - if (numOriginal > 0) { - result.addAll(original); - } - - for (String name : new String[] { StatVfsExtensionParser.NAME, FstatVfsExtensionParser.NAME}) { - result.add(new OpenSSHExtension(name, "2")); - } - - return result; + @Override + public Command create() { + return new SftpSubsystem(getExecutorService(), isShutdownOnExit(), getUnsupportedAttributePolicy()) { + @Override + protected List<OpenSSHExtension> resolveOpenSSHExtensions() { + List<OpenSSHExtension> original = super.resolveOpenSSHExtensions(); + int numOriginal = GenericUtils.size(original); + List<OpenSSHExtension> result = new ArrayList<OpenSSHExtension>(numOriginal + 2); + if (numOriginal > 0) { + result.addAll(original); + } + + for (String name : new String[]{StatVfsExtensionParser.NAME, FstatVfsExtensionParser.NAME}) { + result.add(new OpenSSHExtension(name, "2")); } - @Override - protected void executeExtendedCommand(Buffer buffer, int id, String extension) throws IOException { - if (StatVfsExtensionParser.NAME.equals(extension) - || FstatVfsExtensionParser.NAME.equals(extension)) { - String prev = extensionHolder.getAndSet(extension); - if (prev != null) { - throw new StreamCorruptedException("executeExtendedCommand(" + extension + ") previous not null: " + prev); - } - - buffer.clear(); - buffer.putByte((byte) SSH_FXP_EXTENDED_REPLY); - buffer.putInt(id); - OpenSSHStatExtensionInfo.encode(buffer, expected); - send(buffer); - } else { - super.executeExtendedCommand(buffer, id, extension); + return result; + } + + @Override + protected void executeExtendedCommand(Buffer buffer, int id, String extension) throws IOException { + if (StatVfsExtensionParser.NAME.equals(extension) + || FstatVfsExtensionParser.NAME.equals(extension)) { + String prev = extensionHolder.getAndSet(extension); + if (prev != null) { + throw new StreamCorruptedException("executeExtendedCommand(" + extension + ") previous not null: " + prev); } + + buffer.clear(); + buffer.putByte((byte) SSH_FXP_EXTENDED_REPLY); + buffer.putInt(id); + OpenSSHStatExtensionInfo.encode(buffer, expected); + send(buffer); + } else { + super.executeExtendedCommand(buffer, id, extension); } - }; - } - })); - - try(SshClient client = SshClient.setUpDefaultClient()) { + } + }; + } + })); + + try (SshClient client = SshClient.setUpDefaultClient()) { client.start(); - + try (ClientSession session = client.connect(getCurrentTestName(), "localhost", port).verify(7L, TimeUnit.SECONDS).getSession()) { session.addPasswordIdentity(getCurrentTestName()); session.auth().verify(5L, TimeUnit.SECONDS); - - try(SftpClient sftp = session.createSftpClient()) { + + try (SftpClient sftp = session.createSftpClient()) { { OpenSSHStatPathExtension pathStat = assertExtensionCreated(sftp, OpenSSHStatPathExtension.class); OpenSSHStatExtensionInfo actual = pathStat.stat(srcPath); @@ -193,8 +193,8 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport { assertEquals("Mismatched invoked extension", pathStat.getName(), invokedExtension); assertOpenSSHStatExtensionInfoEquals(invokedExtension, expected, actual); } - - try(CloseableHandle handle = sftp.open(srcPath)) { + + try (CloseableHandle handle = sftp.open(srcPath)) { OpenSSHStatHandleExtension handleStat = assertExtensionCreated(sftp, OpenSSHStatHandleExtension.class); OpenSSHStatExtensionInfo actual = handleStat.stat(handle); String invokedExtension = extensionHolder.getAndSet(null); @@ -205,7 +205,7 @@ public class OpenSSHExtensionsTest extends AbstractSftpClientTestSupport { } } } - + private static void assertOpenSSHStatExtensionInfoEquals(String extension, OpenSSHStatExtensionInfo expected, OpenSSHStatExtensionInfo actual) throws Exception { Field[] fields = expected.getClass().getFields(); for (Field f : fields) { http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/common/FactoryManagerUtilsTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/FactoryManagerUtilsTest.java b/sshd-core/src/test/java/org/apache/sshd/common/FactoryManagerUtilsTest.java index 2bf955b..e5fe646 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/FactoryManagerUtilsTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/FactoryManagerUtilsTest.java @@ -40,25 +40,25 @@ public class FactoryManagerUtilsTest extends BaseTestSupport { @Test public void testLongProperty() { - final long expected=System.currentTimeMillis(); - final String name=getCurrentTestName(); - + final long expected = System.currentTimeMillis(); + final String name = getCurrentTestName(); + Session session = createMockSession(); assertEquals("Mismatched empty props value", expected, FactoryManagerUtils.getLongProperty(session, name, expected)); FactoryManagerUtils.updateProperty(session, name, expected); testLongProperty(session, name, expected); - + FactoryManagerUtils.updateProperty(session, name, Long.toString(expected)); testLongProperty(session, name, expected); } - + private void testLongProperty(Session session, String name, long expected) { - FactoryManager manager = session.getFactoryManager(); - Map<String,?> props = manager.getProperties(); - Object value = props.get(name); - Class<?> type = value.getClass(); - String storage = type.getSimpleName(); + FactoryManager manager = session.getFactoryManager(); + Map<String, ?> props = manager.getProperties(); + Object value = props.get(name); + Class<?> type = value.getClass(); + String storage = type.getSimpleName(); { Long actual = FactoryManagerUtils.getLong(session, name); @@ -75,15 +75,15 @@ public class FactoryManagerUtilsTest extends BaseTestSupport { @Test public void testIntegerProperty() { - final int expected=3777347; - final String name=getCurrentTestName(); - + final int expected = 3777347; + final String name = getCurrentTestName(); + Session session = createMockSession(); assertEquals("Mismatched empty props value", expected, FactoryManagerUtils.getIntProperty(session, name, expected)); FactoryManagerUtils.updateProperty(session, name, expected); testIntegerProperty(session, name, expected); - + FactoryManagerUtils.updateProperty(session, name, Integer.toString(expected)); testIntegerProperty(session, name, expected); @@ -91,13 +91,13 @@ public class FactoryManagerUtilsTest extends BaseTestSupport { FactoryManagerUtils.updateProperty(session, name, Long.valueOf(expected)); testIntegerProperty(session, name, expected); } - + private void testIntegerProperty(Session session, String name, int expected) { - FactoryManager manager = session.getFactoryManager(); - Map<String,?> props = manager.getProperties(); - Object value = props.get(name); - Class<?> type = value.getClass(); - String storage = type.getSimpleName(); + FactoryManager manager = session.getFactoryManager(); + Map<String, ?> props = manager.getProperties(); + Object value = props.get(name); + Class<?> type = value.getClass(); + String storage = type.getSimpleName(); { Integer actual = FactoryManagerUtils.getInteger(session, name); @@ -114,26 +114,26 @@ public class FactoryManagerUtilsTest extends BaseTestSupport { @Test public void testBooleanProperty() { - for (final boolean expected : new boolean[] { false, true }) { - final String name=getCurrentTestName(); - + for (final boolean expected : new boolean[]{false, true}) { + final String name = getCurrentTestName(); + Session session = createMockSession(); assertEquals("Mismatched empty props value", expected, FactoryManagerUtils.getBooleanProperty(session, name, expected)); - + FactoryManagerUtils.updateProperty(session, name, expected); testBooleanProperty(session, name, expected); - + FactoryManagerUtils.updateProperty(session, name, Boolean.toString(expected)); testBooleanProperty(session, name, expected); } } - + private void testBooleanProperty(Session session, String name, boolean expected) { - FactoryManager manager = session.getFactoryManager(); - Map<String,?> props = manager.getProperties(); - Object value = props.get(name); - Class<?> type = value.getClass(); - String storage = type.getSimpleName(); + FactoryManager manager = session.getFactoryManager(); + Map<String, ?> props = manager.getProperties(); + Object value = props.get(name); + Class<?> type = value.getClass(); + String storage = type.getSimpleName(); { Boolean actual = FactoryManagerUtils.getBoolean(session, name); @@ -149,10 +149,10 @@ public class FactoryManagerUtilsTest extends BaseTestSupport { } private Session createMockSession() { - Map<String,Object> props = new TreeMap<String,Object>(String.CASE_INSENSITIVE_ORDER); - FactoryManager manager = Mockito.mock(FactoryManager.class); + Map<String, Object> props = new TreeMap<String, Object>(String.CASE_INSENSITIVE_ORDER); + FactoryManager manager = Mockito.mock(FactoryManager.class); Mockito.when(manager.getProperties()).thenReturn(props); - + Session session = Mockito.mock(Session.class); Mockito.when(session.getUsername()).thenReturn(getCurrentTestName()); Mockito.when(session.getFactoryManager()).thenReturn(manager); http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/common/ForwardingFilterTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/ForwardingFilterTest.java b/sshd-core/src/test/java/org/apache/sshd/common/ForwardingFilterTest.java index 3246f1f..75ea234 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/ForwardingFilterTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/ForwardingFilterTest.java @@ -41,12 +41,12 @@ public class ForwardingFilterTest extends BaseTestSupport { @Test public void testFromStringForwardingFilterType() { - for (String name : new String[] { null, "", getCurrentTestName() }) { + for (String name : new String[]{null, "", getCurrentTestName()}) { assertNull("Unexpected value for name='" + name + "'", ForwardingFilter.Type.fromString(name)); } for (ForwardingFilter.Type expected : ForwardingFilter.Type.VALUES) { - for (String name : new String[] { expected.name(), expected.getName() }) { + for (String name : new String[]{expected.name(), expected.getName()}) { for (int index = 0; index < name.length(); index++) { ForwardingFilter.Type actual = ForwardingFilter.Type.fromString(name); assertSame("Mismatched instance for name=" + name, expected, actual); @@ -55,6 +55,7 @@ public class ForwardingFilterTest extends BaseTestSupport { } } } + @Test public void testAcceptAllForwardingFilter() { testStaticDecisionForwardingFilter(AcceptAllForwardingFilter.INSTANCE, true); @@ -67,12 +68,12 @@ public class ForwardingFilterTest extends BaseTestSupport { private static void testStaticDecisionForwardingFilter(StaticDecisionForwardingFilter filter, boolean expected) { assertEquals("Mismatched acceptance status", expected, filter.isAccepted()); - - Session session=Mockito.mock(Session.class); + + Session session = Mockito.mock(Session.class); assertEquals("Mismatched 'canForwardAgent' result", expected, filter.canForwardAgent(session)); assertEquals("Mismatched 'canForwardX11' result", expected, filter.canForwardX11(session)); assertEquals("Mismatched 'canListen' result", expected, filter.canListen(SshdSocketAddress.LOCALHOST_ADDRESS, session)); - + for (ForwardingFilter.Type t : ForwardingFilter.Type.VALUES) { assertEquals("Mismatched 'canConnect(" + t + ")' result", expected, filter.canConnect(t, SshdSocketAddress.LOCALHOST_ADDRESS, session)); } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/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 ba73f02..610f242 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 @@ -50,7 +50,7 @@ public class SshBuilderTest extends BaseTestSupport { */ @Test public void testAllBuiltinCiphersListed() { - Set<BuiltinCiphers> all=EnumSet.allOf(BuiltinCiphers.class); + Set<BuiltinCiphers> all = EnumSet.allOf(BuiltinCiphers.class); // The 'none' cipher is not listed as preferred - it is implied assertTrue("Missing " + BuiltinCiphers.Constants.NONE + " cipher in all values", all.remove(BuiltinCiphers.none)); testAllInstancesListed(all, BaseBuilder.DEFAULT_CIPHERS_PREFERENCE); @@ -97,14 +97,14 @@ public class SshBuilderTest extends BaseTestSupport { */ @Test public void testSetUpDefaultCiphers() { - for (boolean ignoreUnsupported : new boolean[] { true, false }) { - List<NamedFactory<Cipher>> ciphers=BaseBuilder.setUpDefaultCiphers(ignoreUnsupported); - int numCiphers=GenericUtils.size(ciphers); + for (boolean ignoreUnsupported : new boolean[]{true, false}) { + List<NamedFactory<Cipher>> ciphers = BaseBuilder.setUpDefaultCiphers(ignoreUnsupported); + int numCiphers = GenericUtils.size(ciphers); // make sure returned list size matches expected count if (ignoreUnsupported) { assertEquals("Incomplete full ciphers size", BaseBuilder.DEFAULT_CIPHERS_PREFERENCE.size(), numCiphers); } else { - int expectedCount=0; + int expectedCount = 0; for (BuiltinCiphers c : BaseBuilder.DEFAULT_CIPHERS_PREFERENCE) { if (c.isSupported()) { expectedCount++; @@ -112,19 +112,19 @@ public class SshBuilderTest extends BaseTestSupport { } assertEquals("Incomplete supported ciphers size", expectedCount, numCiphers); } - + // make sure order is according to the default preference list - List<String> cipherNames=NamedResource.Utils.getNameList(ciphers); - int nameIndex=0; + List<String> cipherNames = NamedResource.Utils.getNameList(ciphers); + int nameIndex = 0; for (BuiltinCiphers c : BaseBuilder.DEFAULT_CIPHERS_PREFERENCE) { if ((!c.isSupported()) && (!ignoreUnsupported)) { continue; } - - String expectedName=c.getName(); + + String expectedName = c.getName(); assertTrue("Out of actual ciphers for expected=" + expectedName, nameIndex < numCiphers); - - String actualName=cipherNames.get(nameIndex); + + String actualName = cipherNames.get(nameIndex); assertEquals("Mismatched cipher at position " + nameIndex + " for ignoreUnsupported=" + ignoreUnsupported, expectedName, actualName); nameIndex++; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java index b7f1d9e..d7afcd8 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/ChannelPipedInputStreamTest.java @@ -37,14 +37,14 @@ public class ChannelPipedInputStreamTest extends BaseTestSupport { @Test public void testAvailable() throws IOException { Window window = new Window(new BogusChannel(), null, true, true); - try(ChannelPipedInputStream stream = new ChannelPipedInputStream(window)) { + try (ChannelPipedInputStream stream = new ChannelPipedInputStream(window)) { byte[] b = getCurrentTestName().getBytes(StandardCharsets.UTF_8); stream.receive(b, 0, b.length); assertEquals("Mismatched reported available size after receive", b.length, stream.available()); - + stream.eof(); assertEquals("Mismatched reported available size after EOF", b.length, stream.available()); - + byte[] readBytes = new byte[b.length + Long.SIZE]; assertEquals("Mismatched reported read size", b.length, stream.read(readBytes)); assertStreamEquals(b, readBytes); @@ -55,12 +55,12 @@ public class ChannelPipedInputStreamTest extends BaseTestSupport { @Test public void testIdempotentClose() throws IOException { Window window = new Window(new BogusChannel(), null, true, true); - try(ChannelPipedInputStream stream = new ChannelPipedInputStream(window)) { + try (ChannelPipedInputStream stream = new ChannelPipedInputStream(window)) { byte[] b = getCurrentTestName().getBytes(StandardCharsets.UTF_8); stream.receive(b, 0, b.length); stream.eof(); - - for (int index=0; index < Byte.SIZE; index++) { + + for (int index = 0; index < Byte.SIZE; index++) { stream.close(); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/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 249887c..cb6f943 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 @@ -44,27 +44,27 @@ public class ChannelPipedOutputStreamTest extends BaseTestSupport { @Test public void testNioChannelImplementation() throws IOException { - ChannelPipedSink sink = Mockito.mock(ChannelPipedSink.class); + 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; - } - }).when(sink).eof(); + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + 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; - } - }).when(sink).receive(Matchers.any(byte[].class), Matchers.anyInt(), Matchers.anyInt()); - try(ChannelPipedOutputStream stream = new ChannelPipedOutputStream(sink)) { + @Override + public Void answer(InvocationOnMock invocation) throws Throwable { + 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()); assertEquals("Unexpected initial receive count", 0, receiveCount.intValue()); @@ -72,7 +72,7 @@ public class ChannelPipedOutputStreamTest extends BaseTestSupport { stream.write(b); assertTrue("Stream not marked as still open after write data", stream.isOpen()); assertEquals("Mismatched write data count", b.length, receiveCount.intValue()); - + stream.close(); assertFalse("Stream still marked as open after close", stream.isOpen()); assertTrue("Sink EOF not called on close", eofCalled.get()); @@ -80,14 +80,14 @@ public class ChannelPipedOutputStreamTest extends BaseTestSupport { try { stream.write(b); fail("Unexpected write success after close"); - } catch(IOException e) { + } catch (IOException e) { // expected } try { stream.flush(); fail("Unexpected flush success after close"); - } catch(IOException e) { + } catch (IOException e) { // expected } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java index 1074ef0..4a31038 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES192CTRTest.java @@ -28,14 +28,14 @@ import org.junit.runners.MethodSorters; */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class AES192CTRTest extends BaseCipherTest { - public AES192CTRTest() { - super(); - } + public AES192CTRTest() { + super(); + } - @Test - public void testEncryptDecrypt() throws Exception { - // for AES 256 bits we need the JCE unlimited strength policy - ensureKeySizeSupported(16, 24, "AES", "AES/CTR/NoPadding"); - testEncryptDecrypt(BuiltinCiphers.aes192ctr); - } + @Test + public void testEncryptDecrypt() throws Exception { + // for AES 256 bits we need the JCE unlimited strength policy + ensureKeySizeSupported(16, 24, "AES", "AES/CTR/NoPadding"); + testEncryptDecrypt(BuiltinCiphers.aes192ctr); + } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java index fea7d34..30208ab 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/AES256CBCTest.java @@ -28,14 +28,14 @@ import org.junit.runners.MethodSorters; */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class AES256CBCTest extends BaseCipherTest { - public AES256CBCTest() { - super(); - } + public AES256CBCTest() { + super(); + } - @Test - public void testEncryptDecrypt() throws Exception { - // for AES 256 bits we need the JCE unlimited strength policy - ensureKeySizeSupported(16, 32, "AES", "AES/CBC/NoPadding"); - testEncryptDecrypt(BuiltinCiphers.aes256cbc); - } + @Test + public void testEncryptDecrypt() throws Exception { + // for AES 256 bits we need the JCE unlimited strength policy + ensureKeySizeSupported(16, 32, "AES", "AES/CBC/NoPadding"); + testEncryptDecrypt(BuiltinCiphers.aes256cbc); + } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java index cc08799..7ff066f 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR128Test.java @@ -28,12 +28,12 @@ import org.junit.runners.MethodSorters; */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ARCFOUR128Test extends BaseCipherTest { - public ARCFOUR128Test() { - super(); - } + public ARCFOUR128Test() { + super(); + } - @Test - public void testEncryptDecrypt() throws Exception { - testEncryptDecrypt(BuiltinCiphers.arcfour128); - } + @Test + public void testEncryptDecrypt() throws Exception { + testEncryptDecrypt(BuiltinCiphers.arcfour128); + } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java index 6a3ccef..ac534c6 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ARCFOUR256Test.java @@ -28,14 +28,14 @@ import org.junit.runners.MethodSorters; */ @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ARCFOUR256Test extends BaseCipherTest { - public ARCFOUR256Test() { - super(); - } + public ARCFOUR256Test() { + super(); + } - @Test - public void testEncryptDecrypt() throws Exception { - // for RC4 256 bits we need the JCE unlimited strength policy - ensureKeySizeSupported(32, "ARCFOUR", "RC4"); - testEncryptDecrypt(BuiltinCiphers.arcfour256); - } + @Test + public void testEncryptDecrypt() throws Exception { + // for RC4 256 bits we need the JCE unlimited strength policy + ensureKeySizeSupported(32, "ARCFOUR", "RC4"); + testEncryptDecrypt(BuiltinCiphers.arcfour256); + } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java index 67fe05d..95e8f3e 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/BaseCipherTest.java @@ -19,13 +19,12 @@ package org.apache.sshd.common.cipher; +import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; import java.nio.charset.StandardCharsets; import java.security.GeneralSecurityException; import java.security.InvalidKeyException; -import javax.crypto.spec.IvParameterSpec; -import javax.crypto.spec.SecretKeySpec; - import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.cipher.Cipher.Mode; import org.apache.sshd.common.util.SecurityUtils; @@ -36,55 +35,55 @@ import org.junit.Assume; * @author <a href="mailto:[email protected]">Apache MINA SSHD Project</a> */ public abstract class BaseCipherTest extends BaseTestSupport { - protected BaseCipherTest() { - super(); - } + protected BaseCipherTest() { + super(); + } protected void ensureKeySizeSupported(int bsize, String algorithm, String transformation) throws GeneralSecurityException { - try { - javax.crypto.Cipher cipher=SecurityUtils.getCipher(transformation); - byte[] key=new byte[bsize]; - cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, new SecretKeySpec(key, algorithm)); - } catch(GeneralSecurityException e) { - if (e instanceof InvalidKeyException) { // NOTE: assumption violations are NOT test failures... - Assume.assumeTrue(algorithm + "/" + transformation + "[" + bsize + "] N/A", false); - } + try { + javax.crypto.Cipher cipher = SecurityUtils.getCipher(transformation); + byte[] key = new byte[bsize]; + cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, new SecretKeySpec(key, algorithm)); + } catch (GeneralSecurityException e) { + if (e instanceof InvalidKeyException) { // NOTE: assumption violations are NOT test failures... + Assume.assumeTrue(algorithm + "/" + transformation + "[" + bsize + "] N/A", false); + } - throw e; - } - } + throw e; + } + } - protected void ensureKeySizeSupported(int ivsize, int bsize, String algorithm, String transformation) throws GeneralSecurityException { - try { - javax.crypto.Cipher cipher=SecurityUtils.getCipher(transformation); - byte[] key=new byte[bsize]; - byte[] iv=new byte[ivsize]; - cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, new SecretKeySpec(key, algorithm), new IvParameterSpec(iv)); - } catch(GeneralSecurityException e) { - if (e instanceof InvalidKeyException) { - Assume.assumeTrue(algorithm + "/" + transformation + "[" + bsize + "/" + ivsize + "]", false /* force exception */); - } + protected void ensureKeySizeSupported(int ivsize, int bsize, String algorithm, String transformation) throws GeneralSecurityException { + try { + javax.crypto.Cipher cipher = SecurityUtils.getCipher(transformation); + byte[] key = new byte[bsize]; + byte[] iv = new byte[ivsize]; + cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, new SecretKeySpec(key, algorithm), new IvParameterSpec(iv)); + } catch (GeneralSecurityException e) { + if (e instanceof InvalidKeyException) { + Assume.assumeTrue(algorithm + "/" + transformation + "[" + bsize + "/" + ivsize + "]", false /* force exception */); + } - throw e; - } - } + throw e; + } + } - protected void testEncryptDecrypt(NamedFactory<Cipher> factory) throws Exception { - String facName=factory.getName(); - Cipher enc=factory.create(); - int keySize=enc.getBlockSize(), ivSize=enc.getIVSize(); - byte[] key=new byte[keySize], iv=new byte[ivSize]; - enc.init(Mode.Encrypt, key, iv); + protected void testEncryptDecrypt(NamedFactory<Cipher> factory) throws Exception { + String facName = factory.getName(); + Cipher enc = factory.create(); + int keySize = enc.getBlockSize(), ivSize = enc.getIVSize(); + byte[] key = new byte[keySize], iv = new byte[ivSize]; + enc.init(Mode.Encrypt, key, iv); - byte[] expected=facName.getBytes(StandardCharsets.UTF_8); - byte[] workBuf=expected.clone(); // need to clone since the cipher works in-line - enc.update(workBuf, 0, workBuf.length); + byte[] expected = facName.getBytes(StandardCharsets.UTF_8); + byte[] workBuf = expected.clone(); // need to clone since the cipher works in-line + enc.update(workBuf, 0, workBuf.length); - Cipher dec=factory.create(); - dec.init(Mode.Decrypt, key, iv); - byte[] actual=workBuf.clone(); - dec.update(actual, 0, actual.length); + Cipher dec = factory.create(); + dec.init(Mode.Decrypt, key, iv); + byte[] actual = workBuf.clone(); + dec.update(actual, 0, actual.length); - assertArrayEquals(facName, expected, actual); - } + assertArrayEquals(facName, expected, actual); + } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/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 ad1cf02..c9514f2 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 @@ -56,10 +56,10 @@ public class BuiltinCiphersTest extends BaseTestSupport { @Test public void testFromEnumName() { for (BuiltinCiphers expected : BuiltinCiphers.VALUES) { - String name=expected.name(); + String name = expected.name(); - for (int index=0; index < name.length(); index++) { - BuiltinCiphers actual=BuiltinCiphers.fromString(name); + for (int index = 0; index < name.length(); index++) { + BuiltinCiphers actual = BuiltinCiphers.fromString(name); assertSame(name + " - mismatched enum values", expected, actual); name = shuffleCase(name); // prepare for next time } @@ -69,10 +69,10 @@ public class BuiltinCiphersTest extends BaseTestSupport { @Test public void testFromFactoryName() { for (BuiltinCiphers expected : BuiltinCiphers.VALUES) { - String name=expected.getName(); - - for (int index=0; index < name.length(); index++) { - BuiltinCiphers actual=BuiltinCiphers.fromFactoryName(name); + String name = expected.getName(); + + for (int index = 0; index < name.length(); index++) { + BuiltinCiphers actual = BuiltinCiphers.fromFactoryName(name); assertSame(name + " - mismatched enum values", expected, actual); name = shuffleCase(name); // prepare for next time } @@ -86,19 +86,19 @@ public class BuiltinCiphersTest extends BaseTestSupport { System.out.append("Skip unsupported cipher: ").println(expected); continue; } - - NamedFactory<Cipher> factory=expected; + + NamedFactory<Cipher> factory = expected; assertEquals(expected.name() + " - mismatched factory names", expected.getName(), factory.getName()); - BuiltinCiphers actual=BuiltinCiphers.fromFactory(factory); + BuiltinCiphers actual = BuiltinCiphers.fromFactory(factory); assertSame(expected.getName() + " - mismatched enum values", expected, actual); } } @Test public void testAllConstantsCovered() throws Exception { - Set<BuiltinCiphers> avail=EnumSet.noneOf(BuiltinCiphers.class); - Field[] fields=BuiltinCiphers.Constants.class.getFields(); + Set<BuiltinCiphers> avail = EnumSet.noneOf(BuiltinCiphers.class); + Field[] fields = BuiltinCiphers.Constants.class.getFields(); for (Field f : fields) { int mods = f.getModifiers(); if (!Modifier.isStatic(mods)) { @@ -115,19 +115,19 @@ public class BuiltinCiphersTest extends BaseTestSupport { assertNotNull("No match found for " + name, value); assertTrue(name + " re-specified", avail.add(value)); } - + assertEquals("Incomplete coverage", BuiltinCiphers.VALUES, avail); } @Test // make sure that if a cipher is reported as supported we can indeed use it public void testSupportedCipher() throws Exception { Exception err = null; - Random rnd = new Random(System.nanoTime()); + Random rnd = new Random(System.nanoTime()); for (BuiltinCiphers c : BuiltinCiphers.VALUES) { if (c.isSupported()) { try { testCipherEncryption(rnd, c.create()); - } catch(Exception e) { + } catch (Exception e) { System.err.println("Failed (" + e.getClass().getSimpleName() + ") to encrypt using " + c + ": " + e.getMessage()); err = e; } @@ -135,7 +135,7 @@ public class BuiltinCiphersTest extends BaseTestSupport { System.out.append("Skip unsupported cipher: ").println(c); } } - + if (err != null) { throw err; } @@ -143,12 +143,12 @@ public class BuiltinCiphersTest extends BaseTestSupport { @Test // make sure that the reported support matches reality by trying to encrypt something public void testCipherSupportDetection() throws Exception { - Random rnd = new Random(System.nanoTime()); + Random rnd = new Random(System.nanoTime()); for (BuiltinCiphers c : BuiltinCiphers.VALUES) { try { testCipherEncryption(rnd, c.create()); assertTrue("Mismatched support report for " + c, c.isSupported()); - } catch(Exception e) { + } catch (Exception e) { assertFalse("Mismatched support report for " + c, c.isSupported()); } } @@ -156,14 +156,14 @@ public class BuiltinCiphersTest extends BaseTestSupport { @Test public void testSshClientSupportedCiphersConfiguration() throws Exception { - try(SshClient client = SshClient.setUpDefaultClient()) { + try (SshClient client = SshClient.setUpDefaultClient()) { testSupportedCiphersConfiguration(client); } } @Test public void testSshSercerSupportedCiphersConfiguration() throws Exception { - try(SshServer server = SshServer.setUpDefaultServer()) { + try (SshServer server = SshServer.setUpDefaultServer()) { testSupportedCiphersConfiguration(server); } } @@ -181,35 +181,35 @@ public class BuiltinCiphersTest extends BaseTestSupport { assertTrue("Supported cipher not configured by default: " + c, names.contains(c.getName())); } } - + return manager; } private static void testCipherEncryption(Random rnd, Cipher cipher) throws Exception { - byte[] key=new byte[cipher.getBlockSize()]; + byte[] key = new byte[cipher.getBlockSize()]; rnd.nextBytes(key); - byte[] iv=new byte[cipher.getIVSize()]; + byte[] iv = new byte[cipher.getIVSize()]; rnd.nextBytes(iv); cipher.init(Cipher.Mode.Encrypt, key, iv); - byte[] data=new byte[cipher.getBlockSize()]; + byte[] data = new byte[cipher.getBlockSize()]; rnd.nextBytes(data); - + cipher.update(data); } @Test public void testParseCiphersList() { - List<String> builtin=NamedResource.Utils.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++) { + List<String> builtin = NamedResource.Utils.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()); - for (int bIndex=0, uIndex=0; (bIndex < builtin.size()) || (uIndex < unknown.size()); ) { - boolean useBuiltin=false; + + List<String> weavedList = new ArrayList<String>(builtin.size() + unknown.size()); + for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size()); ) { + boolean useBuiltin = false; if (bIndex < builtin.size()) { useBuiltin = (uIndex < unknown.size()) ? rnd.nextBoolean() : true; } @@ -217,17 +217,17 @@ public class BuiltinCiphersTest extends BaseTestSupport { if (useBuiltin) { weavedList.add(builtin.get(bIndex)); bIndex++; - } else if (uIndex < unknown.size()){ + } else if (uIndex < unknown.size()) { weavedList.add(unknown.get(uIndex)); uIndex++; } } - String fullList=GenericUtils.join(weavedList, ','); - ParseResult result=BuiltinCiphers.parseCiphersList(fullList); - List<String> parsed=NamedResource.Utils.getNameList(result.getParsedFactories()); - List<String> missing=result.getUnsupportedFactories(); - + String fullList = GenericUtils.join(weavedList, ','); + ParseResult result = BuiltinCiphers.parseCiphersList(fullList); + List<String> parsed = NamedResource.Utils.getNameList(result.getParsedFactories()); + List<String> missing = result.getUnsupportedFactories(); + // makes sure not only that the contents are the same but also the order assertListEquals(fullList + "[parsed]", builtin, parsed); assertListEquals(fullList + "[unsupported]", unknown, missing); @@ -237,8 +237,8 @@ public class BuiltinCiphersTest extends BaseTestSupport { @Test public void testResolveFactoryOnBuiltinValues() { for (NamedFactory<Cipher> expected : BuiltinCiphers.VALUES) { - String name=expected.getName(); - NamedFactory<Cipher> actual=BuiltinCiphers.resolveFactory(name); + String name = expected.getName(); + NamedFactory<Cipher> actual = BuiltinCiphers.resolveFactory(name); assertSame(name, expected, actual); } } @@ -249,20 +249,20 @@ public class BuiltinCiphersTest extends BaseTestSupport { try { BuiltinCiphers.registerExtension(expected); fail("Unexpected sucess for " + expected.getName()); - } catch(IllegalArgumentException e) { + } catch (IllegalArgumentException e) { // expected - ignored } } } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testNotAllowedToOverrideRegisteredFactories() { - CipherFactory expected=Mockito.mock(CipherFactory.class); + CipherFactory expected = Mockito.mock(CipherFactory.class); Mockito.when(expected.getName()).thenReturn(getCurrentTestName()); - String name=expected.getName(); + String name = expected.getName(); try { - for (int index=1; index <= Byte.SIZE; index++) { + for (int index = 1; index <= Byte.SIZE; index++) { BuiltinCiphers.registerExtension(expected); assertEquals("Unexpected success at attempt #" + index, 1, index); } @@ -273,32 +273,21 @@ public class BuiltinCiphersTest extends BaseTestSupport { @Test public void testResolveFactoryOnRegisteredExtension() { - CipherFactory expected=Mockito.mock(CipherFactory.class); + CipherFactory expected = Mockito.mock(CipherFactory.class); Mockito.when(expected.getName()).thenReturn(getCurrentTestName()); - String name=expected.getName(); + String name = expected.getName(); try { assertNull("Extension already registered", BuiltinCiphers.resolveFactory(name)); BuiltinCiphers.registerExtension(expected); - NamedFactory<Cipher> actual=BuiltinCiphers.resolveFactory(name); + NamedFactory<Cipher> actual = BuiltinCiphers.resolveFactory(name); assertSame("Mismatched resolved instance", expected, actual); } finally { - NamedFactory<Cipher> actual=BuiltinCiphers.unregisterExtension(name); + NamedFactory<Cipher> actual = BuiltinCiphers.unregisterExtension(name); assertSame("Mismatched unregistered instance", expected, actual); assertNull("Extension not un-registered", BuiltinCiphers.resolveFactory(name)); } } - @Test - public void testFac2NamedTransformer() { - assertNull("Invalid null transformation", CipherFactory.FAC2NAMED.transform(null)); - for (CipherFactory expected : BuiltinCiphers.VALUES) { - NamedFactory<Cipher> actual=CipherFactory.FAC2NAMED.transform(expected); - assertSame("Mismatched transformed instance for " + expected.getName(), expected, actual); - } - - CipherFactory mock=Mockito.mock(CipherFactory.class); - assertSame("Mismatched transformed mocked instance", mock, CipherFactory.FAC2NAMED.transform(mock)); - } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/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 2c69afb..260746d 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 @@ -27,6 +27,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import com.jcraft.jsch.JSch; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.common.NamedResource; import org.apache.sshd.common.random.Random; @@ -46,8 +47,6 @@ import org.junit.runners.MethodSorters; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import com.jcraft.jsch.JSch; - /** * Test Cipher algorithms. * @@ -63,23 +62,23 @@ public class CipherTest extends BaseTestSupport { */ private static final List<Object[]> PARAMETERS = Collections.unmodifiableList(Arrays.asList( - new Object[] { BuiltinCiphers.aes128cbc, com.jcraft.jsch.jce.AES128CBC.class, NUM_LOADTEST_ROUNDS }, - new Object[] { BuiltinCiphers.tripledescbc, com.jcraft.jsch.jce.TripleDESCBC.class, NUM_LOADTEST_ROUNDS }, - new Object[] { BuiltinCiphers.blowfishcbc, com.jcraft.jsch.jce.BlowfishCBC.class, NUM_LOADTEST_ROUNDS }, - new Object[] { BuiltinCiphers.aes192cbc, com.jcraft.jsch.jce.AES192CBC.class, NUM_LOADTEST_ROUNDS }, - new Object[] { BuiltinCiphers.aes256cbc, com.jcraft.jsch.jce.AES256CBC.class, NUM_LOADTEST_ROUNDS } - )); + new Object[]{BuiltinCiphers.aes128cbc, com.jcraft.jsch.jce.AES128CBC.class, NUM_LOADTEST_ROUNDS}, + new Object[]{BuiltinCiphers.tripledescbc, com.jcraft.jsch.jce.TripleDESCBC.class, NUM_LOADTEST_ROUNDS}, + new Object[]{BuiltinCiphers.blowfishcbc, com.jcraft.jsch.jce.BlowfishCBC.class, NUM_LOADTEST_ROUNDS}, + new Object[]{BuiltinCiphers.aes192cbc, com.jcraft.jsch.jce.AES192CBC.class, NUM_LOADTEST_ROUNDS}, + new Object[]{BuiltinCiphers.aes256cbc, com.jcraft.jsch.jce.AES256CBC.class, NUM_LOADTEST_ROUNDS} + )); @SuppressWarnings("synthetic-access") - private static final List<NamedResource> TEST_CIPHERS = + 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); } }); @@ -105,14 +104,14 @@ public class CipherTest extends BaseTestSupport { @Test public void testBuiltinCipherSession() throws Exception { Assume.assumeTrue("No internal support for " + builtInCipher.getName(), builtInCipher.isSupported() && checkCipher(jschCipher.getName())); - - try(SshServer sshd = SshServer.setUpDefaultServer()) { + + try (SshServer sshd = SshServer.setUpDefaultServer()) { sshd.setKeyPairProvider(Utils.createTestHostKeyProvider()); sshd.setCipherFactories(Arrays.<NamedFactory<org.apache.sshd.common.cipher.Cipher>>asList(builtInCipher)); sshd.setShellFactory(new EchoShellFactory()); sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE); sshd.start(); - + try { runJschTest(sshd.getPort()); } finally { @@ -129,14 +128,14 @@ public class CipherTest extends BaseTestSupport { com.jcraft.jsch.Session s = sch.getSession(getCurrentTestName(), "localhost", port); s.setUserInfo(new SimpleUserInfo(getCurrentTestName())); s.connect(); - + try { com.jcraft.jsch.Channel c = s.openChannel("shell"); c.connect(); - - try(OutputStream os = c.getOutputStream(); - InputStream is = c.getInputStream()) { - String expected = "this is my command\n"; + + try (OutputStream os = c.getOutputStream(); + InputStream is = c.getInputStream()) { + String expected = "this is my command\n"; byte[] expData = expected.getBytes(StandardCharsets.UTF_8); byte[] actData = new byte[expData.length + Long.SIZE /* just in case */]; for (int i = 0; i < 10; i++) { @@ -179,16 +178,15 @@ public class CipherTest extends BaseTestSupport { System.err.println(factory.getName() + "[" + numRounds + "]: " + (t1 - t0) + " ms"); } - static boolean checkCipher(String cipher){ - try{ - Class<?> c=Class.forName(cipher); - com.jcraft.jsch.Cipher _c = (com.jcraft.jsch.Cipher)(c.newInstance()); + static boolean checkCipher(String cipher) { + try { + Class<?> c = Class.forName(cipher); + com.jcraft.jsch.Cipher _c = (com.jcraft.jsch.Cipher) (c.newInstance()); _c.init(com.jcraft.jsch.Cipher.ENCRYPT_MODE, new byte[_c.getBlockSize()], new byte[_c.getIVSize()]); return true; - } - catch(Exception e){ + } catch (Exception e) { System.err.println("checkCipher(" + cipher + ") " + e.getClass().getSimpleName() + ": " + e.getMessage()); return false; } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/sshd-core/src/test/java/org/apache/sshd/common/cipher/ECCurvesTest.java ---------------------------------------------------------------------- diff --git a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ECCurvesTest.java b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ECCurvesTest.java index 07b3bce..ae11701 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/cipher/ECCurvesTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/cipher/ECCurvesTest.java @@ -40,7 +40,7 @@ public class ECCurvesTest extends BaseTestSupport { public void testFromName() { for (ECCurves expected : ECCurves.VALUES) { String name = expected.getName(); - for (int index=0; index < name.length(); index++) { + for (int index = 0; index < name.length(); index++) { ECCurves actual = ECCurves.fromCurveName(name); assertSame(name, expected, actual); name = shuffleCase(name); @@ -56,7 +56,7 @@ public class ECCurvesTest extends BaseTestSupport { assertNotNull("No curve for listed name=" + name, c); assertTrue("Duplicated listed name: " + name, listed.add(c)); } - + assertEquals("Mismatched listed vs. values", ECCurves.VALUES, listed); } @@ -82,14 +82,14 @@ public class ECCurvesTest extends BaseTestSupport { public void testFromKeyType() { for (ECCurves expected : ECCurves.VALUES) { String keyType = expected.getKeyType(); - for (int index=0; index < keyType.length(); index++) { + for (int index = 0; index < keyType.length(); index++) { ECCurves actual = ECCurves.fromKeyType(keyType); assertSame(keyType, expected, actual); keyType = shuffleCase(keyType); } } } - + @Test public void testAllKeyTypesListed() { Set<ECCurves> listed = EnumSet.noneOf(ECCurves.class); @@ -98,7 +98,7 @@ public class ECCurvesTest extends BaseTestSupport { assertNotNull("No curve for listed key type=" + name, c); assertTrue("Duplicated listed key type: " + name, listed.add(c)); } - + assertEquals("Mismatched listed vs. values", ECCurves.VALUES, listed); } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/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 88cbcc8..45e5233 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 @@ -50,41 +50,42 @@ public class BuiltinCompressionsTest extends BaseTestSupport { @Test public void testFromFactoryName() { for (BuiltinCompressions expected : BuiltinCompressions.VALUES) { - String name=expected.getName(); + String name = expected.getName(); - for (int index=0; index < name.length(); index++) { - BuiltinCompressions actual=BuiltinCompressions.fromFactoryName(name); + for (int index = 0; index < name.length(); index++) { + BuiltinCompressions actual = BuiltinCompressions.fromFactoryName(name); assertSame(name, expected, actual); name = shuffleCase(name); } } } + @Test public void testAllConstantsCovered() throws Exception { - Set<BuiltinCompressions> avail=EnumSet.noneOf(BuiltinCompressions.class); - Field[] fields=BuiltinCompressions.Constants.class.getFields(); + Set<BuiltinCompressions> avail = EnumSet.noneOf(BuiltinCompressions.class); + Field[] fields = BuiltinCompressions.Constants.class.getFields(); for (Field f : fields) { - String name=(String) f.get(null); - BuiltinCompressions value=BuiltinCompressions.fromFactoryName(name); + String name = (String) f.get(null); + BuiltinCompressions value = BuiltinCompressions.fromFactoryName(name); assertNotNull("No match found for " + name, value); assertTrue(name + " re-specified", avail.add(value)); } - + assertEquals("Incomplete coverage", BuiltinCompressions.VALUES, avail); } @Test public void testParseCompressionsList() { - List<String> builtin=NamedResource.Utils.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++) { + List<String> builtin = NamedResource.Utils.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()); - for (int bIndex=0, uIndex=0; (bIndex < builtin.size()) || (uIndex < unknown.size()); ) { - boolean useBuiltin=false; + + List<String> weavedList = new ArrayList<String>(builtin.size() + unknown.size()); + for (int bIndex = 0, uIndex = 0; (bIndex < builtin.size()) || (uIndex < unknown.size()); ) { + boolean useBuiltin = false; if (bIndex < builtin.size()) { useBuiltin = (uIndex < unknown.size()) ? rnd.nextBoolean() : true; } @@ -92,17 +93,17 @@ public class BuiltinCompressionsTest extends BaseTestSupport { if (useBuiltin) { weavedList.add(builtin.get(bIndex)); bIndex++; - } else if (uIndex < unknown.size()){ + } else if (uIndex < unknown.size()) { weavedList.add(unknown.get(uIndex)); uIndex++; } } - String fullList=GenericUtils.join(weavedList, ','); - ParseResult result=BuiltinCompressions.parseCompressionsList(fullList); - List<String> parsed=NamedResource.Utils.getNameList(result.getParsedFactories()); - List<String> missing=result.getUnsupportedFactories(); - + String fullList = GenericUtils.join(weavedList, ','); + ParseResult result = BuiltinCompressions.parseCompressionsList(fullList); + List<String> parsed = NamedResource.Utils.getNameList(result.getParsedFactories()); + List<String> missing = result.getUnsupportedFactories(); + // makes sure not only that the contents are the same but also the order assertListEquals(fullList + "[parsed]", builtin, parsed); assertListEquals(fullList + "[unsupported]", unknown, missing); @@ -112,8 +113,8 @@ public class BuiltinCompressionsTest extends BaseTestSupport { @Test public void testResolveFactoryOnBuiltinValues() { for (NamedFactory<Compression> expected : BuiltinCompressions.VALUES) { - String name=expected.getName(); - NamedFactory<Compression> actual=BuiltinCompressions.resolveFactory(name); + String name = expected.getName(); + NamedFactory<Compression> actual = BuiltinCompressions.resolveFactory(name); assertSame(name, expected, actual); } } @@ -124,20 +125,20 @@ public class BuiltinCompressionsTest extends BaseTestSupport { try { BuiltinCompressions.registerExtension(expected); fail("Unexpected sucess for " + expected.getName()); - } catch(IllegalArgumentException e) { + } catch (IllegalArgumentException e) { // expected - ignored } } } - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void testNotAllowedToOverrideRegisteredFactories() { - CompressionFactory expected=Mockito.mock(CompressionFactory.class); + CompressionFactory expected = Mockito.mock(CompressionFactory.class); Mockito.when(expected.getName()).thenReturn(getCurrentTestName()); - String name=expected.getName(); + String name = expected.getName(); try { - for (int index=1; index <= Byte.SIZE; index++) { + for (int index = 1; index <= Byte.SIZE; index++) { BuiltinCompressions.registerExtension(expected); assertEquals("Unexpected success at attempt #" + index, 1, index); } @@ -148,32 +149,21 @@ public class BuiltinCompressionsTest extends BaseTestSupport { @Test public void testResolveFactoryOnRegisteredExtension() { - CompressionFactory expected=Mockito.mock(CompressionFactory.class); + CompressionFactory expected = Mockito.mock(CompressionFactory.class); Mockito.when(expected.getName()).thenReturn(getCurrentTestName()); - String name=expected.getName(); + String name = expected.getName(); try { assertNull("Extension already registered", BuiltinCompressions.resolveFactory(name)); BuiltinCompressions.registerExtension(expected); - NamedFactory<Compression> actual=BuiltinCompressions.resolveFactory(name); + NamedFactory<Compression> actual = BuiltinCompressions.resolveFactory(name); assertSame("Mismatched resolved instance", expected, actual); } finally { - NamedFactory<Compression> actual=BuiltinCompressions.unregisterExtension(name); + NamedFactory<Compression> actual = BuiltinCompressions.unregisterExtension(name); assertSame("Mismatched unregistered instance", expected, actual); assertNull("Extension not un-registered", BuiltinCompressions.resolveFactory(name)); } } - @Test - public void testFac2NamedTransformer() { - assertNull("Invalid null transformation", CompressionFactory.FAC2NAMED.transform(null)); - for (CompressionFactory expected : BuiltinCompressions.VALUES) { - NamedFactory<Compression> actual=CompressionFactory.FAC2NAMED.transform(expected); - assertSame("Mismatched transformed instance for " + expected.getName(), expected, actual); - } - - CompressionFactory mock=Mockito.mock(CompressionFactory.class); - assertSame("Mismatched transformed mocked instance", mock, CompressionFactory.FAC2NAMED.transform(mock)); - } } http://git-wip-us.apache.org/repos/asf/mina-sshd/blob/17f2d627/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 f59884d..3345bda 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 @@ -23,6 +23,7 @@ import java.io.OutputStream; import java.nio.charset.StandardCharsets; import java.util.Arrays; +import com.jcraft.jsch.JSch; import org.apache.sshd.common.NamedFactory; import org.apache.sshd.server.SshServer; import org.apache.sshd.util.BaseTestSupport; @@ -36,8 +37,6 @@ import org.junit.FixMethodOrder; import org.junit.Test; import org.junit.runners.MethodSorters; -import com.jcraft.jsch.JSch; - /** * Test compression algorithms. * @@ -73,9 +72,9 @@ public class CompressionTest extends BaseTestSupport { sshd.setShellFactory(new EchoShellFactory()); sshd.setPasswordAuthenticator(BogusPasswordAuthenticator.INSTANCE); sshd.start(); - JSch.setConfig("compression.s2c", "[email protected],zlib,none"); - JSch.setConfig("compression.c2s", "[email protected],zlib,none"); - JSch.setConfig("zlib", com.jcraft.jsch.jcraft.Compression.class.getName()); + JSch.setConfig("compression.s2c", "[email protected],zlib,none"); + JSch.setConfig("compression.c2s", "[email protected],zlib,none"); + JSch.setConfig("zlib", com.jcraft.jsch.jcraft.Compression.class.getName()); JSch.setConfig("[email protected]", com.jcraft.jsch.jcraft.Compression.class.getName()); } @@ -98,11 +97,11 @@ public class CompressionTest extends BaseTestSupport { try { com.jcraft.jsch.Channel c = s.openChannel("shell"); c.connect(); - try(OutputStream os = c.getOutputStream(); + try (OutputStream os = c.getOutputStream(); InputStream is = c.getInputStream()) { - final String STR="this is my command\n"; - final byte[] bytes=STR.getBytes(StandardCharsets.UTF_8); - byte[] data=new byte[bytes.length + Long.SIZE]; + final String STR = "this is my command\n"; + final byte[] bytes = STR.getBytes(StandardCharsets.UTF_8); + byte[] data = new byte[bytes.length + Long.SIZE]; for (int i = 0; i < 10; i++) { os.write(bytes); os.flush(); @@ -113,7 +112,7 @@ public class CompressionTest extends BaseTestSupport { } } finally { c.disconnect(); - } + } } finally { s.disconnect(); }
