Skip to content

Commit

Permalink
replaes FileUtil with java 9+ apis
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Feb 5, 2025
1 parent bb8f5d7 commit 1ceefd3
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 40 deletions.
31 changes: 0 additions & 31 deletions pitest-entry/src/main/java/org/pitest/util/FileUtil.java

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import org.pitest.classpath.ClassPath;
import org.pitest.help.PitHelpError;
import org.pitest.mutationtest.engine.gregor.Generated;
import org.pitest.util.FileUtil;
import org.pitest.util.IsolationUtils;

import com.example.BeforeAfterClassTest;
Expand Down Expand Up @@ -233,7 +232,7 @@ public void shouldExcludeFilteredClasses() {
public void shouldMutateClassesSuppliedToAlternateClassPath()
throws IOException {
// yes, this is horrid
final String location = FileUtil.randomFilename() + ".jar";
final String location = ("" + Math.random()).replaceAll("\\.", "") + ".jar";
try {
try (FileOutputStream fos = new FileOutputStream(location)) {
final InputStream stream = IsolationUtils.getContextClassLoader()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import java.io.FileInputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.nio.file.Files;

import org.hamcrest.Matcher;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.pitest.util.FileUtil;
import org.pitest.util.PitError;

public class FileWriterFactoryTest {
Expand All @@ -33,7 +33,7 @@ public void writeToFile() throws IOException {
writer.write("test");
writerFactory.close();

final String content = FileUtil.readToString(new FileInputStream(file));
final String content = Files.readString(file.toPath());
assertThat(content, equalTo("test"));
}

Expand All @@ -57,7 +57,7 @@ public void writeToFileWithinFolder() throws IOException {
writer.write("test");
writerFactory.close();

final String content = FileUtil.readToString(new FileInputStream(file));
final String content = Files.readString(file.toPath());
assertThat(content, equalTo("test"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@
import org.pitest.mutationtest.MutationResultListener;
import org.pitest.mutationtest.SourceLocator;
import org.pitest.mutationtest.verify.BuildMessage;
import org.pitest.util.FileUtil;
import org.pitest.util.IsolationUtils;
import org.pitest.util.Log;
import org.pitest.util.ResultOutputStrategy;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.io.Writer;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -83,9 +84,9 @@ public MutationHtmlReportListener(Charset outputCharset,
}

private String loadCss() {
try {
return FileUtil.readToString(IsolationUtils.getContextClassLoader()
.getResourceAsStream("templates/mutation/style.css"));
try (InputStream is = IsolationUtils.getContextClassLoader()
.getResourceAsStream("templates/mutation/style.css")) {
return new String(is.readAllBytes(), StandardCharsets.UTF_8);
} catch (final IOException e) {
Log.getLogger().log(Level.SEVERE, "Error while loading css", e);
}
Expand Down

0 comments on commit 1ceefd3

Please # to comment.