byte[] chunk1 = new byte[] { 1, 2, 3, 4 };
byte[] chunk2 = new byte[] { 5, 6, 7, 8 };
byte[] chunk3 = new byte[] { 9, 10 };
InputStream stream = new ByteArrayInputStream( data );
WriteRequest writeRequest = new WriteRequest( stream );
/*
* Record expectations
*/
session.setAttribute( StreamWriteFilter.CURRENT_STREAM, stream );
mockSession.setReturnValue(null);
session.setAttribute( StreamWriteFilter.INITIAL_WRITE_FUTURE, writeRequest.getFuture() );
mockSession.setReturnValue(null);
nextFilter.filterWrite( session, new WriteRequest( ByteBuffer.wrap( chunk1 ) ) );
mockNextFilter.setMatcher( new WriteRequestMatcher() );
session.getAttribute( StreamWriteFilter.CURRENT_STREAM );
mockSession.setReturnValue( stream );
nextFilter.filterWrite( session, new WriteRequest( ByteBuffer.wrap( chunk2 ) ) );
session.getAttribute( StreamWriteFilter.CURRENT_STREAM );
mockSession.setReturnValue( stream );
nextFilter.filterWrite( session, new WriteRequest( ByteBuffer.wrap( chunk3 ) ) );
session.getAttribute( StreamWriteFilter.CURRENT_STREAM );
mockSession.setReturnValue( stream );
session.removeAttribute( StreamWriteFilter.CURRENT_STREAM );
mockSession.setReturnValue( stream );
session.removeAttribute( StreamWriteFilter.INITIAL_WRITE_FUTURE );
mockSession.setReturnValue( writeRequest.getFuture() );
session.removeAttribute( StreamWriteFilter.WRITE_REQUEST_QUEUE );
mockSession.setReturnValue( null );
nextFilter.messageSent( session, stream );
/*
* Replay.
*/
mockNextFilter.replay();
mockSession.replay();
filter.filterWrite( nextFilter, session, writeRequest );
filter.messageSent( nextFilter, session, chunk1 );
filter.messageSent( nextFilter, session, chunk2 );
filter.messageSent( nextFilter, session, chunk3 );
/*
* Verify.
*/
mockNextFilter.verify();
mockSession.verify();
assertTrue( writeRequest.getFuture().isWritten() );
}