You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2023/04/05 23:22:55 UTC
[commons-fileupload] branch master updated: Use assertThrows or propagate exceptions out of test methods
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/commons-fileupload.git
The following commit(s) were added to refs/heads/master by this push:
new b717222 Use assertThrows or propagate exceptions out of test methods
b717222 is described below
commit b71722219a8ed81c5f6c14a178370811885518ff
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Wed Apr 5 19:22:53 2023 -0400
Use assertThrows or propagate exceptions out of test methods
---
.../fileupload2/DiskFileItemSerializeTest.java | 12 ++----------
.../org/apache/commons/fileupload2/SizesTest.java | 22 +++++++---------------
2 files changed, 9 insertions(+), 25 deletions(-)
diff --git a/src/test/java/org/apache/commons/fileupload2/DiskFileItemSerializeTest.java b/src/test/java/org/apache/commons/fileupload2/DiskFileItemSerializeTest.java
index 703875a..7aa0fa4 100644
--- a/src/test/java/org/apache/commons/fileupload2/DiskFileItemSerializeTest.java
+++ b/src/test/java/org/apache/commons/fileupload2/DiskFileItemSerializeTest.java
@@ -152,11 +152,7 @@ public class DiskFileItemSerializeTest {
// Check state is as expected
assertFalse(item.isInMemory(), "Initial: in memory");
assertEquals(item.getSize(), testFieldValueBytes.length, "Initial: size");
- try {
- compareBytes("Initial", item.get(), testFieldValueBytes);
- } catch (UncheckedIOException e) {
- fail("Unexpected IOException", e);
- }
+ compareBytes("Initial", item.get(), testFieldValueBytes);
testWritingToFile(item, testFieldValueBytes);
item.delete();
@@ -188,11 +184,7 @@ public class DiskFileItemSerializeTest {
// Check state is as expected
assertTrue(item.isInMemory(), "Initial: in memory");
assertEquals(item.getSize(), testFieldValueBytes.length, "Initial: size");
- try {
- compareBytes("Initial", item.get(), testFieldValueBytes);
- } catch (UncheckedIOException e) {
- fail("Unexpected IOException", e);
- }
+ compareBytes("Initial", item.get(), testFieldValueBytes);
testWritingToFile(item, testFieldValueBytes);
item.delete();
}
diff --git a/src/test/java/org/apache/commons/fileupload2/SizesTest.java b/src/test/java/org/apache/commons/fileupload2/SizesTest.java
index 3099fd5..5fe6b31 100644
--- a/src/test/java/org/apache/commons/fileupload2/SizesTest.java
+++ b/src/test/java/org/apache/commons/fileupload2/SizesTest.java
@@ -18,6 +18,7 @@ package org.apache.commons.fileupload2;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
@@ -267,24 +268,15 @@ public class SizesTest {
}
// the second item is over the size max, thus we expect an error
- try {
- // the header is still within size max -> this shall still succeed
- assertTrue(it.hasNext());
- } catch (final FileUploadSizeException e) {
- fail();
- }
-
- item = it.next();
+ // the header is still within size max -> this shall still succeed
+ assertTrue(it.hasNext());
- try {
+ assertThrows(FileUploadException.class, () -> {
+ final FileItemStream item2 = it.next();
try (final ByteArrayOutputStream baos = new ByteArrayOutputStream();
- final InputStream stream = item.openStream()) {
+ final InputStream stream = item2.openStream()) {
IOUtils.copy(stream, baos);
}
- fail();
- } catch (final FileUploadException e) {
- // expected
- }
+ });
}
-
}