chkpnt commented on code in PR #486:
URL: https://github.com/apache/commons-io/pull/486#discussion_r1340186889


##########
src/test/java/org/apache/commons/io/FileUtilsTest.java:
##########
@@ -2463,18 +2485,56 @@ public void testReadFileToStringWithEncoding() throws 
Exception {
         assertEquals("Hello /u1234", data);
     }
 
+    @Test
+    public void testReadFileToString_Errors() {
+        assertThrows(NullPointerException.class, () -> 
FileUtils.readFileToString(null));
+        assertThrows(NoSuchFileException.class, () -> 
FileUtils.readFileToString(new File("non-exsistent")));
+
+        Exception exception = assertThrows(IOException.class, () -> 
FileUtils.readFileToString(tempDirFile));
+        assertEquals("Is a directory", exception.getMessage());
+
+        assertThrows(UnsupportedCharsetException.class, () -> 
FileUtils.readFileToString(tempDirFile, "unsupported-charset"));
+    }
+
+    @Test
+    @EnabledIf("isPosixFilePermissionsSupported")
+    public void testReadFileToString_AccessDeniedExceptionOnPosixFileSystem() 
throws Exception {
+        final File file = TestUtils.newFile(tempDirFile, "cant-read.txt");
+        TestUtils.createFile(file, 100);
+        Files.setPosixFilePermissions(file.toPath(), 
PosixFilePermissions.fromString("---------"));
+
+        assertThrows(AccessDeniedException.class, () -> 
FileUtils.readFileToString(file));
+    }
+
     @Test
     public void testReadLines() throws Exception {
         final File file = TestUtils.newFile(tempDirFile, "lines.txt");
-        try {
-            final String[] data = {"hello", "/u1234", "", "this is", "some 
text"};
-            TestUtils.createLineBasedFile(file, data);
+        final String[] data = {"hello", "/u1234", "", "this is", "some text"};
+        TestUtils.createLineBasedFile(file, data);
 
-            final List<String> lines = FileUtils.readLines(file, UTF_8);
-            assertEquals(Arrays.asList(data), lines);
-        } finally {
-            TestUtils.deleteFile(file);

Review Comment:
   NP, your repo, your decision ;-)
   
   Do you want me to add the deletion in the 
`*_AccessDeniedExceptionOnPosixFileSystem`, too? I took my cue from the 
`testWriteString*` tests, where the cleanup relies on the tempDir.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to