You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/02/21 02:40:13 UTC
(commons-io) branch master updated (526b3154f -> 969434f0d)
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
from 526b3154f Fix test fixture
new 0a7134403 Fix test fixtures
new e45b048fc Normalize test method names
new 969434f0d Comments and longer lines
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../java/org/apache/commons/io/FileUtilsTest.java | 216 ++++++++++-----------
.../java/org/apache/commons/io/IOUtilsTest.java | 3 +-
2 files changed, 103 insertions(+), 116 deletions(-)
(commons-io) 01/03: Fix test fixtures
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 0a71344031cda9a5ce5e444a82ec42702885da37
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Thu Feb 20 21:35:49 2025 -0500
Fix test fixtures
---
src/test/java/org/apache/commons/io/FileUtilsTest.java | 6 +++---
src/test/java/org/apache/commons/io/IOUtilsTest.java | 3 ++-
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index bd31ee2da..b4bbf31ce 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -2815,9 +2815,9 @@ public void testReadFileToString_IOExceptionOnPosixFileSystem() throws Exception
@Test
public void testReadFileToStringWithDefaultEncoding() throws Exception {
final File file = new File(tempDirFile, "read.obj");
- final String fixture = "Hello \u1234";
+ // Don't use non-ASCII in this test fixture because this test uses the default platform encoding.
+ final String fixture = "Hello 1234";
Files.write(file.toPath(), fixture.getBytes());
-
assertEquals(fixture, FileUtils.readFileToString(file));
}
@@ -3506,7 +3506,7 @@ public void testWriteStringToFileIntoSymlinkedDir() throws Exception {
final Path symlinkDir = createTempSymbolicLinkedRelativeDir().getLeft();
final File file = symlinkDir.resolve("file").toFile();
FileUtils.writeStringToFile(file, "Hello \u1234", StandardCharsets.UTF_8);
- final byte[] text = "Hello \u1234".getBytes();
+ final byte[] text = "Hello \u1234".getBytes(StandardCharsets.UTF_8);
TestUtils.assertEqualContent(text, file);
}
diff --git a/src/test/java/org/apache/commons/io/IOUtilsTest.java b/src/test/java/org/apache/commons/io/IOUtilsTest.java
index 6ef0171b8..c641a73c5 100644
--- a/src/test/java/org/apache/commons/io/IOUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/IOUtilsTest.java
@@ -1085,7 +1085,8 @@ public void testReadLines_Reader() throws Exception {
final File file = TestUtils.newFile(temporaryFolder, "lines.txt");
Reader in = null;
try {
- final String[] data = {"hello", "\u1234", "", "this is", "some text"};
+ // Don't use non-ASCII in this test fixture because this test uses the default platform encoding.
+ final String[] data = {"hello", "1234", "", "this is", "some text"};
TestUtils.createLineFileUtf8(file, data);
in = new InputStreamReader(Files.newInputStream(file.toPath()));
final List<String> lines = IOUtils.readLines(in);
(commons-io) 02/03: Normalize test method names
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit e45b048fc36b7e9cf07d2a278061ffe36f5a8c5d
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Thu Feb 20 21:37:18 2025 -0500
Normalize test method names
---
.../java/org/apache/commons/io/FileUtilsTest.java | 178 ++++++++++-----------
1 file changed, 89 insertions(+), 89 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index b4bbf31ce..afcb7004b 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -358,95 +358,6 @@ public void setUp() throws Exception {
}
}
- @Test
- public void test_openInputStream_exists() throws Exception {
- final File file = new File(tempDirFile, "test.txt");
- TestUtils.createLineFileUtf8(file, new String[]{"Hello"});
- try (FileInputStream in = FileUtils.openInputStream(file)) {
- assertEquals('H', in.read());
- }
- }
-
- @Test
- public void test_openInputStream_existsButIsDirectory() {
- final File directory = new File(tempDirFile, "subdir");
- directory.mkdirs();
- assertThrows(IOException.class, () -> FileUtils.openInputStream(directory));
- }
-
- @Test
- public void test_openInputStream_notExists() {
- final File directory = new File(tempDirFile, "test.txt");
- assertThrows(IOException.class, () -> FileUtils.openInputStream(directory));
- }
-
- @Test
- public void test_openOutputStream_exists() throws Exception {
- final File file = new File(tempDirFile, "test.txt");
- TestUtils.createLineFileUtf8(file, new String[]{"Hello"});
- try (FileOutputStream out = FileUtils.openOutputStream(file)) {
- out.write(0);
- }
- assertTrue(file.exists());
- }
-
- @Test
- public void test_openOutputStream_existsButIsDirectory() {
- final File directory = new File(tempDirFile, "subdir");
- directory.mkdirs();
- assertThrows(IllegalArgumentException.class, () -> FileUtils.openOutputStream(directory));
- }
-
- /**
- * Requires admin privileges on Windows.
- *
- * @throws Exception For example java.nio.file.FileSystemException:
- * C:\Users\you\AppData\Local\Temp\junit2324629522183300191\FileUtilsTest8613879743106252609\symlinked-dir: A required privilege is
- * not held by the client.
- */
- @Test
- public void test_openOutputStream_intoExistingSymlinkedDir() throws Exception {
- final Path symlinkedDir = createTempSymbolicLinkedRelativeDir().getLeft();
- final File file = symlinkedDir.resolve("test.txt").toFile();
- try (FileOutputStream out = FileUtils.openOutputStream(file)) {
- out.write(0);
- }
- assertTrue(file.exists());
- }
-
- @Test
- public void test_openOutputStream_noParentCreateFile() throws Exception {
- openOutputStream_noParent(true);
- }
-
- @Test
- public void test_openOutputStream_noParentNoFile() throws Exception {
- openOutputStream_noParent(false);
- }
-
- @Test
- public void test_openOutputStream_notExists() throws Exception {
- final File file = new File(tempDirFile, "a/test.txt");
- try (FileOutputStream out = FileUtils.openOutputStream(file)) {
- out.write(0);
- }
- assertTrue(file.exists());
- }
-
- @Test
- public void test_openOutputStream_notExistsCannotCreate() {
- // according to Wikipedia, most filing systems have a 256 limit on filename
- final String longStr =
- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
- "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz"; // 300 chars
- final File file = new File(tempDirFile, "a/" + longStr + "/test.txt");
- assertThrows(IOException.class, () -> FileUtils.openOutputStream(file));
- }
-
// byteCountToDisplaySize
@Test
public void testByteCountToDisplaySizeBigInteger() {
@@ -2765,6 +2676,95 @@ public void testMoveToDirectory_Errors() throws Exception {
}
+ @Test
+ public void testOpenInputStream_exists() throws Exception {
+ final File file = new File(tempDirFile, "test.txt");
+ TestUtils.createLineFileUtf8(file, new String[]{"Hello"});
+ try (FileInputStream in = FileUtils.openInputStream(file)) {
+ assertEquals('H', in.read());
+ }
+ }
+
+ @Test
+ public void testOpenInputStream_existsButIsDirectory() {
+ final File directory = new File(tempDirFile, "subdir");
+ directory.mkdirs();
+ assertThrows(IOException.class, () -> FileUtils.openInputStream(directory));
+ }
+
+ @Test
+ public void testOpenInputStream_notExists() {
+ final File directory = new File(tempDirFile, "test.txt");
+ assertThrows(IOException.class, () -> FileUtils.openInputStream(directory));
+ }
+
+ @Test
+ public void testOpenOutputStream_exists() throws Exception {
+ final File file = new File(tempDirFile, "test.txt");
+ TestUtils.createLineFileUtf8(file, new String[]{"Hello"});
+ try (FileOutputStream out = FileUtils.openOutputStream(file)) {
+ out.write(0);
+ }
+ assertTrue(file.exists());
+ }
+
+ @Test
+ public void testOpenOutputStream_existsButIsDirectory() {
+ final File directory = new File(tempDirFile, "subdir");
+ directory.mkdirs();
+ assertThrows(IllegalArgumentException.class, () -> FileUtils.openOutputStream(directory));
+ }
+
+ /**
+ * Requires admin privileges on Windows.
+ *
+ * @throws Exception For example java.nio.file.FileSystemException:
+ * C:\Users\you\AppData\Local\Temp\junit2324629522183300191\FileUtilsTest8613879743106252609\symlinked-dir: A required privilege is
+ * not held by the client.
+ */
+ @Test
+ public void testOpenOutputStream_intoExistingSymlinkedDir() throws Exception {
+ final Path symlinkedDir = createTempSymbolicLinkedRelativeDir().getLeft();
+ final File file = symlinkedDir.resolve("test.txt").toFile();
+ try (FileOutputStream out = FileUtils.openOutputStream(file)) {
+ out.write(0);
+ }
+ assertTrue(file.exists());
+ }
+
+ @Test
+ public void testOpenOutputStream_noParentCreateFile() throws Exception {
+ openOutputStream_noParent(true);
+ }
+
+ @Test
+ public void testOpenOutputStream_noParentNoFile() throws Exception {
+ openOutputStream_noParent(false);
+ }
+
+ @Test
+ public void testOpenOutputStream_notExists() throws Exception {
+ final File file = new File(tempDirFile, "a/test.txt");
+ try (FileOutputStream out = FileUtils.openOutputStream(file)) {
+ out.write(0);
+ }
+ assertTrue(file.exists());
+ }
+
+ @Test
+ public void testOpenOutputStream_notExistsCannotCreate() {
+ // according to Wikipedia, most filing systems have a 256 limit on filename
+ final String longStr =
+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz" +
+ "abcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyzabcdevwxyz"; // 300 chars
+ final File file = new File(tempDirFile, "a/" + longStr + "/test.txt");
+ assertThrows(IOException.class, () -> FileUtils.openOutputStream(file));
+ }
+
@Test
public void testReadFileToByteArray() throws Exception {
final File file = new File(tempDirFile, "read.txt");
(commons-io) 03/03: Comments and longer lines
Posted by gg...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
commit 969434f0d4946b6f8129aff097a3fde698568fb5
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Thu Feb 20 21:38:46 2025 -0500
Comments and longer lines
---
.../java/org/apache/commons/io/FileUtilsTest.java | 32 ++++++----------------
1 file changed, 9 insertions(+), 23 deletions(-)
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTest.java b/src/test/java/org/apache/commons/io/FileUtilsTest.java
index afcb7004b..b46a55f88 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTest.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTest.java
@@ -548,42 +548,28 @@ public void testContentEquals() throws Exception {
assertTrue(FileUtils.contentEquals(null, null));
assertFalse(FileUtils.contentEquals(null, file));
assertFalse(FileUtils.contentEquals(file, null));
- // both don't exist
+ // both don't exist
assertTrue(FileUtils.contentEquals(file, file));
assertTrue(FileUtils.contentEquals(file, file2));
assertTrue(FileUtils.contentEquals(file2, file2));
assertTrue(FileUtils.contentEquals(file2, file));
-
// Directories
assertThrows(IllegalArgumentException.class, () -> FileUtils.contentEquals(tempDirFile, tempDirFile));
-
// Different files
- final File objFile1 =
- new File(tempDirFile, getName() + ".object");
- FileUtils.copyURLToFile(
- getClass().getResource("/java/lang/Object.class"),
- objFile1);
-
- final File objFile1b =
- new File(tempDirFile, getName() + ".object2");
- FileUtils.copyURLToFile(
- getClass().getResource("/java/lang/Object.class"),
- objFile1b);
-
- final File objFile2 =
- new File(tempDirFile, getName() + ".collection");
- FileUtils.copyURLToFile(
- getClass().getResource("/java/util/Collection.class"),
- objFile2);
-
+ final File objFile1 = new File(tempDirFile, getName() + ".object");
+ FileUtils.copyURLToFile(getClass().getResource("/java/lang/Object.class"), objFile1);
+ final File objFile1b = new File(tempDirFile, getName() + ".object2");
+ FileUtils.copyURLToFile(getClass().getResource("/java/lang/Object.class"), objFile1b);
+ final File objFile2 = new File(tempDirFile, getName() + ".collection");
+ FileUtils.copyURLToFile(getClass().getResource("/java/util/Collection.class"), objFile2);
+ // equals to other
assertFalse(FileUtils.contentEquals(objFile1, objFile2));
assertFalse(FileUtils.contentEquals(objFile1b, objFile2));
assertTrue(FileUtils.contentEquals(objFile1, objFile1b));
-
+ // equals to self
assertTrue(FileUtils.contentEquals(objFile1, objFile1));
assertTrue(FileUtils.contentEquals(objFile1b, objFile1b));
assertTrue(FileUtils.contentEquals(objFile2, objFile2));
-
// Equal files
file.createNewFile();
file2.createNewFile();