### Question:
IlpOverHttpLink extends AbstractLink<IlpOverHttpLinkSettings> implements Link<IlpOverHttpLinkSettings> { public void testConnection() { try { final Request okHttpRequest = this.constructSendPacketRequest(UNFULFILLABLE_PACKET); try (Response response = okHttpClient.newCall(okHttpRequest).execute()) { if (response.isSuccessful()) { boolean responseHasOctetStreamContentType = response.headers(CONTENT_TYPE).stream() .findFirst() .filter(OCTET_STREAM_STRING::equals) .isPresent(); if (responseHasOctetStreamContentType) { logger.info("Remote peer-link supports ILP-over-HTTP. url={} responseHeaders={}", outgoingUrl, response ); } else { logger.warn("Remote peer-link supports ILP-over-HTTP but uses wrong ContentType. url={} " + "response={}", outgoingUrl, response ); } } else { if (response.code() == 406 || response.code() == 415) { throw new LinkException( String.format("Remote peer-link DOES NOT support ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } else { throw new LinkException( String.format("Unable to connect to ILP-over-HTTP. url=%s response=%s", outgoingUrl, response ), getLinkId() ); } } } } catch (IOException e) { throw new LinkException(e.getMessage(), e, getLinkId()); } } IlpOverHttpLink(
      final Supplier<InterledgerAddress> operatorAddressSupplier,
      final HttpUrl outgoingUrl,
      final OkHttpClient okHttpClient,
      final ObjectMapper objectMapper,
      final CodecContext ilpCodecContext,
      final BearerTokenSupplier bearerTokenSupplier
  ); @Override InterledgerResponsePacket sendPacket(final InterledgerPreparePacket preparePacket); void testConnection(); @Override String toString(); HttpUrl getOutgoingUrl(); static final String LINK_TYPE_STRING; static final LinkType LINK_TYPE; }### Answer:
@Test public void testConnectionThrowsUnexpected() throws Exception { Call call = mock(Call.class); when(httpClientMock.newCall(any())).thenReturn(call); when(call.execute()).thenThrow(new IOException("hey a penny")); expectedException.expect(LinkException.class); expectedException.expectMessage("hey a penny"); link.testConnection(); }
@Test public void testConnection() throws Exception { mockCall(200); link.testConnection(); }
@Test public void testConnectionFailsOn406() throws Exception { mockCall(406); expectedException.expect(LinkException.class); expectedException.expectMessage("Remote peer-link DOES NOT support ILP-over-HTTP. " + "url=https: + "response=Response{" + "protocol=h2, " + "code=406, " + "message=stop asking me to set stuff, " + "url=https: + "}"); link.testConnection(); }
@Test public void testConnectionFailsOn415() throws Exception { mockCall(415); expectedException.expect(LinkException.class); expectedException.expectMessage("Remote peer-link DOES NOT support ILP-over-HTTP. " + "url=https: + "response=Response{" + "protocol=h2, " + "code=415, " + "message=stop asking me to set stuff, " + "url=https: + "}"); link.testConnection(); }
@Test public void testConnectionFailsOnOther() throws Exception { mockCall(422); expectedException.expect(LinkException.class); expectedException.expectMessage("Unable to connect to ILP-over-HTTP. " + "url=https: + "response=Response{" + "protocol=h2, " + "code=422, " + "message=stop asking me to set stuff, " + "url=https: + "}"); link.testConnection(); }