/*
 * Copyright (c) 2013 Jean Niklas L'orange. All rights reserved.
 *
 * The use and distribution terms for this software are covered by the
 * Eclipse Public License 1.0 (http://opensource.org/licenses/eclipse-1.0.php)
 * which can be found in the file LICENSE at the root of this distribution.
 *
 * By using this software in any fashion, you are agreeing to be bound by
 * the terms of this license.
 *
 * You must not remove this notice, or any other, from this software.
 */

package com.hypirion.io;

import java.io.InputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;

import com.hypirion.io.Pipe;

import org.junit.Test;
import static org.junit.Assert.*;

public class PipeTest {

    /**
     * Tests that an InputStream with random ascii characters will be completely
     * piped through the pipe.
     */
    @Test(timeout=1000)
    public void testBasicStreamCapabilities() throws Exception {
        PipedOutputStream sink = new PipedOutputStream();
        PipedInputStream source = new PipedInputStream(sink);
        String inString = RandomStringUtils.randomAscii(37);
        InputStream inStream = IOUtils.toInputStream(inString);
        Pipe p = new Pipe(inStream, sink);
        p.start();
        p.join();
        inStream.close();
        sink.close();
        String outString = IOUtils.toString(source);
        source.close();
        assertEquals(inString, outString);
    }
}

@@ -1515,11 +1515,904 @@
 );%0A    %7D
+%0A%0A    /**%0A     * Test that multiple InputStreams with random ascii characters will be%0A     * completely piped through the pipe, and not close the OutputStream.%0A     */%0A    @Test(timeout=1000)%0A    public void testMultipleStreams() throws Exception %7B%0A        PipedOutputStream sink = new PipedOutputStream();%0A        PipedInputStream source = new PipedInputStream(sink);%0A        String totalString = %22%22;%0A        for (int i = 0; i %3C 10; i++) %7B%0A            String inString = RandomStringUtils.randomAscii(37);%0A            totalString += inString;%0A            InputStream inStream = IOUtils.toInputStream(inString);%0A            Pipe p = new Pipe(inStream, sink);%0A            p.start();%0A            p.join();%0A            inStream.close();%0A        %7D%0A        sink.close();%0A        String outString = IOUtils.toString(source);%0A        source.close();%0A        assertEquals(totalString, outString);%0A    %7D
 %0A%7D%0A

Test stream concatenation.