|
| 1 | +import java.io.IOException; |
| 2 | + |
| 3 | +import dev.personnummer.*; |
| 4 | +import org.junit.jupiter.api.BeforeAll; |
| 5 | +import org.junit.jupiter.params.ParameterizedTest; |
| 6 | +import org.junit.jupiter.params.provider.MethodSource; |
| 7 | + |
| 8 | +import static org.junit.jupiter.api.Assertions.*; |
| 9 | + |
| 10 | +public class InterimnummerTest { |
| 11 | + private static Options opts = new Options(true, true); |
| 12 | + |
| 13 | + @BeforeAll |
| 14 | + public static void setup() throws IOException { |
| 15 | + DataProvider.initialize(); |
| 16 | + } |
| 17 | + |
| 18 | + @ParameterizedTest |
| 19 | + @MethodSource("DataProvider#getValidInterimNumbers") |
| 20 | + public void testValidateInterim(PersonnummerData ssn) { |
| 21 | + assertTrue(Personnummer.valid(ssn.longFormat, opts)); |
| 22 | + assertTrue(Personnummer.valid(ssn.shortFormat, opts)); |
| 23 | + } |
| 24 | + |
| 25 | + @ParameterizedTest |
| 26 | + @MethodSource("DataProvider#getInvalidInterimNumbers") |
| 27 | + public void testValidateInvalidInterim(PersonnummerData ssn) { |
| 28 | + assertFalse(Personnummer.valid(ssn.longFormat, opts)); |
| 29 | + assertFalse(Personnummer.valid(ssn.shortFormat, opts)); |
| 30 | + } |
| 31 | + |
| 32 | + @ParameterizedTest |
| 33 | + @MethodSource("DataProvider#getValidInterimNumbers") |
| 34 | + public void testFormatLongInterim(PersonnummerData ssn) throws PersonnummerException { |
| 35 | + Personnummer pnr = Personnummer.parse(ssn.longFormat, opts); |
| 36 | + |
| 37 | + assertEquals(pnr.format(false), ssn.longFormat); |
| 38 | + assertEquals(pnr.format(), ssn.separatedFormat); |
| 39 | + } |
| 40 | + |
| 41 | + @ParameterizedTest |
| 42 | + @MethodSource("DataProvider#getValidInterimNumbers") |
| 43 | + public void testFormatShortInterim(PersonnummerData ssn) throws PersonnummerException { |
| 44 | + Personnummer pnr = Personnummer.parse(ssn.shortFormat, opts); |
| 45 | + |
| 46 | + assertEquals(pnr.format(false), ssn.longFormat); |
| 47 | + assertEquals(pnr.format(), ssn.separatedFormat); |
| 48 | + } |
| 49 | + |
| 50 | + @ParameterizedTest |
| 51 | + @MethodSource("DataProvider#getInvalidInterimNumbers") |
| 52 | + public void testInvalidInterimThrows(PersonnummerData ssn) { |
| 53 | + assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.shortFormat, opts)); |
| 54 | + assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.longFormat, opts)); |
| 55 | + assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.separatedLong, opts)); |
| 56 | + assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.separatedFormat, opts)); |
| 57 | + } |
| 58 | + |
| 59 | + @ParameterizedTest |
| 60 | + @MethodSource("DataProvider#getValidInterimNumbers") |
| 61 | + public void testInterimThrowsIfNotActive(PersonnummerData ssn) { |
| 62 | + assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.shortFormat)); |
| 63 | + assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.longFormat)); |
| 64 | + assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.separatedLong)); |
| 65 | + assertThrows(PersonnummerException.class, () -> Personnummer.parse(ssn.separatedFormat)); |
| 66 | + } |
| 67 | +} |
0 commit comments