### Question:
RotatingFileWriter implements Flushable, Closeable { private boolean rotate() throws IOException { File oldFile = new File(mLogFile.toString() + ".old"); File newFile = new File(mLogFile.toString()); if (newFile.renameTo(oldFile)) { BufferedReader oldLog = null; FileWriter rotatedLog = null; try { oldLog = new BufferedReader(new FileReader(oldFile)); rotatedLog = new FileWriter(mLogFile.toString()); long lineCount = 0; String line; while ((line = oldLog.readLine()) != null) { lineCount++; if (lineCount > mDeleteOld) { rotatedLog.write(line); rotatedLog.write(LINE_SEPARATOR); } } } finally { DataUtils.close(oldLog); DataUtils.close(rotatedLog); oldFile.delete(); } mSize = mLogFile.length(); return true; } else { return mLogFile.delete(); } } RotatingFileWriter(File logFile);  RotatingFileWriter(File logFile, long rotateAt, int deleteOld); @Override synchronized void flush(); @Override synchronized void close(); @SuppressWarnings("ResultOfMethodCallIgnored") synchronized void abort(); synchronized void println(String x);  }### Answer:
@SuppressWarnings("ResultOfMethodCallIgnored") @Test public void testRotate() throws Exception { int lineSepLen = System.getProperty("line.separator").length(); File f = File.createTempFile("log", null); RotatingFileWriter w = new RotatingFileWriter(f, 3000, 2); w.println(StringUtils.randomString(512)); w.println(StringUtils.randomString(512)); w.println(StringUtils.randomString(512)); w.println(StringUtils.randomString(512)); w.flush(); assertEquals((512*4)+(lineSepLen*4), f.length()); w.println(StringUtils.randomString(512)); w.flush(); assertEquals((512*5)+(lineSepLen*5), f.length()); w.println(StringUtils.randomString(512)); w.flush(); assertEquals((512*4)+(lineSepLen*4), f.length()); w.println(StringUtils.randomString(512)); w.flush(); assertEquals((512*5)+(lineSepLen*5), f.length()); w.println(StringUtils.randomString(512)); w.flush(); assertEquals((512*4)+(lineSepLen*4), f.length()); w.close(); f.delete(); }