Skip to content

Commit

Permalink
fix: Minor fix to day fetching for coordination numbers in date test.
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 5050e24 commit 2493f87
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions src/test/java/PersonnummerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void testParse(PersonnummerData ssn) {
assertDoesNotThrow(() -> Personnummer.parse(ssn.separatedFormat, new Options(false)));
assertDoesNotThrow(() -> Personnummer.parse(ssn.separatedFormat, new Options(false)));
}

@ParameterizedTest
@MethodSource("DataProvider#getDate")
public void testDate(PersonnummerData ssn) {
Expand All @@ -72,31 +72,36 @@ public void testDate(PersonnummerData ssn) {
data.add(new Personnummer(ssn.longFormat, new Options()));
data.add(new Personnummer(ssn.shortFormat, new Options()));
data.add(new Personnummer(ssn.separatedFormat, new Options()));

data.forEach(entry -> {

assertDoesNotThrow(() -> entry.getDate());
LocalDateTime dateTime = entry.getDate();
String expectedYear = entry.getFullYear();
String expectedMonth = entry.getMonth();
if(expectedMonth.charAt(0)=='0')
expectedMonth = expectedMonth.substring(1);
String expectedDate = String.valueOf(entry.getRealDay());
int day = Integer.parseInt(entry.getDay());
if (day > 60) {
day -= 60;
}

String expectedDate = String.valueOf(day);
if(expectedDate.charAt(0)=='0')
expectedDate = expectedDate.substring(1);
// Integer expected = Integer.valueOf(ssn.longFormat.substring(0,4));
String actualYear = String.valueOf(dateTime.getYear());
String actualMonth = String.valueOf(dateTime.getMonth().getValue());
String actualDate = String.valueOf(dateTime.getDayOfMonth());

assertEquals(expectedYear, actualYear); //, "expected year = " + expectedYear + "\n" + "Actual year = " + actualYear);
assertEquals(expectedMonth, actualMonth);//, "expected month = " + expectedMonth + "\n" + "Actual month = " + actualMonth);
assertEquals(expectedDate, actualDate); //, "expected date = " + expectedDate + "\n" + "Actual date = " + actualDate);

});



} catch (PersonnummerException e) {
// TODO Auto-generated catch block
e.printStackTrace();
Expand Down

0 comments on commit 2493f87

Please sign in to comment.