From e1841ad5cbcdbf2af6df58d5dbd18f8807ca57cd Mon Sep 17 00:00:00 2001 From: Sharang Gupta Date: Wed, 28 Oct 2026 23:47:18 +0000 Subject: [PATCH] TestGZip: assert writeTo propagates IOException testCompressionIOExceptionLeavesOutputStreamOpen only verified that the output stream stays open inside the catch block. If writeTo swallowed the IOException, nothing was checked and the test still passed. --- .../java/org/apache/hc/client5/http/entity/TestGZip.java | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestGZip.java b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestGZip.java index 2938af5032..0cff6673dd 100644 --- a/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestGZip.java +++ b/httpclient5/src/test/java/org/apache/hc/client5/http/entity/TestGZip.java @@ -83,11 +83,8 @@ void testCompressionIOExceptionLeavesOutputStreamOpen() throws Exception { Mockito.doThrow(new IOException("Ooopsie")).when(in).writeTo(ArgumentMatchers.any()); try (final GzipCompressingEntity gzipe = new GzipCompressingEntity(in)) { final OutputStream out = Mockito.mock(OutputStream.class); - try { - gzipe.writeTo(out); - } catch (final IOException ex) { - Mockito.verify(out, Mockito.never()).close(); - } + Assertions.assertThrows(IOException.class, () -> gzipe.writeTo(out)); + Mockito.verify(out, Mockito.never()).close(); } }