### Question:
ReportExportRestApi { @NotNull public OutputResource requestExportAttachment(@NotNull String executionId, @NotNull String exportId, @NotNull String attachmentId) throws IOException, HttpException { Utils.checkNotNull(executionId, "Execution id should not be null"); Utils.checkNotNull(exportId, "Export id should not be null"); Utils.checkNotNull(attachmentId, "Attachment id should not be null"); HttpUrl url = new PathResolver.Builder() .addPath("rest_v2") .addPath("reportExecutions") .addPath(executionId) .addPath("exports") .addPath(exportId) .addPath("attachments") .addPath(attachmentId) .build() .resolve(mNetworkClient.getBaseUrl()); Request request = new Request.Builder() .addHeader("Accept", "application/json; charset=UTF-8") .get() .url(url) .build(); com.squareup.okhttp.Response response = mNetworkClient.makeCall(request); return new RetrofitOutputResource(response.body()); } ReportExportRestApi(NetworkClient networkClient); @NotNull ExportExecutionDescriptor runExportExecution(@NotNull String executionId,
                                                        @NotNull ExecutionRequestOptions executionOptions); @NotNull ExecutionStatus checkExportExecutionStatus(@NotNull String executionId,
                                                      @NotNull String exportId); @NotNull ExportOutputResource requestExportOutput(@NotNull String executionId,
                                                    @NotNull String exportId); @NotNull OutputResource requestExportAttachment(@NotNull String executionId,
                                                  @NotNull String exportId,
                                                  @NotNull String attachmentId);  }### Answer:
@Test public void requestForAttachmentShouldBeWrappedInsideInput() throws Exception { MockResponse mockResponse = MockResponseFactory.create200() .setBody(mResource.asString()); mWebMockRule.enqueue(mockResponse); OutputResource resource = restApiUnderTest.requestExportAttachment("any_id", "any_id", "any_id"); InputStream stream = resource.getStream(); assertThat(stream, is(notNullValue())); stream.close(); }
@Test public void shouldRequestExportAttachment() throws Exception { MockResponse mockResponse = MockResponseFactory.create200() .setBody(mResource.asString()); mWebMockRule.enqueue(mockResponse); restApiUnderTest.requestExportAttachment(EXECUTION_ID, "html;pages=1", "attachment_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/exports/html;pages=1/attachments/attachment_id")); assertThat(request, wasMethod("GET")); }
@Test public void requestExportAttachmentShouldThrowRestErrorOn500() throws Exception { mExpectedException.expect(HttpException.class); mWebMockRule.enqueue(MockResponseFactory.create500()); restApiUnderTest.requestExportAttachment("any_id", "any_id", "any_id"); }
@Test public void executionIdParameterShouldNotBeNullForAttachmentRequest() throws Exception { mExpectedException.expect(NullPointerException.class); mExpectedException.expectMessage("Execution id should not be null"); restApiUnderTest.requestExportAttachment(null, "any_id", "any_id"); }
@Test public void exportIdParameterShouldNotBeNullForAttachmentRequest() throws Exception { mExpectedException.expect(NullPointerException.class); mExpectedException.expectMessage("Export id should not be null"); restApiUnderTest.requestExportAttachment("any_id", null, "any_id"); }
@Test public void attachmentIdParameterShouldNotBeNullForAttachmentRequest() throws Exception { mExpectedException.expect(NullPointerException.class); mExpectedException.expectMessage("Attachment id should not be null"); restApiUnderTest.requestExportAttachment("any_id", "any_id", null); }