package expectj;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import junit.framework.TestCase;
import expectj.test.StagedStringProducer;

/**
 * Verify that the different expect() methods of {@link SpawnedProcess} work as expected.
 * @author johan.walles@gmail.com
 */
public class TestExpect extends TestCase
{
    /**
     * Generate a SpawnedProcess producing the indicated output on stdout.
     * @param strings The strings to print to stdout.  Strings will be produced with
     * 500ms between each.
     * @return A new SpawnedProcess.
     * @throws Exception when things go wrong.
     */
    private SpawnedProcess getSpawnedProcess(final String ... strings)
    throws Exception
    {
        return new ExpectJ("/dev/null", -1).spawn(new Spawnable() {
            public void stop() {
                // This method intentionally left blank
            }
        
            public void start() {
                // This method intentionally left blank
            }
        
            public boolean isClosed() {
                return false;
            }
        
            public OutputStream getOutputStream() {
                return null;
            }
        
            public InputStream getInputStream() {
                try {
                    return new StagedStringProducer(strings).getInputStream();
                } catch (IOException e) {
                    return null;
                }
            }
        
            public int getExitValue() throws ExpectJException {
                return 0;
            }
        
            public InputStream getErrorStream() {
                return null;
            }
        });
    }
    
    /**
     * Test that we can find a simple string.
     * @throws Exception if things go wrong.
     */
    public void testExpectString() throws Exception
    {
        SpawnedProcess testMe = getSpawnedProcess("flaska");
        testMe.expect("flaska");
    }
}

@@ -15,94 +15,8 @@
 j;%0A%0A
-import java.io.IOException;%0Aimport java.io.InputStream;%0Aimport java.io.OutputStream;%0A%0A
 impo
@@ -71,29 +71,24 @@
 .StagedS
-tringProducer
+pawnable
 ;%0A%0A/**%0A 
@@ -701,925 +701,31 @@
 ew S
-pawnable() %7B%0A            public void stop() %7B%0A                // This method intentionally left blank%0A            %7D%0A        %0A            public void start() %7B%0A                // This method intentionally left blank%0A            %7D%0A        %0A            public boolean isClosed() %7B%0A                return false;%0A            %7D%0A        %0A            public OutputStream getOutputStream() %7B%0A                return null;%0A            %7D%0A        %0A            public InputStream getInputStream() %7B%0A                try %7B%0A                    return new StagedStringProducer(strings).getInputStream();%0A                %7D catch (IOException e) %7B%0A                    return null;%0A                %7D%0A            %7D%0A        %0A            public int getExitValue() throws ExpectJException %7B%0A                return 0;%0A            %7D%0A        %0A            public InputStream getErrorStream() %7B%0A                return null;%0A            %7D%0A        %7D
+tagedSpawnable(strings)
 );%0A 
@@ -837,24 +837,24 @@
 ng.%0A     */%0A
-
     public v
@@ -875,16 +875,20 @@
 String()
+%0A   
  throws 

Put the staged spawnable in its own class.