FileUtils { public static void serialize(final File folder, final String content, final String fileName) throws IOException { if (!folder.exists()) { folder.mkdirs(); } final File output = new File(folder, fileName); try ( final FileWriter writer = new FileWriter(output); ) { writer.write(content); writer.flush(); } catch (Exception e) { throw new IOException("Failed to serialize the notification in folder " + folder.getPath(), e); } } private  FileUtils(); static void serialize(final File folder, final String content, final String fileName); static String read(final File file); static Long getSize(final File file); static void touch(final File folder , final String fileName); static String getFileChecksumSHA256(final File artifactFile);  }
@Test public void checkSerialization() throws IOException { final File testdir = new File(System.getProperty("user.dir") + "/target"); final String content = "content"; final String fileName = "test.txt"; final File testFile = new File(testdir, fileName); assertFalse(testFile.exists()); FileUtils.serialize(testdir, content, fileName); assertTrue(testFile.exists()); FileReader reader = null; BufferedReader buff = null; String realContent = null; try{ reader = new FileReader(testFile); buff = new BufferedReader(reader); realContent = buff.readLine(); } catch (Exception e){ } finally { if(buff != null){ try { buff.close(); } catch (IOException e) { e.printStackTrace(); } } if(reader != null){ try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } assertNotNull(realContent); assertEquals(content, realContent); if(testFile.exists()){ testFile.delete(); } }