### Question:
ChunkedHandlerSwitcher extends ChannelDuplexHandler { @Override public void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise) throws Exception { boolean isChunked = chunkedClass.isAssignableFrom(msg.getClass()); if (isChunked && !chunkedHandlerActive) { deactivateNonChunkedHandler(ctx); activateChunkedHandler(ctx); } else if (!isChunked && chunkedHandlerActive) { deactivateChunkedHandler(ctx); activateNonChunkedHandler(ctx); } ctx.write(msg, promise); } protected  ChunkedHandlerSwitcher(final ChunkedMessageHandler chunkedHandler,
                                   final NonChunkedHttpMessageHandler nonChunkedHandler,
                                   final Class<? extends Request> chunkedClass); @Override void channelActive(final ChannelHandlerContext ctx); @Override void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise); static final String SWITCHER_IDENTIFIER; }### Answer:
@Test void switchesToNonChunkIfNeeded() { assertChunkedInPipeline(channel); GenericSearchRequest upsertRequest = mock(GenericSearchRequest.class); when(upsertRequest.retryStrategy()).thenReturn(FailFastRetryStrategy.INSTANCE); channel.write(upsertRequest); assertNonChunkedInPipeline(channel); }
@Test void switchesToChunkIfNeeded() { assertChunkedInPipeline(channel); for (int i = 0; i < 2; i++) { GenericSearchRequest genericSearchRequest = mock(GenericSearchRequest.class); when(genericSearchRequest.retryStrategy()).thenReturn(FailFastRetryStrategy.INSTANCE); channel.write(genericSearchRequest); assertNonChunkedInPipeline(channel); SearchRequest searchRequest = mock(SearchRequest.class); when(searchRequest.retryStrategy()).thenReturn(FailFastRetryStrategy.INSTANCE); channel.write(searchRequest); assertChunkedInPipeline(channel); } }