diff options
author | Michael Dardis <git@md-5.net> | 2020-02-14 12:07:19 +1100 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2020-02-21 23:45:43 +0100 |
commit | 40555223594005481cba95d09b32c4f6bb5dcff3 (patch) | |
tree | 3cda0ef2390dbfa1dc1f55a1475c6add54b79478 /org.eclipse.jgit.test/tst | |
parent | f2b67be62aa02facd23a6b09a3b759abedcb9e10 (diff) | |
download | jgit-40555223594005481cba95d09b32c4f6bb5dcff3.tar.gz jgit-40555223594005481cba95d09b32c4f6bb5dcff3.zip |
Remove use of org.bouncycastle.util.io.TeeOutputStream
Bug: 559106
Change-Id: Ife06f21a00d258780a2030745738194098c631cf
Signed-off-by: Michael Dardis <git@md-5.net>
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TeeOutputStreamTest.java | 81 |
1 files changed, 81 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TeeOutputStreamTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TeeOutputStreamTest.java new file mode 100644 index 0000000000..bb1c974455 --- /dev/null +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/util/io/TeeOutputStreamTest.java @@ -0,0 +1,81 @@ +/* + * Copyright (C) 2020, Michael Dardis. and others + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Distribution License v. 1.0 which is available at + * https://www.eclipse.org/org/documents/edl-v10.php. + * + * SPDX-License-Identifier: BSD-3-Clause + */ +package org.eclipse.jgit.util.io; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.IOException; + +import org.eclipse.jgit.lib.Constants; +import org.junit.Test; + +public class TeeOutputStreamTest { + + @Test + public void test() throws IOException { + byte[] data = Constants.encode("Hello World"); + + TestOutput first = new TestOutput(); + TestOutput second = new TestOutput(); + try (TeeOutputStream tee = new TeeOutputStream(first, second)) { + tee.write(data); + assertArrayEquals("Stream output must match", first.toByteArray(), + second.toByteArray()); + + tee.write(1); + assertArrayEquals("Stream output must match", first.toByteArray(), + second.toByteArray()); + + tee.write(data, 1, 4); // Test partial write methods + assertArrayEquals("Stream output must match", first.toByteArray(), + second.toByteArray()); + } + assertTrue("First stream should be closed", first.closed); + assertTrue("Second stream should be closed", second.closed); + } + + @Test + public void testCloseException() { + TestOutput first = new TestOutput() { + @Override + public void close() throws IOException { + throw new IOException(); + } + + }; + TestOutput second = new TestOutput(); + + @SuppressWarnings("resource") + TeeOutputStream tee = new TeeOutputStream(first, second); + try { + tee.close(); + } catch (IOException ex) { + // Expected from first closed + } + assertFalse("First stream should not be closed", first.closed); + assertTrue("Second stream should still be closed if first close failed", + second.closed); + } + + private static class TestOutput extends ByteArrayOutputStream { + + private boolean closed; + + @Override + public void close() throws IOException { + closed = true; + super.close(); + } + } + +} |