Skip to content

Commit

Permalink
feat(test): Implemented tests for interim numbers.
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Tegnér <johannes@jitesoft.com>
  • Loading branch information
Johannestegner committed Mar 13, 2023
1 parent 6deca46 commit 0865ef2
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions src/test/java/InterimnummerTest.java
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));
}
}

0 comments on commit 0865ef2

Please sign in to comment.