diff --git a/README.md b/README.md index e0cd485..f54e2e0 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ Fixed Width Parser is a small library that purpose is: - If you are using Gradle just add the following dependency to your `build.gradle`. ```groovy -compile "com.github.joutvhu:fixed-width-parser:1.1.3" +compile "com.github.joutvhu:fixed-width-parser:1.1.4" ``` - Or add the following dependency to your `pom.xml` if you are using Maven. @@ -20,7 +20,7 @@ compile "com.github.joutvhu:fixed-width-parser:1.1.3" com.github.joutvhu fixed-width-parser - 1.1.3 + 1.1.4 ``` diff --git a/build.gradle b/build.gradle index e0a063b..7815e89 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,7 @@ plugins { } group = 'com.github.joutvhu' -version '1.1.3' +version '1.1.4' sourceCompatibility = 1.8 targetCompatibility = 1.8 @@ -29,26 +29,19 @@ dependencies { compileOnly 'org.projectlombok:lombok:1.18.12' implementation 'org.apache.commons:commons-lang3:3.11' - implementation 'com.google.code.findbugs:jsr305:3.0.2' - - implementation 'org.apache.logging.log4j:log4j-api:2.13.3' - implementation 'org.apache.logging.log4j:log4j-core:2.13.3' implementation "com.google.re2j:re2j:1.4" implementation "org.reflections:reflections:0.9.12" implementation "com.fasterxml.jackson.core:jackson-core:2.11.2" - implementation "com.fasterxml.jackson.core:jackson-annotations:2.11.2" implementation "com.fasterxml.jackson.core:jackson-databind:2.11.2" implementation "com.fasterxml.jackson.datatype:jackson-datatype-jdk8:2.11.2" implementation "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:2.11.2" - testImplementation 'junit:junit:4.13' testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2' testImplementation 'org.junit.jupiter:junit-jupiter-params:5.6.2' testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.6.2' - testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.6.2' testCompileOnly 'org.projectlombok:lombok:1.18.12' testAnnotationProcessor 'org.projectlombok:lombok:1.18.12' @@ -88,9 +81,7 @@ artifacts { } tasks.withType(Test) { - useJUnitPlatform { - includeEngines 'junit-jupiter' - } + useJUnitPlatform() filter { includeTestsMatching 'com.joutvhu.fixedwidth.parser.*' } diff --git a/gradlew b/gradlew old mode 100644 new mode 100755 diff --git a/src/main/java/com/joutvhu/fixedwidth/parser/support/FixedParseStrategy.java b/src/main/java/com/joutvhu/fixedwidth/parser/support/FixedParseStrategy.java index a31beb9..b51a5c6 100644 --- a/src/main/java/com/joutvhu/fixedwidth/parser/support/FixedParseStrategy.java +++ b/src/main/java/com/joutvhu/fixedwidth/parser/support/FixedParseStrategy.java @@ -48,13 +48,14 @@ private void validate(FixedTypeInfo info, String value, ValidationType type) { @Override public Object read(FixedTypeInfo info, StringAssembler assembler) { info.detectTypeWith(assembler); + String value = assembler.getValue(); assembler.trim(info); if (assembler.isBlank(info)) { if (info.require) throw new NullPointerException(info.buildMessage("{title} cannot be blank.")); return null; } - validate(info, assembler.getValue(), ValidationType.BEFORE_READ); + validate(info, value, ValidationType.BEFORE_READ); FixedWidthReader reader = module.createReaderBy(info, this); if (reader != null) { diff --git a/src/main/java/com/joutvhu/fixedwidth/parser/util/IgnoreError.java b/src/main/java/com/joutvhu/fixedwidth/parser/util/IgnoreError.java index 4ef0ca5..6a00b59 100644 --- a/src/main/java/com/joutvhu/fixedwidth/parser/util/IgnoreError.java +++ b/src/main/java/com/joutvhu/fixedwidth/parser/util/IgnoreError.java @@ -1,7 +1,6 @@ package com.joutvhu.fixedwidth.parser.util; import lombok.experimental.UtilityClass; -import lombok.extern.log4j.Log4j2; /** * Ignore exception executor @@ -9,7 +8,6 @@ * @author Giao Ho * @since 1.0.0 */ -@Log4j2 @UtilityClass public class IgnoreError { public void execute(NoResultCaller caller) { diff --git a/src/test/java/com/joutvhu/fixedwidth/parser/AlignmentTests.java b/src/test/java/com/joutvhu/fixedwidth/parser/AlignmentTests.java index 925acb8..f6fd75c 100644 --- a/src/test/java/com/joutvhu/fixedwidth/parser/AlignmentTests.java +++ b/src/test/java/com/joutvhu/fixedwidth/parser/AlignmentTests.java @@ -37,16 +37,9 @@ void validateFormattedFieldWithPadding(Sample sample) { static List samples() { return Arrays.asList( new Sample(new AutoPerson("Bob"), "Bob "), - - // FIXME "left" alignment means padding to the right to me new Sample(new LeftPerson("Bob"), "Bob "), - - // FIXME "right" alignment means padding to the left for me new Sample(new RightPerson("Bob"), " Bob"), - new Sample(new CenterPerson("Bob"), " Bob "), - - // FIXME fixed length = 10, "Emma".length = 4, this means 3 chars to the left, and 3 chars to the right new Sample(new CenterPerson("Emma"), " Emma ") ); } diff --git a/src/test/java/com/joutvhu/fixedwidth/parser/OptionTests.java b/src/test/java/com/joutvhu/fixedwidth/parser/OptionTests.java new file mode 100644 index 0000000..3ace891 --- /dev/null +++ b/src/test/java/com/joutvhu/fixedwidth/parser/OptionTests.java @@ -0,0 +1,60 @@ +package com.joutvhu.fixedwidth.parser; + +import com.joutvhu.fixedwidth.parser.annotation.FixedField; +import com.joutvhu.fixedwidth.parser.annotation.FixedObject; +import com.joutvhu.fixedwidth.parser.constraint.FixedOption; +import com.joutvhu.fixedwidth.parser.domain.KeepPadding; +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +class OptionTests { + private FixedParser fixedParser; + + @BeforeAll + public void beforeTest() { + this.fixedParser = FixedParser.parser(); + } + + @Test + void optionsWithDropPadding() { + DropPaddingStone stone = new DropPaddingStone("blue"); + + assertEquals("blue ", fixedParser.export(stone)); + assertEquals("blue", fixedParser.parse(DropPaddingStone.class, "blue ").color); + } + + @Test + void optionsWithKeepPadding() { + KeepPaddingStone stone = new KeepPaddingStone("blue"); + + assertEquals("blue ", fixedParser.export(stone)); + assertEquals("blue ", fixedParser.parse(KeepPaddingStone.class, "blue ").color); + } + + @FixedObject + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class DropPaddingStone { + @FixedField(length = 5, keepPadding = KeepPadding.DROP) + @FixedOption(options = {"blue ", "white"}) + private String color; + } + + @FixedObject + @Data + @NoArgsConstructor + @AllArgsConstructor + public static class KeepPaddingStone { + @FixedField(length = 5, keepPadding = KeepPadding.KEEP) + @FixedOption(options = {"blue ", "white"}) + private String color; + } +}