Skip to content

Commit

Permalink
fix 2 letters names and surnames
Browse files Browse the repository at this point in the history
  • Loading branch information
kamaladafrica committed Feb 22, 2022
1 parent 58263d8 commit bdb42ec
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package it.kamaladafrica.codicefiscale.internal;

import static it.kamaladafrica.codicefiscale.utils.PartUtils.extractConsonants;
import static it.kamaladafrica.codicefiscale.utils.PartUtils.extractVowels;
import static it.kamaladafrica.codicefiscale.utils.PartUtils.normalizeString;
import static org.apache.commons.lang3.Validate.matchesPattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;

import lombok.AccessLevel;
import lombok.EqualsAndHashCode;
import lombok.RequiredArgsConstructor;
import lombok.Value;
import org.apache.commons.lang3.Validate;

import static it.kamaladafrica.codicefiscale.utils.PartUtils.*;
import static org.apache.commons.lang3.Validate.matchesPattern;

@Value
@RequiredArgsConstructor(access = AccessLevel.PRIVATE)
Expand All @@ -25,6 +29,7 @@ public class LastnamePart extends AbstractPart {
public static LastnamePart from(String value) {
Validate.notEmpty(value, "invalid name: %s", value);
matchesPattern(value, VALIDATION_PATTERN, "invalid value: %s", value);
value = StringUtils.removeEnd(value, "X");
return of(value);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import static it.kamaladafrica.codicefiscale.utils.PartUtils.normalizeString;
import static org.apache.commons.lang3.Validate.matchesPattern;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.Validate;

import lombok.AccessLevel;
Expand All @@ -30,6 +31,7 @@ public class NamePart extends AbstractPart {
public static NamePart from(String value) {
Validate.notEmpty(value, "invalid name: %s", value);
matchesPattern(value, VALIDATION_PATTERN, "invalid value: %s", value);
value = StringUtils.removeEnd(value, "X");
return of(value);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package it.kamaladafrica.codicefiscale.internal;

import org.junit.Test;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

public class LastnamePartTest {

@Test
Expand All @@ -16,4 +16,14 @@ public void testOf() {
assertEquals("RSS", LastnamePart.of("Rossini").getValue());
}

@Test
public void testFromPlaceholder() {
assertEquals("BO", NamePart.from("BOX").getName());
}

@Test
public void testOf2Letters() {
assertEquals("BOX", NamePart.of("Bo").getValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class NamePartTest {

@Test
public void testFromString() {
assertEquals("MRA", NamePart.from("MRA").getValue());
assertEquals("MRA", NamePart.from("MRA").getName());
}

@Test
Expand All @@ -26,4 +26,14 @@ public void testOf3Consonants() {
assertEquals("MRC", NamePart.of("Marco").getValue());
}

@Test
public void testFromPlaceholder() {
assertEquals("BO", NamePart.from("BOX").getName());
}

@Test
public void testOf2Letters() {
assertEquals("BOX", NamePart.of("Bo").getValue());
}

}

0 comments on commit bdb42ec

Please sign in to comment.