mil.dod.th.ose.test/src/mil/dod/th/ose/test/FileOutputStreamMocker.java
public static FileOutputStream mockIt(final ByteArrayOutputStream outputData) throws IllegalStateException
    {
        FileOutputStream stream = mock(FileOutputStream.class);
        
        try
        {
            doAnswer(new Answer<Void>()
            {
                @Override
                public Void answer(InvocationOnMock invocation) throws Throwable
                {
                    outputData.write((byte[])invocation.getArguments()[0]);
                    return null;
                }
            }).when(stream).write(Mockito.any(byte[].class));
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        
        try
        {
            doAnswer(new Answer<Void>()
            {
                @Override
                public Void answer(InvocationOnMock invocation) throws Throwable
                {
                    outputData.write((byte[])invocation.getArguments()[0], (int)invocation.getArguments()[1], 
                            (int)invocation.getArguments()[2]);
                    return null;
                }
            }).when(stream).write(Mockito.any(byte[].class), anyInt(), anyInt());
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        
        return stream;
    }
/**
     * Create a {@link FileOutputStream} mock that writes it's data to the given output stream so the output data can be
     * checked easily.
     */
Create a  FileOutputStream mock that writes it's data to the given output stream so the output data can be
checked easily.
Create a FileOutputStream mock that writes it ' s data to the given output stream so the output data can be checked easily .
public static FileOutputStream mockIt(final ByteArrayOutputStream outputData) throws IllegalStateException
    {
        FileOutputStream stream = mock(FileOutputStream.class);
        try
        {
            doAnswer(new Answer<Void>()
            {
                @Override
                public Void answer(InvocationOnMock invocation) throws Throwable
                {
                    outputData.write((byte[])invocation.getArguments()[0]);
                    return null;
                }
            }).when(stream).write(Mockito.any(byte[].class));
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        try
        {
            doAnswer(new Answer<Void>()
            {
                @Override
                public Void answer(InvocationOnMock invocation) throws Throwable
                {
                    outputData.write((byte[])invocation.getArguments()[0], (int)invocation.getArguments()[1], 
                            (int)invocation.getArguments()[2]);
                    return null;
                }
            }).when(stream).write(Mockito.any(byte[].class), anyInt(), anyInt());
        }
        catch (IOException e)
        {
            throw new IllegalStateException(e);
        }
        return stream;
    }
public static FileOutputStream mockIt ( final ByteArrayOutputStream outputData ) throws IllegalStateException { FileOutputStream stream = mock ( FileOutputStream . class ) ; try { doAnswer ( new Answer < Void > ( ) { @ Override public Void answer ( InvocationOnMock invocation ) throws Throwable { outputData . write ( ( byte [ ] ) invocation . getArguments ( ) [ 0 ] ) ; return null ; } } ) . when ( stream ) . write ( Mockito . any ( byte [ ] . class ) ) ; } catch ( IOException e ) { throw new IllegalStateException ( e ) ; } try { doAnswer ( new Answer < Void > ( ) { @ Override public Void answer ( InvocationOnMock invocation ) throws Throwable { outputData . write ( ( byte [ ] ) invocation . getArguments ( ) [ 0 ] , ( int ) invocation . getArguments ( ) [ 1 ] , ( int ) invocation . getArguments ( ) [ 2 ] ) ; return null ; } } ) . when ( stream ) . write ( Mockito . any ( byte [ ] . class ) , anyInt ( ) , anyInt ( ) ) ; } catch ( IOException e ) { throw new IllegalStateException ( e ) ; } return stream ; }
Create a {@link FileOutputStream} mock that writes it's data to the given output stream so the output data can be
 checked easily.
Create a { @link FileOutputStream } mock that writes it ' s data to the given output stream so the output data can be checked easily .