Skip to content

Commit

Permalink
Fix test fixture
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Feb 20, 2025
1 parent 27eb9a9 commit 526b315
Showing 1 changed file with 18 additions and 18 deletions.
36 changes: 18 additions & 18 deletions src/test/java/org/apache/commons/io/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2815,7 +2815,7 @@ 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";
final String fixture = "Hello \u1234";
Files.write(file.toPath(), fixture.getBytes());

assertEquals(fixture, FileUtils.readFileToString(file));
Expand All @@ -2824,18 +2824,18 @@ public void testReadFileToStringWithDefaultEncoding() throws Exception {
@Test
public void testReadFileToStringWithEncoding() throws Exception {
final File file = new File(tempDirFile, "read.obj");
final byte[] text = "Hello /u1234".getBytes(StandardCharsets.UTF_8);
final byte[] text = "Hello \u1234".getBytes(StandardCharsets.UTF_8);
Files.write(file.toPath(), text);

final String data = FileUtils.readFileToString(file, "UTF8");
assertEquals("Hello /u1234", data);
assertEquals("Hello \u1234", data);
}

@Test
public void testReadLines() throws Exception {
final File file = TestUtils.newFile(tempDirFile, "lines.txt");
try {
final String[] data = {"hello", "/u1234", "", "this is", "some text"};
final String[] data = {"hello", "\u1234", "", "this is", "some text"};
TestUtils.createLineFileUtf8(file, data);

final List<String> lines = FileUtils.readLines(file, UTF_8);
Expand Down Expand Up @@ -3270,16 +3270,16 @@ public void testWriteByteArrayToFile_WithOffsetAndLength_WithAppendOptionTrue_Sh
@Test
public void testWriteCharSequence1() throws Exception {
final File file = new File(tempDirFile, "write.txt");
FileUtils.write(file, "Hello /u1234", "UTF8");
final byte[] text = "Hello /u1234".getBytes(StandardCharsets.UTF_8);
FileUtils.write(file, "Hello \u1234", "UTF8");
final byte[] text = "Hello \u1234".getBytes(StandardCharsets.UTF_8);
TestUtils.assertEqualContent(text, file);
}

@Test
public void testWriteCharSequence2() throws Exception {
final File file = new File(tempDirFile, "write.txt");
FileUtils.write(file, "Hello /u1234", (String) null);
final byte[] text = "Hello /u1234".getBytes();
FileUtils.write(file, "Hello \u1234", (String) null);
final byte[] text = "Hello \u1234".getBytes();
TestUtils.assertEqualContent(text, file);
}

Expand Down Expand Up @@ -3489,8 +3489,8 @@ public void testWriteStringToFile_WithAppendOptionTrue_ShouldNotDeletePreviousFi
@Test
public void testWriteStringToFileIntoNonExistentSubdir() throws Exception {
final File file = new File(tempDirFile, "subdir/write.txt");
FileUtils.writeStringToFile(file, "Hello /u1234", (Charset) null);
final byte[] text = "Hello /u1234".getBytes();
FileUtils.writeStringToFile(file, "Hello \u1234", (Charset) null);
final byte[] text = "Hello \u1234".getBytes();
TestUtils.assertEqualContent(text, file);
}

Expand All @@ -3505,16 +3505,16 @@ public void testWriteStringToFileIntoNonExistentSubdir() throws Exception {
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();
FileUtils.writeStringToFile(file, "Hello \u1234", StandardCharsets.UTF_8);
final byte[] text = "Hello \u1234".getBytes();
TestUtils.assertEqualContent(text, file);
}

@Test
public void testWriteStringToFileWithCharset() throws Exception {
final File file = new File(tempDirFile, "write.txt");
FileUtils.writeStringToFile(file, "Hello /u1234", "UTF8");
final byte[] text = "Hello /u1234".getBytes(StandardCharsets.UTF_8);
FileUtils.writeStringToFile(file, "Hello \u1234", "UTF8");
final byte[] text = "Hello \u1234".getBytes(StandardCharsets.UTF_8);
TestUtils.assertEqualContent(text, file);
}

Expand Down Expand Up @@ -3546,16 +3546,16 @@ public void testWriteStringToFileWithEncoding_WithAppendOptionTrue_ShouldNotDele
@Test
public void testWriteStringToFileWithNullCharset() throws Exception {
final File file = new File(tempDirFile, "write.txt");
FileUtils.writeStringToFile(file, "Hello /u1234", (Charset) null);
final byte[] text = "Hello /u1234".getBytes();
FileUtils.writeStringToFile(file, "Hello \u1234", (Charset) null);
final byte[] text = "Hello \u1234".getBytes();
TestUtils.assertEqualContent(text, file);
}

@Test
public void testWriteStringToFileWithNullStringCharset() throws Exception {
final File file = new File(tempDirFile, "write.txt");
FileUtils.writeStringToFile(file, "Hello /u1234", (String) null);
final byte[] text = "Hello /u1234".getBytes();
FileUtils.writeStringToFile(file, "Hello \u1234", (String) null);
final byte[] text = "Hello \u1234".getBytes();
TestUtils.assertEqualContent(text, file);
}

Expand Down

0 comments on commit 526b315

Please sign in to comment.