### Question:
Http2ConnectionHandler extends ByteToMessageDecoder implements Http2LifecycleManager, ChannelOutboundHandler { @Override public ChannelFuture resetStream( final ChannelHandlerContext ctx, final int streamId, final long errorCode, final ChannelPromise promise) { final Http2Stream stream = connection().stream(streamId); if (stream == null) { return resetUnknownStream(ctx, streamId, errorCode, promise.unvoid()); } return resetStream(ctx, stream, errorCode, promise); } protected  Http2ConnectionHandler(
      final Http2ConnectionDecoder decoder,
      final Http2ConnectionEncoder encoder,
      final Http2Settings initialSettings); protected  Http2ConnectionHandler(
      final Http2ConnectionDecoder decoder,
      final Http2ConnectionEncoder encoder,
      final Http2Settings initialSettings,
      final boolean decoupleCloseAndGoAway); long gracefulShutdownTimeoutMillis(); void gracefulShutdownTimeoutMillis(final long gracefulShutdownTimeoutMillis); Http2Connection connection(); Http2ConnectionDecoder decoder(); Http2ConnectionEncoder encoder(); void onHttpClientUpgrade(); void onHttpServerUpgrade(final Http2Settings settings); @Override void flush(final ChannelHandlerContext ctx); @Override void handlerAdded(final ChannelHandlerContext ctx); @Override void channelActive(final ChannelHandlerContext ctx); @Override void channelInactive(final ChannelHandlerContext ctx); @Override void channelWritabilityChanged(final ChannelHandlerContext ctx); @Override void bind(
      final ChannelHandlerContext ctx,
      final SocketAddress localAddress,
      final ChannelPromise promise); @Override void connect(
      final ChannelHandlerContext ctx,
      final SocketAddress remoteAddress,
      final SocketAddress localAddress,
      final ChannelPromise promise); @Override void disconnect(final ChannelHandlerContext ctx, final ChannelPromise promise); @Override void close(
      final ChannelHandlerContext ctx,
      @SuppressWarnings("checkstyle:finalparameters") ChannelPromise promise); @Override void deregister(final ChannelHandlerContext ctx, final ChannelPromise promise); @Override void read(final ChannelHandlerContext ctx); @Override void write(final ChannelHandlerContext ctx, final Object msg, final ChannelPromise promise); @Override void channelReadComplete(final ChannelHandlerContext ctx); @Override void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause); @Override void closeStreamLocal(final Http2Stream stream, final ChannelFuture future); @Override void closeStreamRemote(final Http2Stream stream, final ChannelFuture future); @Override void closeStream(final Http2Stream stream, final ChannelFuture future); @Override void onError(
      final ChannelHandlerContext ctx, final boolean outbound, final Throwable cause); @Override ChannelFuture resetStream(
      final ChannelHandlerContext ctx,
      final int streamId,
      final long errorCode,
      final ChannelPromise promise); @Override ChannelFuture goAway(
      final ChannelHandlerContext ctx,
      final int lastStreamId,
      final long errorCode,
      final ByteBuf debugData,
      ChannelPromise promise);  }### Answer:
@Test public void writeRstOnNonExistantStreamShouldSucceed() throws Exception { handler = newHandler(); when(frameWriter.writeRstStream( eq(ctx), eq(NON_EXISTANT_STREAM_ID), ArgumentMatchers.eq(Http2Error.STREAM_CLOSED.code()), eq(promise))) .thenReturn(future); handler.resetStream(ctx, NON_EXISTANT_STREAM_ID, Http2Error.STREAM_CLOSED.code(), promise); verify(frameWriter) .writeRstStream( eq(ctx), eq(NON_EXISTANT_STREAM_ID), ArgumentMatchers.eq(Http2Error.STREAM_CLOSED.code()), eq(promise)); }
@Test public void writeRstOnClosedStreamShouldSucceed() throws Exception { handler = newHandler(); when(stream.id()).thenReturn(STREAM_ID); when(frameWriter.writeRstStream(eq(ctx), eq(STREAM_ID), anyLong(), any(ChannelPromise.class))) .thenReturn(future); when(stream.state()).thenReturn(CLOSED); when(stream.isHeadersSent()).thenReturn(true); handler.resetStream(ctx, STREAM_ID, Http2Error.STREAM_CLOSED.code(), promise); verify(frameWriter) .writeRstStream(eq(ctx), eq(STREAM_ID), anyLong(), any(ChannelPromise.class)); }