### Question:
UnsignedXrayClient { public GetSamplingRulesResult getSamplingRules(GetSamplingRulesRequest request) { return sendRequest(getSamplingRulesEndpoint, request, GetSamplingRulesResult.class); } UnsignedXrayClient();   UnsignedXrayClient(String endpoint); GetSamplingRulesResult getSamplingRules(GetSamplingRulesRequest request); GetSamplingTargetsResult getSamplingTargets(GetSamplingTargetsRequest request);  }### Answer:
@Test public void getSamplingRules() throws Exception { stubFor(any(anyUrl()).willReturn(aResponse() .withStatus(200) .withBody(SAMPLING_RULES))); GetSamplingRulesResult result = client.getSamplingRules(new GetSamplingRulesRequest()); GetSamplingRulesResult expected = OBJECT_MAPPER.readValue(SAMPLING_RULES, GetSamplingRulesResult.class); assertThat(expected).isEqualTo(result); verify(postRequestedFor(urlEqualTo("/GetSamplingRules")) .withHeader("Content-Type", equalTo("application/json")) .withRequestBody(equalToJson("{}"))); }
@Test public void badStatus() { String expectedMessage = "{\"message\": \"bad authentication\"}"; stubFor(any(anyUrl()).willReturn(aResponse() .withStatus(500) .withBody(expectedMessage))); assertThatThrownBy(() -> client.getSamplingRules(new GetSamplingRulesRequest())) .isInstanceOf(XrayClientException.class) .hasMessageContaining(expectedMessage); }
@Test public void cannotSend() { client = new UnsignedXrayClient("http: assertThatThrownBy(() -> client.getSamplingRules(new GetSamplingRulesRequest())) .isInstanceOf(XrayClientException.class) .hasMessageContaining("Could not serialize and send request"); }