### Question:
StreamValve extends ChannelInboundHandlerAdapter { public static StreamValve locateValve(ChannelPipeline pipeline) throws NoSuchElementException { ChannelHandlerContext context = pipeline.context(StreamValve.class); if (context == null) throw new NoSuchElementException("PauseResume not configured on the current pipeline"); return (StreamValve) context.handler(); }  @Override void channelRegistered(ChannelHandlerContext ctx); @Override void channelRead(ChannelHandlerContext ctx, Object msg); boolean isPaused(); void pause(ChannelPipeline pipeline); void resume(ChannelPipeline pipeline); void validateInLoopAndPipeline(ChannelPipeline otherPipeline); static boolean isPipelinePaused(ChannelPipeline pipeline); static void pipelinePause(ChannelPipeline pipeline); static void pipelineResume(ChannelPipeline pipeline); static StreamValve locateValve(ChannelPipeline pipeline); static FlowControl wrap(final ChannelHandlerContext ctx);  }### Answer:
@Test(expected = NoSuchElementException.class) public void testLocateValveFailsIfNotInPipeline() throws Exception { reset(mockProvidedPipeline); when(mockProvidedPipeline.context(StreamValve.class)).thenReturn(null); StreamValve.locateValve(mockProvidedPipeline); }
@Test public void testLocateValveAsksProvidedContextForHandler() throws Exception { StreamValve locatedValve = StreamValve.locateValve(mockProvidedPipeline); verify(mockProvidedPipeline,atLeast(1)).context(StreamValve.class); verify(mockProvidedContext,atLeast(1)).handler(); assertEquals(mockValve, locatedValve); }