### Question:
IOFactory { void moveTo(File fromFile, File toFile) throws IOException { if (toFile.exists()) { if (!toFile.delete()) { throw new IOException("Failed to move file from " + fromFile + " to " + toFile.getAbsolutePath() + ": destination file exists and cannot be removed."); } } if (!fromFile.renameTo(toFile)) { throw new IOException("Failed to move file from, " + fromFile + ", to " + toFile.getAbsolutePath()); } }    }### Answer:
@Test public void shouldMoveTempFile() throws IOException { File destinationFile = mock(File.class); File tmpFile = mock(File.class); given(tmpFile.renameTo(destinationFile)).willReturn(true); ioFactory.moveTo(tmpFile, destinationFile); }
@Test (expectedExceptions = IOException.class) public void shouldFailToMoveTempFile() throws IOException { File destinationFile = mock(File.class); File tmpFile = mock(File.class); given(reader.readLine()) .willReturn("LINE1") .willReturn("LINE2") .willReturn("LINE3") .willReturn(null); given(tmpFile.renameTo(destinationFile)).willReturn(false); ioFactory.moveTo(tmpFile, destinationFile); }