DataTransferResource { @GET @Path("export") @Produces("application/zip") public Response export() { try { String exportFile = dataTransferServices.doExport(DataTransferExportModel.exportAll()); org.uberfire.java.nio.file.Path path = Paths.get(exportFile); return Response.ok(ioService.readAllBytes(path)).build(); } catch (Exception e) { String errorMessage = "Error creating export: " + e.getMessage(); logger.error(errorMessage); logger.debug("Not able to create export.", e); return Response.serverError() .entity(errorMessage) .build(); } }  @GET @Path("export") @Produces("application/zip") Response export();  }
@Test public void testSuccessExport() throws IOException { when(dataTransferServices.doExport(any())).thenReturn("file: Response response = dataTransferResource.export(); assertEquals(Response.Status.OK.getStatusCode(), response.getStatus()); }
@Test public void testBadExport() throws IOException { when(dataTransferServices.doExport(any())).thenThrow(new IOException()); Response response = dataTransferResource.export(); assertEquals(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode(), response.getStatus()); }