FileWriterCommonsIOImpl implements FileWriter { @Override public void writeText(String text) throws IOException { if (encoding != null) { FileUtils.writeStringToFile(file, text, encoding); } else { FileUtils.writeStringToFile(file, text); } } FileWriterCommonsIOImpl(File file); @Override FileWriter setEncoding(String encoding); @Override FileWriter setWriteTarget(File file); @Override void writeText(String text); @Override void writeText(String text, String encoding);  }
@Test public void writeText_A$String() throws Exception { File file = new File("src/test/resources/tmp.txt"); FileWriterCommonsIOImpl target = new FileWriterCommonsIOImpl(file); String text = "testtest\r\ntest"; target.writeText(text); }
@Test public void writeText_A$String_T$IOException() throws Exception { File file = new File("src/test/resources/tmp.txt"); FileWriterCommonsIOImpl target = new FileWriterCommonsIOImpl(file); String text = null; try { file.setWritable(false); target.writeText(text); fail("Expected exception was not thrown!"); } catch (IOException e) { } file.setWritable(true); }
@Test public void writeText_A$String$String() throws Exception { File file = new File("src/test/resources/tmp.txt"); FileWriterCommonsIOImpl target = new FileWriterCommonsIOImpl(file); String text = null; String encoding = "UTF-8"; target.writeText(text, encoding); }
@Test public void writeText_A$String$String_NotWritable() throws Exception { File file = new File("src/test/resources/tmp.txt"); FileWriterCommonsIOImpl target = new FileWriterCommonsIOImpl(file); String text = null; String encoding = "UTF-8"; try { file.setWritable(false); target.writeText(text, encoding); fail("Expected exception was not thrown!"); } catch (IOException e) { } file.setWritable(true); }
@Test public void writeText_A$String_StringIsNull() throws Exception { File file = new File("src/test/resources/tmp.txt"); FileWriterCommonsIOImpl target = new FileWriterCommonsIOImpl(file); String text = null; target.writeText(text); file.setWritable(true); }
@Test public void writeText_A$String_StringIsEmpty() throws Exception { File file = new File("src/test/resources/tmp.txt"); FileWriterCommonsIOImpl target = new FileWriterCommonsIOImpl(file); String text = ""; target.writeText(text); file.setWritable(true); }
@Test public void writeText_A$String_StringIsFoo() throws Exception { File file = new File("src/test/resources/tmp.txt"); FileWriterCommonsIOImpl target = new FileWriterCommonsIOImpl(file); String text = "foo"; target.writeText(text); file.setWritable(true); }
@Test public void writeText_A$String$String_StringIsNull() throws Exception { File file = new File("src/test/resources/tmp.txt"); FileWriterCommonsIOImpl target = new FileWriterCommonsIOImpl(file); String text = null; String encoding = null; target.writeText(text, encoding); file.setWritable(true); }
@Test public void writeText_A$String$String_StringIsEmpty() throws Exception { File file = new File("src/test/resources/tmp.txt"); FileWriterCommonsIOImpl target = new FileWriterCommonsIOImpl(file); String text = ""; String encoding = ""; target.writeText(text, encoding); file.setWritable(true); }