### Question:
FileUtils { public static String getCanonicalPath(final File file) { if (file == null) { return null; } try { return file.getCanonicalPath(); } catch (final IOException ioe) { throw new IllegalStateException("Cannot determine canonical path for '" + file + "'", ioe); } } private  FileUtils(); static String backOneDirectory(String fileIdentifier); static boolean copyRecursively(final File source, final File destination,
      final boolean deleteDestinationOnExit); static String ensureTrailingSeparator(final String path); static String getCanonicalPath(final File file); static String getFileSeparatorAsRegex(); static String getFirstDirectory(String fileIdentifier); static InputStream getInputStream(final Class<?> loadingClass, final String filename); static String getPath(final Class<?> loadingClass, final String relativeFilename); static String getSystemDependentPath(final Collection<String> pathElements); static String getSystemDependentPath(final String... pathElements); static boolean matchesAntPath(final String antPattern, final String canonicalPath); static final String CURRENT_DIRECTORY; }### Answer:
@Test(expected = IllegalStateException.class) public void testGetCanonicalPathForInvalidFile() throws Exception { final File invalidFile = mock(File.class); when(invalidFile.getCanonicalPath()).thenThrow(new IOException("dummy")); FileUtils.getCanonicalPath(invalidFile); }
@Test public void testGetCanonicalPathForNullFile() { assertNull(FileUtils.getCanonicalPath(null)); }
@Test public void testGetCanonicalPathForValidFile() throws Exception { final File validFile = mock(File.class); final String canonicalPath = "the_path"; when(validFile.getCanonicalPath()).thenReturn(canonicalPath); final String actualPath = FileUtils.getCanonicalPath(validFile); assertEquals(canonicalPath, actualPath); }