From 05bc663ae9ac268b16a26c6fd370d38f83d1dc52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Johannes=20Tegn=C3=A9r?= Date: Tue, 20 Feb 2024 17:41:16 +0100 Subject: [PATCH] feat: Allow + in enskild firma. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Johannes Tegnér --- .../java/dev/organisationsnummer/Organisationsnummer.java | 7 ++++++- src/test/java/OrganisationsnummerTest.java | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) 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)); }