private void init(String testClass, String testName, TestState state) { if (writeToFile) { File fileToWrite = createFile(testClass, testName); if (fileToWrite == null) { System.err.println( "Cannot create file for " + testClass + "." + testName + ". Writing to STDOUT"); state.printStream = System.out; } else { try { state.printStream = new PrintStream(new FileOutputStream(fileToWrite)); System.out.println( testClass + "." + testName + " writing to " + fileToWrite.getAbsolutePath()); } catch (FileNotFoundException e) { e.printStackTrace(); state.printStream = System.out; } } } else { state.printStream = System.out; } // sanity check if (state.printStream == null) { throw new IllegalStateException("PrintStream cannot be null!!"); } }