private Optional<String> createJar() { try { final File randomName = File.createTempFile(FileUtil.randomFilename(), ".jar"); final FileOutputStream fos = new FileOutputStream(randomName); createJarFromClassPathResources(fos, randomName.getAbsolutePath()); return Optional.ofNullable(randomName.getAbsolutePath()); } catch (final IOException ex) { throw Unchecked.translateCheckedException(ex); } }
private String loadCss() { try { return FileUtil.readToString(IsolationUtils.getContextClassLoader() .getResourceAsStream("templates/mutation/style.css")); } catch (final IOException e) { Log.getLogger().log(Level.SEVERE, "Error while loading css", e); } return ""; }
@Test public void writeToFileWithinFolder() throws IOException { final File folder = this.testFolder.newFolder(); final File file = new File(folder, "subfolder/file"); final FileWriterFactory writerFactory = new FileWriterFactory(file); final PrintWriter writer = writerFactory.create(); writer.write("test"); writerFactory.close(); final String content = FileUtil.readToString(new FileInputStream(file)); assertThat(content, equalTo("test")); }
@Test public void shouldMutateClassesSuppliedToAlternateClassPath() throws IOException { // yes, this is horrid final String location = FileUtil.randomFilename() + ".jar"; try { try (FileOutputStream fos = new FileOutputStream(location)) { final InputStream stream = IsolationUtils.getContextClassLoader() .getResourceAsStream("outofcp.jar"); copy(stream, fos); } this.data.setTargetClasses(asList("com.outofclasspath.*Mutee*")); this.data.setTargetTests(predicateFor("com.outofclasspath.*")); final List<String> cp = new ArrayList<>(); cp.addAll(ClassPath.getClassPathElementsAsPaths()); cp.add(location); this.data.setClassPathElements(cp); this.data.setDependencyAnalysisMaxDistance(-1); this.data.setExcludedClasses(asList("*Power*", "*JMockit*")); createAndRun(); verifyResults(KILLED); } finally { new File(location).delete(); } }
@Test public void writeToFile() throws IOException { final File file = this.testFolder.newFile(); final FileWriterFactory writerFactory = new FileWriterFactory(file); final PrintWriter writer = writerFactory.create(); writer.write("test"); writerFactory.close(); final String content = FileUtil.readToString(new FileInputStream(file)); assertThat(content, equalTo("test")); }