FileConverter { public synchronized InputStream convertToPDF(String sourceName, final InputStream streamToConvert) throws IOException, OfficeException { File tmpDir = Files.createTempDirectory("docdoku-").toFile(); File fileToConvert = new File(tmpDir, sourceName); Files.copy(streamToConvert, fileToConvert.toPath()); File pdfFile = convertToPDF(fileToConvert); tmpDir.deleteOnExit(); return new FileInputStream(pdfFile); } @Inject  FileConverter(OfficeConfig officeConfig); synchronized InputStream convertToPDF(String sourceName, final InputStream streamToConvert);  }
@Test public void convertToPDFTest() throws StorageException, IOException, OfficeException, FileNotFoundException, URISyntaxException { try(InputStream resourceAsStream = getClass().getResourceAsStream("/org/polarsys/eplmp/server/resourcegetters/sample.txt")){ Assert.assertNotNull(resourceAsStream); try{ fileConverter.convertToPDF("sample.txt", resourceAsStream); Assert.fail("Should have thrown an IOException"); }catch (IOException e ){ Mockito.verify(officeManager, Mockito.times(1)).execute(Matchers.any()); } }catch (IOException e ){ Assert.fail("Resource not found: " + e.getMessage()); } }