Skip to content

Commit

Permalink
feat(test): Added data provider for interim numbers in tests.
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Tegnér <[email protected]>
  • Loading branch information
Johannestegner committed Mar 13, 2023
1 parent 6134deb commit 6deca46
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions src/test/java/DataProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
public class DataProvider {
private static final List<PersonnummerData> all = new ArrayList<>();
private static final List<PersonnummerData> orgNr = new ArrayList<>();
private static final List<PersonnummerData> interimNr = new ArrayList<>();

public static void initialize() throws IOException {
InputStream in = new URL("https://raw.githubusercontent.com/personnummer/meta/master/testdata/list.json").openStream();
Expand Down Expand Up @@ -55,8 +56,38 @@ public static void initialize() throws IOException {
current.getString("type")
));
}


in = new URL("https://raw.githubusercontent.com/personnummer/meta/master/testdata/interim.json").openStream();
reader = new BufferedReader(new InputStreamReader(in));
json = "";
while ((line = reader.readLine()) != null) {
json = json.concat(line);
}

in.close();
rootObject = new JSONArray(json);
for (int i = 0; i < rootObject.length(); i++) {
JSONObject current = rootObject.getJSONObject(i);
interimNr.add(new PersonnummerData(
current.getLong("integer"),
current.getString("short_format"),
current.getString("separated_format"),
current.getBoolean("valid"),
current.getString("type")
));
}
}

public static List<PersonnummerData> getInterimNumbers() {
return interimNr;
}
public static List<PersonnummerData> getValidInterimNumbers() {
return interimNr.stream().filter(o -> o.valid).collect(Collectors.toList());
}
public static List<PersonnummerData> getInvalidInterimNumbers() {
return interimNr.stream().filter(o -> !o.valid).collect(Collectors.toList());
}
public static List<PersonnummerData> getCoordinationNumbers() {
return all.stream().filter(o -> !o.type.equals("ssn")).collect(Collectors.toList());
}
Expand Down

0 comments on commit 6deca46

Please sign in to comment.