Skip to content

Commit

Permalink
fix(charset): read file with charset or as bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
juancgalvis committed Sep 19, 2024
1 parent 334443a commit e85b6c4
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 30 deletions.
15 changes: 8 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ plugins {
id 'maven-publish'
id 'java-gradle-plugin'
id 'org.sonarqube' version '5.1.0.4882'
id 'com.gradle.plugin-publish' version '1.2.2'
id 'com.gradle.plugin-publish' version '1.3.0'
id 'com.github.sherter.google-java-format' version '0.9'
id 'io.github.gradle-nexus.publish-plugin' version '2.0.0'
id 'org.owasp.dependencycheck' version '10.0.4'
Expand Down Expand Up @@ -182,13 +182,13 @@ if (project.hasProperty('signing.keyId')) { // publish as library in maven centr

dependencies {
api 'com.github.spullara.mustache.java:compiler:0.9.14'
api 'com.fasterxml.jackson.core:jackson-databind:2.17.2'
api 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.17.2'
api 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.17.2'
api 'commons-io:commons-io:2.16.1'
api 'com.fasterxml.jackson.core:jackson-databind:2.18.0-rc1'
api 'com.fasterxml.jackson.dataformat:jackson-dataformat-yaml:2.18.0-rc1'
api 'com.fasterxml.jackson.dataformat:jackson-dataformat-xml:2.18.0-rc1'
api 'commons-io:commons-io:2.17.0'
api gradleApi()

implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.17.2'
implementation 'com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.18.0-rc1'
implementation 'org.reflections:reflections:0.10.2'
// swagger generators
implementation('io.swagger.codegen.v3:swagger-codegen-generators:1.0.52') {
Expand All @@ -205,6 +205,7 @@ dependencies {
testImplementation gradleTestKit()
testImplementation 'org.mockito:mockito-junit-jupiter:5.13.0'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.11.0'
testImplementation 'org.junit.jupiter:junit-jupiter-params:5.11.0'
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.11.0'
testRuntimeOnly 'org.junit.platform:junit-platform-launcher:1.11.0'

Expand Down Expand Up @@ -287,7 +288,7 @@ tasks.register('installGitHooks') {
}

tasks.named('wrapper') {
gradleVersion = '8.10'
gradleVersion = '8.10.1'
}

tasks.register('ci-updater', JavaExec) {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package=co.com.bancolombia
systemProp.version=3.17.22
simulateRest=true
systemProp.sonar.gradle.skipCompile=true
systemProp.sonar.gradle.skipCompile=true
4 changes: 2 additions & 2 deletions src/main/java/co/com/bancolombia/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ public final class Constants {
public static final String REACTIVE_COMMONS_VERSION = "4.1.4";
public static final String REACTIVE_COMMONS_MAPPER_VERSION = "0.1.0";
public static final String BLOCK_HOUND_VERSION = "1.0.9.RELEASE";
public static final String AWS_BOM_VERSION = "2.28.1";
public static final String COMMONS_JMS_VERSION = "2.2.18";
public static final String AWS_BOM_VERSION = "2.28.4";
public static final String COMMONS_JMS_VERSION = "2.3.1";
public static final String GRAPHQL_KICKSTART_VERSION = "15.1.0";
public static final String ARCH_UNIT_VERSION = "1.3.0";
public static final String OKHTTP_VERSION = "4.12.0";
Expand Down
35 changes: 15 additions & 20 deletions src/test/java/co/com/bancolombia/utils/FileUtilsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import co.com.bancolombia.exceptions.ParamNotFoundException;
import com.fasterxml.jackson.databind.node.ObjectNode;
Expand All @@ -18,11 +19,15 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.gradle.api.Project;
import org.gradle.testfixtures.ProjectBuilder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

public class FileUtilsTest {

Expand All @@ -38,31 +43,21 @@ void readPropertiesNonExists() {
assertThrows(IOException.class, () -> FileUtils.readProperties("build", property));
}

@Test
void readFile() throws IOException {
@ParameterizedTest
@MethodSource("encodings")
void readFileWithEncodings(String file, String expected) throws IOException {
Project project =
ProjectBuilder.builder().withProjectDir(new File("src/test/resources")).build();
String response = FileUtils.readFile(project, "temp.txt");
String response = FileUtils.readFile(project, file);

assertEquals("hello", response);
assertEquals(expected, 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);
static Stream<Arguments> encodings() {
return Stream.of(
arguments("temp.txt", "hello"),
arguments("temp-iso-8859-1.txt", "¿cómo funcionará?"),
arguments("temp-other.txt", "*\u00ADx>e\u0001%ËØ´£/!vd\u0007"));
}

@Test
Expand Down

0 comments on commit e85b6c4

Please sign in to comment.