### Question:
DefaultStreamManager implements StreamManager { @Override public void onReceivePacket(final Packet packet, final PipelineContext ctx) { requireNonNull(packet); requireNonNull(ctx); if (packet instanceof ShortPacket) { final ShortPacket sp = (ShortPacket) packet; for (final Frame frame : sp.getPayload().getFrames()) { if (frame instanceof StreamFrame) { if (ctx.getState() != State.Ready) { throw new IllegalStateException("Stream frames can only be handled in ready state"); } final StreamFrame sf = (StreamFrame) frame; final DefaultStream stream = streams.getOrCreate(sf.getStreamId(), listener); stream.onData(sf.getOffset(), sf.isFin(), sf.getData()); } else if (frame instanceof ResetStreamFrame) { final ResetStreamFrame rsf = (ResetStreamFrame) frame; final DefaultStream stream = streams.getOrCreate(rsf.getStreamId(), listener); stream.onReset(rsf.getApplicationErrorCode(), rsf.getOffset()); } else if (frame instanceof AckFrame) { final AckFrame af = (AckFrame) frame; af.getBlocks().stream().forEach(this::handleAcks); } } } ctx.next(packet); } DefaultStreamManager(final FrameSender frameSender, final StreamListener listener); @Override void onReceivePacket(final Packet packet, final PipelineContext ctx); @Override Stream openStream(final boolean client, final boolean bidirectional);  }### Answer:
@Test(expected = IllegalStateException.class) public void receiveInInvalidState() { when(ctx.getState()).thenReturn(State.BeforeReady); manager.onReceivePacket(p(new StreamFrame(0, 0, false, DATA1)), ctx); }