Skip to content

Commit

Permalink
Merge pull request #35 from Johannestegner/master
Browse files Browse the repository at this point in the history
feat: Allow + in enskild firma.
  • Loading branch information
Johannestegner authored Feb 20, 2024
2 parents 7a11bdd + 05bc663 commit 3a0f7b8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ public Organisationsnummer(String input) throws OrganisationsnummerException {
* @return Formatted string.
*/
public String format(boolean separator) {
if (separator && this.isPersonnummer) {
return this.innerPersonnummer.format(false);
}

String nr = this.getShortString();

return separator ?
Expand Down Expand Up @@ -156,6 +160,7 @@ private void innerParse(String input) throws OrganisationsnummerException {
throw new OrganisationsnummerException("Input value too " + (input.length() > 13 ? "long" : "short"));
}

String originalInput = input;
try {
Matcher matches = regexPattern.matcher(input);
if (!matches.find()) {
Expand All @@ -181,7 +186,7 @@ private void innerParse(String input) throws OrganisationsnummerException {

} catch (OrganisationsnummerException e) {
try {
this.innerPersonnummer = Personnummer.parse(input);
this.innerPersonnummer = Personnummer.parse(originalInput);
this.isPersonnummer = true;
} catch (PersonnummerException ex) {
throw new OrganisationsnummerException();
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/OrganisationsnummerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testFormatWithoutSeparator(OrgNrData input) throws Organisationsnumm
@ParameterizedTest
@MethodSource("DataProvider#getValid")
public void testFormatWithSeparator(OrgNrData input) throws OrganisationsnummerException {
assertEquals(input.longFormat, Organisationsnummer.parse(input.shortFormat).format(true));
assertEquals(input.longFormat.replace('+', '-'), Organisationsnummer.parse(input.shortFormat).format(true));
assertEquals(input.longFormat, Organisationsnummer.parse(input.longFormat).format(true));
}

Expand Down

0 comments on commit 3a0f7b8

Please sign in to comment.