### Question:
Files { public static String checkFile(final File file, final boolean checkWrite) { if (file == null) throw new IllegalArgumentException(NULL_PARAMS); if (!file.exists()) return String.format(FILE_NO_EXIST, file); if (file.isDirectory()) return String.format(DIR_NOT_FILE, file); if (!file.canRead()) return String.format(FILE_NOT_READABLE, file); if (checkWrite && !file.canWrite()) return String.format(FILE_NOT_WRITABLE, file); return null; }  static void ensureDir(final String dir); static void ensureDir(final String dir, final boolean checkWrite); static void ensureDir(final File dir); static void ensureDir(final File dir, final boolean checkWrite); static String checkDir(final String dir); static String checkDir(final String dir, final boolean checkWrite); static String checkDir(final File dir); static String checkDir(final File dir, final boolean checkWrite); static String checkFile(final File file, final boolean checkWrite); static void ensureMv(final String src, final String dest); static void ensureMv(final String src, final String dest, final boolean overwrite); static void ensureMv(final File src, final File dest); static void ensureMv(final File src, final File dest, final boolean overwrite); static String mv(final String src, final String dest); static String mv(final String src, final String dest, final boolean overwrite); static String mv(final File src, final File dest); static String mv(final File src, final File dest, final boolean overwrite); static File tmpDir();  }### Answer:
@Test public void testCheckFileExists() throws Exception { File file = mock(File.class); expect(file.exists()).andReturn(false); replay(file); String err = Files.checkFile(file, true); assertEquals(err, "File, 'EasyMock for class java.io.File' does not exist."); }
@Test public void testCheckFileIsNotDirectory() throws Exception { File file = mock(File.class); expect(file.exists()).andReturn(true); expect(file.isDirectory()).andReturn(true); replay(file); String err = Files.checkFile(file, true); assertEquals(err, "Directory, 'EasyMock for class java.io.File' is not a file."); }
@Test public void testCheckFileCanRead() throws Exception { File file = mock(File.class); expect(file.exists()).andReturn(true); expect(file.isDirectory()).andReturn(false); expect(file.canRead()).andReturn(false); replay(file); String err = Files.checkFile(file, false); assertEquals(err, "File, 'EasyMock for class java.io.File' cannot be read."); }
@Test public void testCheckFileWritable() throws Exception { File file = mock(File.class); expect(file.exists()).andReturn(true); expect(file.isDirectory()).andReturn(false); expect(file.canRead()).andReturn(true); expect(file.canWrite()).andReturn(false); replay(file); String err = Files.checkFile(file, true); assertEquals(err, "File, 'EasyMock for class java.io.File' cannot be written to."); }