### Question:
HttpResponder { public void respond(ChannelHandlerContext ctx, FullHttpRequest req, HttpResponseStatus status) { respond(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, status)); } @VisibleForTesting  HttpResponder(); @VisibleForTesting  HttpResponder(int httpConnIdleTimeout); static HttpResponder getInstance(); void respond(ChannelHandlerContext ctx, FullHttpRequest req, HttpResponseStatus status); void respond(ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res);  }### Answer:
@Test public void testDefaultHttpConnIdleTimeout_RequestKeepAlive_ShouldHaveResponseKeepAlive() { HttpResponder responder = new HttpResponder(); ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); FullHttpRequest request = mock(FullHttpRequest.class); FullHttpResponse response = mock(FullHttpResponse.class); HttpHeaders headers = mock(HttpHeaders.class); Channel channel = mock(Channel.class); when(ctx.channel()).thenReturn(channel); when(request.content()).thenReturn(null); when(request.headers()).thenReturn(headers); when(headers.get(HttpHeaders.Names.CONNECTION)).thenReturn(HttpHeaders.Values.KEEP_ALIVE); when(request.getProtocolVersion()).thenReturn(HttpVersion.HTTP_1_1); HttpHeaders responseHeaders = new DefaultHttpHeaders(); when(response.headers()).thenReturn(responseHeaders); responder.respond(ctx, request, response); assertEquals("Connection: response header", HttpHeaders.Values.KEEP_ALIVE, responseHeaders.get(HttpHeaders.Names.CONNECTION)); }
@Test public void testNonZeroHttpConnIdleTimeout_RequestKeepAlive_ShouldHaveResponseKeepAliveTimeout() { int idleTimeout = 300; HttpResponder responder = new HttpResponder(idleTimeout); ChannelHandlerContext ctx = mock(ChannelHandlerContext.class); FullHttpRequest request = mock(FullHttpRequest.class); FullHttpResponse response = mock(FullHttpResponse.class); HttpHeaders headers = mock(HttpHeaders.class); Channel channel = mock(Channel.class); ChannelFuture future = mock(ChannelFuture.class); when(ctx.channel()).thenReturn(channel); when(ctx.writeAndFlush(any())).thenReturn(future); when(request.content()).thenReturn(null); when(request.headers()).thenReturn(headers); when(headers.get(HttpHeaders.Names.CONNECTION)).thenReturn(HttpHeaders.Values.KEEP_ALIVE); when(request.getProtocolVersion()).thenReturn(HttpVersion.HTTP_1_1); HttpHeaders responseHeaders = new DefaultHttpHeaders(); when(response.headers()).thenReturn(responseHeaders); responder.respond(ctx, request, response); assertEquals("Connection: response header", HttpHeaders.Values.KEEP_ALIVE, responseHeaders.get(HttpHeaders.Names.CONNECTION)); assertEquals("Keep-Alive: response header", "timeout="+idleTimeout, responseHeaders.get("Keep-Alive")); }