This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch 1.x
in repository https://gitbox.apache.org/repos/asf/commons-fileupload.git

commit fa91cf078784f51ab7837fcecae456c0741d6773
Author: Gary D. Gregory <garydgreg...@gmail.com>
AuthorDate: Thu Jun 5 07:54:26 2025 -0400

    Use assertThrows
---
 .../java/org/apache/commons/fileupload/FileUploadTest.java    | 10 ++--------
 .../fileupload/util/mime/QuotedPrintableDecoderTestCase.java  | 11 ++++-------
 2 files changed, 6 insertions(+), 15 deletions(-)

diff --git a/src/test/java/org/apache/commons/fileupload/FileUploadTest.java 
b/src/test/java/org/apache/commons/fileupload/FileUploadTest.java
index af119776..80d6d2a1 100644
--- a/src/test/java/org/apache/commons/fileupload/FileUploadTest.java
+++ b/src/test/java/org/apache/commons/fileupload/FileUploadTest.java
@@ -20,6 +20,7 @@ import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -33,7 +34,6 @@ import 
org.apache.commons.fileupload.portlet.PortletFileUploadTest;
 import org.apache.commons.fileupload.servlet.ServletFileUpload;
 import org.apache.commons.fileupload.servlet.ServletFileUploadTest;
 import org.apache.commons.fileupload.util.Streams;
-import org.junit.Assert;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 import org.junit.runners.Parameterized;
@@ -486,13 +486,7 @@ public class FileUploadTest {
             Streams.copy(stream, baos, true);
         }
 
-        try {
-            item.openStream();
-            Assert.fail("Attempt to open a closed stream did not throw an 
exception");
-        } catch (final IOException ioe) {
-            // Expected
-        }
-
+        assertThrows(IOException.class, item::openStream, "Attempt to open a 
closed stream did not throw an exception");
         // Should only be one item
         assertFalse(it.hasNext());
     }
diff --git 
a/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java
 
b/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java
index 0b089124..e8436c91 100644
--- 
a/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java
+++ 
b/src/test/java/org/apache/commons/fileupload/util/mime/QuotedPrintableDecoderTestCase.java
@@ -19,6 +19,7 @@ package org.apache.commons.fileupload.util.mime;
 import static org.junit.Assert.assertArrayEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
@@ -47,13 +48,9 @@ public final class QuotedPrintableDecoderTestCase {
     private static void assertIOException(final String messageText, final 
String encoded) throws UnsupportedEncodingException {
         final ByteArrayOutputStream out = new 
ByteArrayOutputStream(encoded.length());
         final byte[] encodedData = encoded.getBytes(US_ASCII_CHARSET);
-        try {
-            QuotedPrintableDecoder.decode(encodedData, out);
-            fail("Expected IOException");
-        } catch (final IOException e) {
-            final String em = e.getMessage();
-            assertTrue("Expected to find " + messageText + " in '" + em + "'", 
em.contains(messageText));
-        }
+        final IOException e = assertThrows(IOException.class, () -> 
QuotedPrintableDecoder.decode(encodedData, out));
+        final String em = e.getMessage();
+        assertTrue("Expected to find " + messageText + " in '" + em + "'", 
em.contains(messageText));
     }
 
     @Test

Reply via email to