From 334443a08046324ede264c1b3876bc630c5391f4 Mon Sep 17 00:00:00 2001 From: Juan C Galvis <8420868+juancgalvis@users.noreply.github.com> Date: Thu, 19 Sep 2024 08:03:23 -0500 Subject: [PATCH] fix(charset): read file with charset or as bytes --- .../com/bancolombia/utils/FileUtilsTest.java | 18 ++++++++++++++++++ src/test/resources/temp-iso-8859-1.txt | 1 + src/test/resources/temp-other.txt | 1 + 3 files changed, 20 insertions(+) create mode 100644 src/test/resources/temp-iso-8859-1.txt create mode 100644 src/test/resources/temp-other.txt diff --git a/src/test/java/co/com/bancolombia/utils/FileUtilsTest.java b/src/test/java/co/com/bancolombia/utils/FileUtilsTest.java index 205da064..4a7939e0 100644 --- a/src/test/java/co/com/bancolombia/utils/FileUtilsTest.java +++ b/src/test/java/co/com/bancolombia/utils/FileUtilsTest.java @@ -47,6 +47,24 @@ void readFile() throws IOException { assertEquals("hello", response); } + @Test + void readFileWithEncodingISO8859() throws IOException { + Project project = + ProjectBuilder.builder().withProjectDir(new File("src/test/resources")).build(); + String response = FileUtils.readFile(project, "temp-iso-8859-1.txt"); + + assertEquals("¿cómo funcionará?", response); + } + + @Test + void readFileWithOtherEncoding() throws IOException { + Project project = + ProjectBuilder.builder().withProjectDir(new File("src/test/resources")).build(); + String response = FileUtils.readFile(project, "temp-other.txt"); + + assertEquals("*\u00ADx>e\u0001%ËØ´£/!vd\u0007", response); + } + @Test void readFileFromResources() throws IOException { DefaultResolver resolver = new DefaultResolver(); diff --git a/src/test/resources/temp-iso-8859-1.txt b/src/test/resources/temp-iso-8859-1.txt new file mode 100644 index 00000000..4ab48f06 --- /dev/null +++ b/src/test/resources/temp-iso-8859-1.txt @@ -0,0 +1 @@ +¿cómo funcionará? \ No newline at end of file diff --git a/src/test/resources/temp-other.txt b/src/test/resources/temp-other.txt new file mode 100644 index 00000000..c99681e7 --- /dev/null +++ b/src/test/resources/temp-other.txt @@ -0,0 +1 @@ +*­x>e%ËØ´£/!vd \ No newline at end of file