This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/mina-sshd.git
commit f0f2e4c3e4dac0d13a7fc0f43bc930736d89fa0a Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Thu May 30 16:49:32 2024 -0400 Use assertThrows() --- .../apache/sshd/common/mac/BuiltinMacsTest.java | 10 ++----- .../common/signature/BuiltinSignaturesTest.java | 10 ++----- .../common/util/io/input/EmptyInputStreamTest.java | 7 +---- .../common/util/io/input/LimitInputStreamTest.java | 7 +---- .../common/util/io/input/NullInputStreamTest.java | 7 +---- .../util/io/output/NullOutputStreamTest.java | 34 +++++----------------- .../sshd/common/channel/WindowTimeoutTest.java | 8 ++--- 7 files changed, 16 insertions(+), 67 deletions(-) diff --git a/sshd-common/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java b/sshd-common/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java index d86bb0d9b..f56785eda 100644 --- a/sshd-common/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java +++ b/sshd-common/src/test/java/org/apache/sshd/common/mac/BuiltinMacsTest.java @@ -120,14 +120,8 @@ public class BuiltinMacsTest extends JUnitTestSupport { @Test public void testNotAllowedToRegisterBuiltinFactories() { - for (MacFactory expected : BuiltinMacs.VALUES) { - try { - BuiltinMacs.registerExtension(expected); - fail("Unexpected success for " + expected.getName()); - } catch (IllegalArgumentException e) { - // expected - ignored - } - } + BuiltinMacs.VALUES.forEach(expected -> assertThrows("Unexpected success for " + expected.getName(), + IllegalArgumentException.class, () -> BuiltinMacs.registerExtension(expected))); } @Test(expected = IllegalArgumentException.class) diff --git a/sshd-common/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java b/sshd-common/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java index d99a8f8dd..6fd1b4884 100644 --- a/sshd-common/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java +++ b/sshd-common/src/test/java/org/apache/sshd/common/signature/BuiltinSignaturesTest.java @@ -103,14 +103,8 @@ public class BuiltinSignaturesTest extends JUnitTestSupport { @Test public void testNotAllowedToRegisterBuiltinFactories() { - for (SignatureFactory expected : BuiltinSignatures.VALUES) { - try { - BuiltinSignatures.registerExtension(expected); - fail("Unexpected success for " + expected.getName()); - } catch (IllegalArgumentException e) { - // expected - ignored - } - } + BuiltinSignatures.VALUES.forEach(expected -> assertThrows("Unexpected success for " + expected.getName(), + IllegalArgumentException.class, () -> BuiltinSignatures.registerExtension(expected))); } @Test(expected = IllegalArgumentException.class) diff --git a/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/EmptyInputStreamTest.java b/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/EmptyInputStreamTest.java index 2958f0e2a..df9d781f7 100644 --- a/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/EmptyInputStreamTest.java +++ b/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/EmptyInputStreamTest.java @@ -62,12 +62,7 @@ public class EmptyInputStreamTest extends JUnitTestSupport { private void testEmptyInputStream(String message, InputStream in, boolean errorExpected) { assertFalse(message + ": unexpected markSupported()", in.markSupported()); - try { - in.mark(Long.SIZE); - fail(message + ": unexpected mark success"); - } catch (UnsupportedOperationException e) { - // expected - } + assertThrows(message + ": unexpected mark success", UnsupportedOperationException.class, () -> in.mark(Long.SIZE)); try { int len = in.available(); diff --git a/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/LimitInputStreamTest.java b/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/LimitInputStreamTest.java index 4bd71db74..51e801b9a 100644 --- a/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/LimitInputStreamTest.java +++ b/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/LimitInputStreamTest.java @@ -74,12 +74,7 @@ public class LimitInputStreamTest extends JUnitTestSupport { limited.close(); assertFalse("Limited stream still marked as open", limited.isOpen()); - try { - readLen = limited.read(); - fail("Unexpected one byte read success after close"); - } catch (IOException e) { - // expected - } + assertThrows("Unexpected one byte read success after close", IOException.class, limited::read); try { readLen = limited.read(actual); diff --git a/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/NullInputStreamTest.java b/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/NullInputStreamTest.java index 0e8ee801d..b61841fad 100644 --- a/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/NullInputStreamTest.java +++ b/sshd-common/src/test/java/org/apache/sshd/common/util/io/input/NullInputStreamTest.java @@ -108,11 +108,6 @@ public class NullInputStreamTest extends JUnitTestSupport { } catch (IOException e) { // expected } - try { - stream.reset(); - fail("Unexpected reset success"); - } catch (EOFException e) { - // expected - } + assertThrows("Unexpected reset success", EOFException.class, stream::reset); } } diff --git a/sshd-common/src/test/java/org/apache/sshd/common/util/io/output/NullOutputStreamTest.java b/sshd-common/src/test/java/org/apache/sshd/common/util/io/output/NullOutputStreamTest.java index 0a8872ea5..3958bebc2 100644 --- a/sshd-common/src/test/java/org/apache/sshd/common/util/io/output/NullOutputStreamTest.java +++ b/sshd-common/src/test/java/org/apache/sshd/common/util/io/output/NullOutputStreamTest.java @@ -45,36 +45,16 @@ public class NullOutputStreamTest extends JUnitTestSupport { NullOutputStream stream = new NullOutputStream(); stream.close(); assertFalse("Stream not marked as closed", stream.isOpen()); - - try { - stream.write('a'); - fail("Unexpected single value write success"); - } catch (EOFException e) { - // expected - } + assertThrows("Unexpected single value write success", EOFException.class, () -> stream.write('a')); byte[] buf = new byte[Byte.SIZE]; - try { - Arrays.fill(buf, (byte) 0x41); - stream.write(buf); - fail("Unexpected full buffer write success"); - } catch (EOFException e) { - // expected - } + Arrays.fill(buf, (byte) 0x41); + assertThrows("Unexpected full buffer write success", EOFException.class, () -> stream.write(buf)); - try { - Arrays.fill(buf, (byte) 0x42); - stream.write(buf, buf.length / 2, (buf.length / 2) - 1); - fail("Unexpected partial buffer write success"); - } catch (EOFException e) { - // expected - } + Arrays.fill(buf, (byte) 0x42); + assertThrows("Unexpected full buffer write success", EOFException.class, + () -> stream.write(buf, buf.length / 2, (buf.length / 2) - 1)); - try { - stream.flush(); - fail("Unexpected flush success"); - } catch (EOFException e) { - // expected - } + assertThrows("Unexpected flush success", EOFException.class, stream::flush); } } diff --git a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java index 35bc0c6d4..9f7ddc510 100644 --- a/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java +++ b/sshd-core/src/test/java/org/apache/sshd/common/channel/WindowTimeoutTest.java @@ -140,12 +140,8 @@ public class WindowTimeoutTest extends BaseTestSupport { window.close(); assertFalse("Window not closed", window.isOpen()); - try { - window.waitAndConsume(2 * window.getSize(), MAX_WAIT_TIME); - fail("Unexpected closed wait success"); - } catch (WindowClosedException e) { - // expected - } + assertThrows("Unexpected closed wait success", WindowClosedException.class, + () -> window.waitAndConsume(2 * window.getSize(), MAX_WAIT_TIME)); } } }