mil.dod.th.ose.test/src/mil/dod/th/ose/test/FileInputStreamMocker.java
public static FileInputStream mockIt(String input)
    {
        FileInputStream stream = mock(FileInputStream.class);
        final ByteArrayInputStream arrayInput = new ByteArrayInputStream(input.getBytes());
        
        try
        {
            when(stream.read(Mockito.any(byte[].class), anyInt(), anyInt())).thenAnswer(new Answer<Integer>()
            {

                @Override
                public Integer answer(InvocationOnMock invocation) throws Throwable
                {
                    return arrayInput.read((byte[])invocation.getArguments()[0], (int)invocation.getArguments()[1], 
                            (int)invocation.getArguments()[2]); 
                }
            });
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        
        try
        {
            when(stream.read(Mockito.any(byte[].class))).thenAnswer(new Answer<Integer>()
            {
                @Override
                public Integer answer(InvocationOnMock invocation) throws Throwable
                {
                    return arrayInput.read((byte[])invocation.getArguments()[0]); 
                }
            });
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        
        return stream;
    }
/**
     * Mock a {@link FileInputStream} so that a consumer will read in the given string as input.
     * 
     * @param input
     *      what to read in as input
     */
Mock a  FileInputStream so that a consumer will read in the given string as input.

@param input
what to read in as input
Mock a FileInputStream so that a consumer will read in the given string as input . @param input what to read in as input
public static FileInputStream mockIt(String input)
    {
        FileInputStream stream = mock(FileInputStream.class);
        final ByteArrayInputStream arrayInput = new ByteArrayInputStream(input.getBytes());
        try
        {
            when(stream.read(Mockito.any(byte[].class), anyInt(), anyInt())).thenAnswer(new Answer<Integer>()
            {
                @Override
                public Integer answer(InvocationOnMock invocation) throws Throwable
                {
                    return arrayInput.read((byte[])invocation.getArguments()[0], (int)invocation.getArguments()[1], 
                            (int)invocation.getArguments()[2]); 
                }
            });
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        try
        {
            when(stream.read(Mockito.any(byte[].class))).thenAnswer(new Answer<Integer>()
            {
                @Override
                public Integer answer(InvocationOnMock invocation) throws Throwable
                {
                    return arrayInput.read((byte[])invocation.getArguments()[0]); 
                }
            });
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        return stream;
    }
public static FileInputStream mockIt ( String input ) { FileInputStream stream = mock ( FileInputStream . class ) ; final ByteArrayInputStream arrayInput = new ByteArrayInputStream ( input . getBytes ( ) ) ; try { when ( stream . read ( Mockito . any ( byte [ ] . class ) , anyInt ( ) , anyInt ( ) ) ) . thenAnswer ( new Answer < Integer > ( ) { @ Override public Integer answer ( InvocationOnMock invocation ) throws Throwable { return arrayInput . read ( ( byte [ ] ) invocation . getArguments ( ) [ 0 ] , ( int ) invocation . getArguments ( ) [ 1 ] , ( int ) invocation . getArguments ( ) [ 2 ] ) ; } } ) ; } catch ( IOException e ) { throw new IllegalStateException ( e ) ; } try { when ( stream . read ( Mockito . any ( byte [ ] . class ) ) ) . thenAnswer ( new Answer < Integer > ( ) { @ Override public Integer answer ( InvocationOnMock invocation ) throws Throwable { return arrayInput . read ( ( byte [ ] ) invocation . getArguments ( ) [ 0 ] ) ; } } ) ; } catch ( IOException e ) { throw new IllegalStateException ( e ) ; } return stream ; }
Mock a {@link FileInputStream} so that a consumer will read in the given string as input.
Mock a { @link FileInputStream } so that a consumer will read in the given string as input .