Code example for PipedInputStream

    private EnterPasswordProcessObserver observer;
    private PipedInputStream handleOut;
    protected void setUp() throws Exception { 
        PipedOutputStream out = new PipedOutputStream();
        handleOut = new PipedInputStream(out);
        observer = new EnterPasswordProcessObserver(out, "blabla");
    public void testAnswersPromptAtColon() throws IOException { 
        observer.processWroteToStream("text ohne doppelpunkt");
        assertEquals(0, handleOut.available());
        observer.processWroteToStream("\nneue zeile ohne doppelpunkt\n");
        assertEquals(0, handleOut.available());
        observer.processWroteToStream("prompt: ");
        assertEquals("blabla".length(), handleOut.available());
        byte[] buffer = new byte[100];
        int chars =;
        assertEquals("blabla", new String(buffer,0, chars));
Connect your IDE to all the code out there  Get Codota for Java