Skip to content

Commit

Permalink
Merge pull request #30 from joutvhu/development
Browse files Browse the repository at this point in the history
v1.1.4
  • Loading branch information
joutvhu authored Jul 6, 2021
2 parents 88f671b + 0f45488 commit 50bcd65
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -20,7 +20,7 @@ compile "com.github.joutvhu:fixed-width-parser:1.1.3"
<dependency>
<groupId>com.github.joutvhu</groupId>
<artifactId>fixed-width-parser</artifactId>
<version>1.1.3</version>
<version>1.1.4</version>
</dependency>
```

Expand Down
13 changes: 2 additions & 11 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ plugins {
}

group = 'com.github.joutvhu'
version '1.1.3'
version '1.1.4'
sourceCompatibility = 1.8
targetCompatibility = 1.8

Expand All @@ -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'
Expand Down Expand Up @@ -88,9 +81,7 @@ artifacts {
}

tasks.withType(Test) {
useJUnitPlatform {
includeEngines 'junit-jupiter'
}
useJUnitPlatform()
filter {
includeTestsMatching 'com.joutvhu.fixedwidth.parser.*'
}
Expand Down
Empty file modified gradlew
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
Expand Up @@ -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<Object> reader = module.createReaderBy(info, this);
if (reader != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
package com.joutvhu.fixedwidth.parser.util;

import lombok.experimental.UtilityClass;
import lombok.extern.log4j.Log4j2;

/**
* Ignore exception executor
*
* @author Giao Ho
* @since 1.0.0
*/
@Log4j2
@UtilityClass
public class IgnoreError {
public <E extends Exception> void execute(NoResultCaller<E> caller) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,9 @@ void validateFormattedFieldWithPadding(Sample sample) {
static List<Sample> 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 ")
);
}
Expand Down
60 changes: 60 additions & 0 deletions src/test/java/com/joutvhu/fixedwidth/parser/OptionTests.java
Original file line number Diff line number Diff line change
@@ -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;
}
}

0 comments on commit 50bcd65

Please sign in to comment.