-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(test): Implemented tests for interim numbers.
Signed-off-by: Johannes Tegnér <johannes@jitesoft.com>
- Loading branch information
1 parent
6deca46
commit 0865ef2
Showing
1 changed file
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import java.io.IOException; | ||
|
||
import dev.personnummer.*; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class InterimnummerTest { | ||
private static Options opts = new Options(true, true); | ||
|
||
@BeforeAll | ||
public static void setup() throws IOException { | ||
DataProvider.initialize(); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("DataProvider#getValidInterimNumbers") | ||
public void testValidateInterim(PersonnummerData ssn) { | ||
assertTrue(Personnummer.valid(ssn.longFormat, opts)); | ||
assertTrue(Personnummer.valid(ssn.shortFormat, opts)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("DataProvider#getInvalidInterimNumbers") | ||
public void testValidateInvalidInterim(PersonnummerData ssn) { | ||
assertFalse(Personnummer.valid(ssn.longFormat, opts)); | ||
assertFalse(Personnummer.valid(ssn.shortFormat, opts)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("DataProvider#getValidInterimNumbers") | ||
public void testFormatLongInterim(PersonnummerData ssn) throws PersonnummerException { | ||
Personnummer pnr = Personnummer.parse(ssn.longFormat, opts); | ||
|
||
assertEquals(pnr.format(false), ssn.longFormat); | ||
assertEquals(pnr.format(), ssn.separatedFormat); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("DataProvider#getValidInterimNumbers") | ||
public void testFormatShortInterim(PersonnummerData ssn) throws PersonnummerException { | ||
Personnummer pnr = Personnummer.parse(ssn.shortFormat, opts); | ||
|
||
assertEquals(pnr.format(false), ssn.longFormat); | ||
assertEquals(pnr.format(), ssn.separatedFormat); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("DataProvider#getInvalidInterimNumbers") | ||
public void testInvalidInterimThrows(PersonnummerData ssn) { | ||
assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.shortFormat, opts)); | ||
assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.longFormat, opts)); | ||
assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.separatedLong, opts)); | ||
assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.separatedFormat, opts)); | ||
} | ||
|
||
@ParameterizedTest | ||
@MethodSource("DataProvider#getValidInterimNumbers") | ||
public void testInterimThrowsIfNotActive(PersonnummerData ssn) { | ||
assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.shortFormat)); | ||
assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.longFormat)); | ||
assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.separatedLong)); | ||
assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.separatedFormat)); | ||
} | ||
} |