commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pascalschumac...@apache.org
Subject commons-io git commit: Strengthen TeeOutputStremTest.testTee with an expected result. Tee should not just repeat what's being written to both outputs, the output should also be the same as expected. For example, if the body of any of the write methods in
Date Fri, 08 Jun 2018 16:38:05 GMT
Repository: commons-io
Updated Branches:
  refs/heads/master 81694016b -> 9e801d916


Strengthen TeeOutputStremTest.testTee with an expected result.
Tee should not just repeat what's being written to both outputs,
the output should also be the same as expected. For example, if
the body of any of the write methods in TeeOutputStream is removed,
then the values written are the same (nothing) and the assertions
don't fail in the test. This is solved by adding an expected value
and checking both outputs against it.


Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/9e801d91
Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/9e801d91
Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/9e801d91

Branch: refs/heads/master
Commit: 9e801d916c3d163a4cfcc822e50dd75ac7cefcc5
Parents: 8169401
Author: oscarlvp <oscarlvp@gmail.com>
Authored: Thu May 31 11:32:19 2018 +0200
Committer: pascalschumacher <pascalschumacher@gmx.net>
Committed: Fri Jun 8 18:37:24 2018 +0200

----------------------------------------------------------------------
 .../commons/io/output/TeeOutputStreamTest.java    | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-io/blob/9e801d91/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java b/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java
index 97f65d0..44c9ac1 100644
--- a/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java
@@ -87,24 +87,36 @@ public class TeeOutputStreamTest {
     public void testTee() throws IOException {
         final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
         final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+        final ByteArrayOutputStream expected = new ByteArrayOutputStream();
+
         final TeeOutputStream tos = new TeeOutputStream(baos1, baos2);
         for (int i = 0; i < 20; i++) {
             tos.write(i);
+            expected.write(i);
         }
-        assertByteArrayEquals("TeeOutputStream.write(int)", baos1.toByteArray(), baos2.toByteArray());
+        assertByteArrayEquals("TeeOutputStream.write(int)", expected.toByteArray(), baos1.toByteArray());
+        assertByteArrayEquals("TeeOutputStream.write(int)", expected.toByteArray(), baos2.toByteArray());
 
         final byte[] array = new byte[10];
         for (int i = 20; i < 30; i++) {
             array[i - 20] = (byte) i;
         }
         tos.write(array);
-        assertByteArrayEquals("TeeOutputStream.write(byte[])", baos1.toByteArray(), baos2.toByteArray());
+        expected.write(array);
+        assertByteArrayEquals("TeeOutputStream.write(byte[])", expected.toByteArray(), baos1.toByteArray());
+        assertByteArrayEquals("TeeOutputStream.write(byte[])", expected.toByteArray(), baos2.toByteArray());
 
         for (int i = 25; i < 35; i++) {
             array[i - 25] = (byte) i;
         }
         tos.write(array, 5, 5);
-        assertByteArrayEquals("TeeOutputStream.write(byte[], int, int)", baos1.toByteArray(),
baos2.toByteArray());
+        expected.write(array, 5, 5);
+        assertByteArrayEquals("TeeOutputStream.write(byte[], int, int)", expected.toByteArray(),
baos1.toByteArray());
+        assertByteArrayEquals("TeeOutputStream.write(byte[], int, int)", expected.toByteArray(),
baos2.toByteArray());
+        
+        expected.flush();
+        expected.close();
+        
         tos.flush();
         tos.close();
     }


Mime
View raw message