FileUtils { public static boolean closeQuietly( FileInputStream fileInputStream ) { if ( fileInputStream != null ) { try { fileInputStream.close(); } catch ( Exception e ) { logger.error( e.getMessage() ); return false; } return true; } return false; }  static String idToPath( String pathId ); static boolean closeQuietly( FileInputStream fileInputStream ); static boolean containsReservedCharacter( String path, char[] reserved ); static boolean containsControlCharacters( String path ); static String[] convertCommaSeparatedStringToArray( String stringToConvert ); static String getParentPath( final String path ); static boolean isRootLevelPath( final String path ); static final String PATH_SEPARATOR; static final String ENCODED_PATH_SEPARATOR; }
@Test public void testCloseQuietly( ) { File newFile = new File( new File( "src/test/resources/newFile.txt" ).getAbsolutePath() ); try { newFile.createNewFile(); FileInputStream fileInputStream = new FileInputStream( newFile ); fileInputStream = spy( fileInputStream ); doThrow( new IOException() ).when( fileInputStream ).close(); assertFalse( FileUtils.closeQuietly( fileInputStream ) ); assertTrue( FileUtils.closeQuietly( new FileInputStream( newFile ) ) ); doCallRealMethod().when( fileInputStream ).close(); fileInputStream.close(); assertTrue( newFile.delete() ); } catch ( IOException e ) { fail(); } assertFalse( FileUtils.closeQuietly( null ) ); }