Skip to content

Commit 6deca46

Browse files
feat(test): Added data provider for interim numbers in tests.
Signed-off-by: Johannes Tegnér <[email protected]>
1 parent 6134deb commit 6deca46

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/test/java/DataProvider.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
public class DataProvider {
1111
private static final List<PersonnummerData> all = new ArrayList<>();
1212
private static final List<PersonnummerData> orgNr = new ArrayList<>();
13+
private static final List<PersonnummerData> interimNr = new ArrayList<>();
1314

1415
public static void initialize() throws IOException {
1516
InputStream in = new URL("https://raw.githubusercontent.com/personnummer/meta/master/testdata/list.json").openStream();
@@ -55,8 +56,38 @@ public static void initialize() throws IOException {
5556
current.getString("type")
5657
));
5758
}
59+
60+
61+
in = new URL("https://raw.githubusercontent.com/personnummer/meta/master/testdata/interim.json").openStream();
62+
reader = new BufferedReader(new InputStreamReader(in));
63+
json = "";
64+
while ((line = reader.readLine()) != null) {
65+
json = json.concat(line);
66+
}
67+
68+
in.close();
69+
rootObject = new JSONArray(json);
70+
for (int i = 0; i < rootObject.length(); i++) {
71+
JSONObject current = rootObject.getJSONObject(i);
72+
interimNr.add(new PersonnummerData(
73+
current.getLong("integer"),
74+
current.getString("short_format"),
75+
current.getString("separated_format"),
76+
current.getBoolean("valid"),
77+
current.getString("type")
78+
));
79+
}
5880
}
5981

82+
public static List<PersonnummerData> getInterimNumbers() {
83+
return interimNr;
84+
}
85+
public static List<PersonnummerData> getValidInterimNumbers() {
86+
return interimNr.stream().filter(o -> o.valid).collect(Collectors.toList());
87+
}
88+
public static List<PersonnummerData> getInvalidInterimNumbers() {
89+
return interimNr.stream().filter(o -> !o.valid).collect(Collectors.toList());
90+
}
6091
public static List<PersonnummerData> getCoordinationNumbers() {
6192
return all.stream().filter(o -> !o.type.equals("ssn")).collect(Collectors.toList());
6293
}

0 commit comments

Comments
 (0)