### Question:
ReportExecutionRestApi { public boolean cancelReportExecution(@NotNull String executionId) throws IOException, HttpException { Utils.checkNotNull(executionId, "Execution id should not be null"); HttpUrl url = mNetworkClient.getBaseUrl() .resolve("rest_v2/reportExecutions") .newBuilder() .addPathSegment(executionId) .addPathSegment("status") .build(); RequestBody jsonRequestBody = mNetworkClient.createJsonRequestBody(ExecutionStatus.cancelledStatus()); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .put(jsonRequestBody) .url(url) .build(); com.squareup.okhttp.Response response = mNetworkClient.makeCall(request); int status = response.code(); return status != 204; } ReportExecutionRestApi(NetworkClient networkClient); @NotNull ReportExecutionDescriptor runReportExecution(@NotNull ReportExecutionRequestOptions executionOptions); @NotNull ReportExecutionDescriptor requestReportExecutionDetails(@NotNull String executionId); @NotNull ExecutionStatus requestReportExecutionStatus(@NotNull String executionId); boolean cancelReportExecution(@NotNull String executionId); boolean updateReportExecution(@NotNull String executionId,
                                         @NotNull List<ReportParameter> params);  }### Answer:
@Test public void executionIdShouldNotBeNullForCancelRequestExecution() throws Exception { mExpectedException.expect(NullPointerException.class); mExpectedException.expectMessage("Execution id should not be null"); restApiUnderTest.cancelReportExecution(null); }
@Test public void shouldCancelReportExecution() throws Exception { MockResponse response = MockResponseFactory.create200(); mWebMockRule.enqueue(response); restApiUnderTest.cancelReportExecution(EXEC_ID); RecordedRequest request = mWebMockRule.get().takeRequest(); assertThat(request, containsHeader("Accept", "application/json; charset=UTF-8")); assertThat(request, hasPath("/rest_v2/reportExecutions/f3a9805a-4089-4b53-b9e9-b54752f91586/status")); assertThat(request, hasBody("{\"value\":\"cancelled\"}")); assertThat(request, wasMethod("PUT")); }
@Test public void responseShouldNotBeCancelledIfResponseIs204() throws Exception { mWebMockRule.enqueue(MockResponseFactory.create204()); boolean cancelled = restApiUnderTest.cancelReportExecution("any_id"); assertThat(cancelled, is(false)); }
@Test public void responseShouldBeCancelledIfResponseIs200() throws Exception { MockResponse response = MockResponseFactory.create200().setBody(cancelledResponse.asString()); mWebMockRule.enqueue(response); boolean cancelled = restApiUnderTest.cancelReportExecution("any_id"); assertThat(cancelled, is(true)); }