Is there a nice way to test code which performs IO? In Java in particular, if you go the Mock route, you need to wrap most of the native APIs in your own mockable classes, something like:
public class Filesystem {
public void write(String filename, String text) throws FileNotFoundException {
try (PrintWriter out = new PrintWriter(filename)) {
out.println(text);
}
}
}
and then pass in an instance of Filesystem
to any class that needs to write text for a file. Is there a better way?