Skip to content

Commit 9e801d9

Browse files
oscarlvpPascalSchumacher
authored andcommitted
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.
1 parent 8169401 commit 9e801d9

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

src/test/java/org/apache/commons/io/output/TeeOutputStreamTest.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,36 @@ public void testCloseMainIOException() {
8787
public void testTee() throws IOException {
8888
final ByteArrayOutputStream baos1 = new ByteArrayOutputStream();
8989
final ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
90+
final ByteArrayOutputStream expected = new ByteArrayOutputStream();
91+
9092
final TeeOutputStream tos = new TeeOutputStream(baos1, baos2);
9193
for (int i = 0; i < 20; i++) {
9294
tos.write(i);
95+
expected.write(i);
9396
}
94-
assertByteArrayEquals("TeeOutputStream.write(int)", baos1.toByteArray(), baos2.toByteArray());
97+
assertByteArrayEquals("TeeOutputStream.write(int)", expected.toByteArray(), baos1.toByteArray());
98+
assertByteArrayEquals("TeeOutputStream.write(int)", expected.toByteArray(), baos2.toByteArray());
9599

96100
final byte[] array = new byte[10];
97101
for (int i = 20; i < 30; i++) {
98102
array[i - 20] = (byte) i;
99103
}
100104
tos.write(array);
101-
assertByteArrayEquals("TeeOutputStream.write(byte[])", baos1.toByteArray(), baos2.toByteArray());
105+
expected.write(array);
106+
assertByteArrayEquals("TeeOutputStream.write(byte[])", expected.toByteArray(), baos1.toByteArray());
107+
assertByteArrayEquals("TeeOutputStream.write(byte[])", expected.toByteArray(), baos2.toByteArray());
102108

103109
for (int i = 25; i < 35; i++) {
104110
array[i - 25] = (byte) i;
105111
}
106112
tos.write(array, 5, 5);
107-
assertByteArrayEquals("TeeOutputStream.write(byte[], int, int)", baos1.toByteArray(), baos2.toByteArray());
113+
expected.write(array, 5, 5);
114+
assertByteArrayEquals("TeeOutputStream.write(byte[], int, int)", expected.toByteArray(), baos1.toByteArray());
115+
assertByteArrayEquals("TeeOutputStream.write(byte[], int, int)", expected.toByteArray(), baos2.toByteArray());
116+
117+
expected.flush();
118+
expected.close();
119+
108120
tos.flush();
109121
tos.close();
110122
}

0 commit comments

Comments
 (0)