### Question:
IldcpResponsePacketHandler { public final void handle(final InterledgerResponsePacket responsePacket) { Objects.requireNonNull(responsePacket); if (IldcpResponsePacket.class.isAssignableFrom(responsePacket.getClass())) { handleIldcpResponsePacket((IldcpResponsePacket) responsePacket); } else if (InterledgerRejectPacket.class.isAssignableFrom(responsePacket.getClass())) { handleIldcpErrorPacket((InterledgerRejectPacket) responsePacket); } else { throw new RuntimeException( String.format("Unsupported IldcpResponsePacket Type: %s", responsePacket.getClass())); } }  final void handle(final InterledgerResponsePacket responsePacket);  }### Answer:
@Test(expected = NullPointerException.class) public void handleNullPacket() { new IldcpResponsePacketHandler() { @Override protected void handleIldcpResponsePacket(IldcpResponsePacket ildcpResponsePacket) { throw new RuntimeException("Should not fulfill!"); } @Override protected void handleIldcpErrorPacket(InterledgerRejectPacket ildcpErrorPacket) { throw new RuntimeException("Should not reject!"); } }.handle(null); fail("cannot handle null packet"); }
@Test public void handleFulfillPacket() { new IldcpResponsePacketHandler() { @Override protected void handleIldcpResponsePacket(IldcpResponsePacket ildcpResponsePacket) { assertThat(ildcpResponsePacket).isEqualTo(fulfillPacket); } @Override protected void handleIldcpErrorPacket(InterledgerRejectPacket ildcpErrorPacket) { fail("Cannot handle fulfill packets"); throw new RuntimeException("Should not reject!"); } }.handle(fulfillPacket); }
@Test public void handleRejectPacket() { new IldcpResponsePacketHandler() { @Override protected void handleIldcpResponsePacket(IldcpResponsePacket ildcpResponsePacket) { fail("Cannot handle reject packet"); throw new RuntimeException("Should not fulfill!"); } @Override protected void handleIldcpErrorPacket(InterledgerRejectPacket ildcpErrorPacket) { assertThat(ildcpErrorPacket.getCode()).isEqualTo(InterledgerErrorCode.T00_INTERNAL_ERROR); } }.handle(rejectPacket); }
@Test public void handleExpiredPacket() { new IldcpResponsePacketHandler() { @Override protected void handleIldcpResponsePacket(IldcpResponsePacket ildcpResponsePacket) { fail("Cannot handle expired packet"); throw new RuntimeException("Should not fulfill!"); } @Override protected void handleIldcpErrorPacket(InterledgerRejectPacket ildcpErrorPacket) { assertThat(ildcpErrorPacket.getCode()).isEqualTo(InterledgerErrorCode.R00_TRANSFER_TIMED_OUT); } }.handle(expiredPacket); }
@Test public void fallthrough() { expectedException.expect(RuntimeException.class); expectedException.expectMessage("Unsupported IldcpResponsePacket Type: " + "class org.interledger.ildcp.InterledgerShampooPacketBuilder$ImmutableInterledgerShampooPacket"); new IldcpResponsePacketHandler() { @Override protected void handleIldcpResponsePacket(IldcpResponsePacket ildcpResponsePacket) { } @Override protected void handleIldcpErrorPacket(InterledgerRejectPacket ildcpErrorPacket) { } }.handle(shampooPacket); }