### Question:
ExportFactory { @NotNull public ReportExport create(ReportExecutionDescriptor descriptor, String execId, ExportIdWrapper exportIdWrapper) throws ServiceException { ExportDescriptor export = findExportDescriptor(descriptor, exportIdWrapper.getServerId()); if (export == null) { throw new ServiceException("Server returned malformed export details", null, StatusCodes.EXPORT_EXECUTION_FAILED); } List<ReportAttachment> attachments = mAttachmentsFactory.create(export, execId); return new ReportExport(mExportExecutionApi, attachments, execId, exportIdWrapper.getExactId()); } ExportFactory(ExportExecutionApi exportExecutionApi, AttachmentsFactory attachmentsFactory); @NotNull ReportExport create(ReportExecutionDescriptor descriptor, String execId, ExportIdWrapper exportIdWrapper);  }### Answer:
@Test public void should_create_export_if_details_fulfilled() throws Exception { ReportExport result = exportFactory.create(mReportExecutionDescriptor, EXEC_ID, mExportIdWrapper); assertThat(result, is(notNullValue())); assertThat(result, is(instanceOf(ReportExport.class))); verify(mAttachmentsFactory).create(mExportDescriptor, EXEC_ID); }
@Test public void should_throw_if_details_missing() throws Exception { when(mExportDescriptor.getId()).thenReturn("123122"); try { exportFactory.create(mReportExecutionDescriptor, EXEC_ID, mExportIdWrapper); fail("Should throw ServiceException"); } catch (ServiceException ex) { assertThat(ex.getMessage(), is("Server returned malformed export details")); assertThat(ex.code(), is(StatusCodes.EXPORT_EXECUTION_FAILED)); } }