AdminDistributionUtils { public void convertDataToFileLocationIfEnabled(EDXLDistribution request) throws LargePayloadException { if (fileUtils.isSavePayloadToFileEnabled()) { List<File> savedAttachmentList = new ArrayList<>(); try { if (request.getContentObject() != null) { for (ContentObjectType co : request.getContentObject()) { File attachmentFile = convertToFile(co); if (attachmentFile != null) { savedAttachmentList.add(attachmentFile); } } } } catch (Exception e) { deleteAllFiles(savedAttachmentList); throw new LargePayloadException("Failed to save attachments to file system", e); } } } AdminDistributionUtils(); static AdminDistributionUtils getInstance(); void convertFileLocationToDataIfEnabled(EDXLDistribution request); void convertDataToFileLocationIfEnabled(EDXLDistribution request);  }
@Test public void testConvertDataToFileLocationIfEnabled() throws Exception { AdminDistributionUtils adminUtils = createAdminDistributionUtils(); context.checking(new Expectations() { { oneOf(mockFileUtils).isSavePayloadToFileEnabled(); will(returnValue(true)); oneOf(mockFileUtils).generateAttachmentFile(); will(returnValue(new File(new URI(URI_SAVED_FILE_STRING)))); oneOf(mockFileUtils).saveDataToFile(with(any(DataHandler.class)), with(any(File.class))); oneOf(mockFileUtils).convertToDataHandler(with(any(String.class))); will(returnValue(LargeFileUtils.getInstance().convertToDataHandler(URI_SAVED_FILE_STRING))); } }); EDXLDistribution request = createEDXLDistribution(); adminUtils.convertDataToFileLocationIfEnabled(request); URI contentUri = LargeFileUtils.getInstance() .parseBase64DataAsUri(request.getContentObject().get(0).getNonXMLContent().getContentData()); assertEquals(URI_SAVED_FILE_STRING, contentUri.toString()); }