diff --git a/src/main/java/dev/organisationsnummer/Organisationsnummer.java b/src/main/java/dev/organisationsnummer/Organisationsnummer.java index 0298d85..bd4fa1f 100644 --- a/src/main/java/dev/organisationsnummer/Organisationsnummer.java +++ b/src/main/java/dev/organisationsnummer/Organisationsnummer.java @@ -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 ? @@ -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()) { @@ -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(); diff --git a/src/test/java/OrganisationsnummerTest.java b/src/test/java/OrganisationsnummerTest.java index 1086c5e..2c3219b 100644 --- a/src/test/java/OrganisationsnummerTest.java +++ b/src/test/java/OrganisationsnummerTest.java @@ -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)); }