Skip to content
Permalink
Browse files
FILEUPLOAD-326 - Simplify Assertion
  • Loading branch information
arturobernalg committed May 1, 2021
1 parent a4186a0 commit 95c77d5eac4c228d648d30c4ea0c31561306aa69
Showing 4 changed files with 13 additions and 11 deletions.
@@ -16,6 +16,7 @@
*/
package org.apache.commons.fileupload2;

import static org.junit.jupiter.api.Assertions.assertArrayEquals;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@@ -27,7 +28,6 @@
import java.io.IOException;
import java.io.OutputStream;
import java.io.UncheckedIOException;
import java.util.Arrays;
import org.apache.commons.io.FileUtils;


@@ -126,7 +126,7 @@ public void testBelowThreshold() {
assertTrue(item.isInMemory());
assertEquals(item.getSize(), testFieldValueBytes.length);
try {
assertTrue(Arrays.equals(item.get(), testFieldValueBytes));
assertArrayEquals(item.get(), testFieldValueBytes);
} catch (UncheckedIOException e) {
fail("Unexpected IOException", e);
}
@@ -189,7 +189,7 @@ public void doTestAboveThreshold(final File repository) {
assertFalse(item.isInMemory());
assertEquals(item.getSize(), testFieldValueBytes.length);
try {
assertTrue(Arrays.equals(item.get(), testFieldValueBytes));
assertArrayEquals(item.get(), testFieldValueBytes);
} catch (UncheckedIOException e) {
fail("Unexpected IOException", e);
}
@@ -35,27 +35,27 @@ public void testParsing() {
"test; test1 = stuff ; test2 = \"stuff; stuff\"; test3=\"stuff";
final ParameterParser parser = new ParameterParser();
Map<String, String> params = parser.parse(s, ';');
assertEquals(null, params.get("test"));
assertNull(params.get("test"));
assertEquals("stuff", params.get("test1"));
assertEquals("stuff; stuff", params.get("test2"));
assertEquals("\"stuff", params.get("test3"));

params = parser.parse(s, new char[] { ',', ';' });
assertEquals(null, params.get("test"));
assertNull(params.get("test"));
assertEquals("stuff", params.get("test1"));
assertEquals("stuff; stuff", params.get("test2"));
assertEquals("\"stuff", params.get("test3"));

s = " test , test1=stuff , , test2=, test3, ";
params = parser.parse(s, ',');
assertEquals(null, params.get("test"));
assertNull(params.get("test"));
assertEquals("stuff", params.get("test1"));
assertEquals(null, params.get("test2"));
assertEquals(null, params.get("test3"));
assertNull(params.get("test2"));
assertNull(params.get("test3"));

s = " test";
params = parser.parse(s, ';');
assertEquals(null, params.get("test"));
assertNull(params.get("test"));

s = " ";
params = parser.parse(s, ';');
@@ -17,6 +17,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.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@@ -17,6 +17,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.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

@@ -264,7 +265,7 @@ public void testInvalidFileNameException() throws Exception {
fail("Expected exception");
} catch (final InvalidFileNameException e) {
assertEquals(fileName, e.getName());
assertTrue(e.getMessage().indexOf(fileName) == -1);
assertEquals(-1, e.getMessage().indexOf(fileName));
assertTrue(e.getMessage().indexOf("foo.exe\\0.png") != -1);
}

@@ -273,7 +274,7 @@ public void testInvalidFileNameException() throws Exception {
fail("Expected exception");
} catch (final InvalidFileNameException e) {
assertEquals(fileName, e.getName());
assertTrue(e.getMessage().indexOf(fileName) == -1);
assertEquals(-1, e.getMessage().indexOf(fileName));
assertTrue(e.getMessage().indexOf("foo.exe\\0.png") != -1);
}
}

0 comments on commit 95c77d5

Please sign in to comment.