### Question:
PingLoopbackLink extends AbstractLink<LinkSettings> implements Link<LinkSettings> { @Override public InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket) { Objects.requireNonNull(preparePacket, "preparePacket must not be null!"); if (preparePacket.getExecutionCondition().equals(PING_PROTOCOL_CONDITION)) { return InterledgerFulfillPacket.builder() .fulfillment(PING_PROTOCOL_FULFILLMENT) .data(preparePacket.getData()) .build(); } else { final InterledgerRejectPacket rejectPacket = InterledgerRejectPacket.builder() .triggeredBy(getOperatorAddressSupplier().get()) .code(InterledgerErrorCode.F00_BAD_REQUEST) .message("Invalid Ping Protocol Condition") .build(); logger.warn( "Rejecting Unidirectional Ping packet: PreparePacket={} RejectPacket={}", preparePacket, rejectPacket ); return rejectPacket; } } PingLoopbackLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier, final LinkSettings linkSettings
  ); @Override void registerLinkHandler(LinkHandler ilpDataHandler); @Override InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket); @Override String toString(); static final String LINK_TYPE_STRING; static final LinkType LINK_TYPE; static final InterledgerFulfillment PING_PROTOCOL_FULFILLMENT; static final InterledgerCondition PING_PROTOCOL_CONDITION; }### Answer:
@Test(expected = NullPointerException.class) public void sendPacketWithNull() { try { link.sendPacket(null); } catch (NullPointerException e) { assertThat(e.getMessage()).isEqualTo("preparePacket must not be null!"); throw e; } }
@Test public void sendPacketWithInvalidCondition() { final InterledgerPreparePacket preparePacket = InterledgerPreparePacket.builder() .amount(UnsignedLong.valueOf(10L)) .executionCondition(InterledgerCondition.of(new byte[32])) .destination(OPERATOR_ADDRESS) .expiresAt(DateUtils.now()) .build(); link.sendPacket(preparePacket).handle(fulfillPacket -> { logger.error("InterledgerFulfillPacket: {}", fulfillPacket); fail("Expected a Reject!"); }, rejectPacket -> { assertThat(rejectPacket.getCode()).isEqualTo(InterledgerErrorCode.F00_BAD_REQUEST); assertThat(rejectPacket.getTriggeredBy().isPresent()).isEqualTo(true); assertThat(rejectPacket.getTriggeredBy()).isEqualTo(EXPECTED_REJECT_PACKET.getTriggeredBy()); } ); }
@Test public void sendPacketWithInvalidAddress() { final InterledgerPreparePacket preparePacket = InterledgerPreparePacket.builder() .amount(UnsignedLong.valueOf(10L)) .executionCondition(PING_PROTOCOL_CONDITION) .destination(InterledgerAddress.of("example.foo")) .expiresAt(DateUtils.now()) .build(); link.sendPacket(preparePacket).handle( fulfillPacket -> assertThat(fulfillPacket.getFulfillment()).isEqualTo(PING_PROTOCOL_FULFILLMENT), rejectPacket -> { logger.error("InterledgerRejectPacket: {}", rejectPacket); fail("Expected a Fulfill!"); } ); }
@Test public void sendPacket() { final InterledgerPreparePacket preparePacket = InterledgerPreparePacket.builder() .amount(UnsignedLong.valueOf(10L)) .executionCondition(PING_PROTOCOL_CONDITION) .destination(OPERATOR_ADDRESS) .expiresAt(DateUtils.now()) .build(); link.sendPacket(preparePacket).handle( fulfillPacket -> assertThat(fulfillPacket.getFulfillment()).isEqualTo(PING_PROTOCOL_FULFILLMENT), rejectPacket -> { logger.error("InterledgerRejectPacket: {}", rejectPacket); fail("Expected a Fulfill!"); } ); }