From b6bca11499d4c6212e17bf3fc2ec9869f88de620 Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sun, 24 Jan 2021 12:04:58 -0500 Subject: [PATCH] Refactor. --- .../apache/commons/io/IOUtilsTestCase.java | 28 +++++++++---------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java index 9f7de4f0b2d..b662d26092f 100644 --- a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java +++ b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java @@ -509,33 +509,31 @@ public void testContentEquals_InputStream_InputStream() throws Exception { { assertTrue(IOUtils.contentEquals((InputStream) null, null)); } + final byte[] dataEmpty = "".getBytes(StandardCharsets.UTF_8); + final byte[] dataAbc = "ABC".getBytes(StandardCharsets.UTF_8); + final byte[] dataAbcd = "ABCD".getBytes(StandardCharsets.UTF_8); { - final ByteArrayInputStream input1 = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); + final ByteArrayInputStream input1 = new ByteArrayInputStream(dataEmpty); assertFalse(IOUtils.contentEquals(input1, null)); } { - final ByteArrayInputStream input1 = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); + final ByteArrayInputStream input1 = new ByteArrayInputStream(dataEmpty); assertFalse(IOUtils.contentEquals(null, input1)); } { - final ByteArrayInputStream input1 = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); + final ByteArrayInputStream input1 = new ByteArrayInputStream(dataEmpty); assertTrue(IOUtils.contentEquals(input1, input1)); } { - final ByteArrayInputStream input1 = new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)); + final ByteArrayInputStream input1 = new ByteArrayInputStream(dataAbc); assertTrue(IOUtils.contentEquals(input1, input1)); } - assertTrue(IOUtils.contentEquals(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)), - new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)))); - assertTrue(IOUtils.contentEquals( - new BufferedInputStream(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))), - new BufferedInputStream(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))))); - assertTrue(IOUtils.contentEquals(new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)), - new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)))); - assertFalse(IOUtils.contentEquals(new ByteArrayInputStream("ABCD".getBytes(StandardCharsets.UTF_8)), - new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)))); - assertFalse(IOUtils.contentEquals(new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)), - new ByteArrayInputStream("ABCD".getBytes(StandardCharsets.UTF_8)))); + assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(dataEmpty), new ByteArrayInputStream(dataEmpty))); + assertTrue(IOUtils.contentEquals(new BufferedInputStream(new ByteArrayInputStream(dataEmpty)), + new BufferedInputStream(new ByteArrayInputStream(dataEmpty)))); + assertTrue(IOUtils.contentEquals(new ByteArrayInputStream(dataAbc), new ByteArrayInputStream(dataAbc))); + assertFalse(IOUtils.contentEquals(new ByteArrayInputStream(dataAbcd), new ByteArrayInputStream(dataAbc))); + assertFalse(IOUtils.contentEquals(new ByteArrayInputStream(dataAbc), new ByteArrayInputStream(dataAbcd))); // Tests with larger inputs that DEFAULT_BUFFER_SIZE in case internal buffers are used. final byte[] bytes2XDefaultA = new byte[IOUtils.DEFAULT_BUFFER_SIZE * 2]; final byte[] bytes2XDefaultB = new byte[IOUtils.DEFAULT_BUFFER_SIZE * 2];