Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,16 @@
*/
public class KorRRNValidator implements ConstraintValidator<KorRRN, CharSequence> {

private static final List<Integer> GENDER_DIGIT = List.of( 1, 2, 3, 4 );
// Gender digit in Korean Resident Registration Number (RRN):
// 1: Male, born 1900–1999
// 2: Female, born 1900–1999
// 3: Male, born 2000–2099
// 4: Female, born 2000–2099
// 5: Foreign male, born 1900–1999
// 6: Foreign female, born 1900–1999
// 7: Foreign male, born 2000–2099
// 8: Foreign female, born 2000–2099
private static final List<Integer> GENDER_DIGIT = List.of( 1, 2, 3, 4, 5, 6, 7, 8 );
// Check sum weight for ModUtil
private static final int[] CHECK_SUM_WEIGHT = new int[] { 5, 4, 3, 2, 9, 8, 7, 6, 5, 4, 3, 2 };
// index of the digit representing the gender
Expand Down Expand Up @@ -90,7 +99,7 @@ private static boolean isValidDate(final String rrn) {
if ( month < 1 || month > 12 || day < 1 || day > 31 ) {
return false;
}
return day <= 31 && ( day <= 30 || ( month != 4 && month != 6 && month != 9 && month != 11 ) ) && ( day <= 29 || month != 2 );
return ( day <= 30 || month != 4 && month != 6 && month != 9 && month != 11 ) && ( day <= 29 || month != 2 );
}

private static boolean isValidLength(String rrn) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ void setUp() {
// valid RRN
@Test
void testBeforeOctober2020OnlyAttr() {

assertValidRRN( "861224-2567484" );
assertValidRRN( "960223-2499378" );
assertValidRRN( "790707-1133360" );
Expand Down Expand Up @@ -71,6 +70,14 @@ void invalidDate() {
assertInvalidRRN( "999999-6609491" );
}

@Test
void testAlwaysForeignerGenderDigits() {
assertValidRRN( "850101-5000005" );
assertValidRRN( "920202-6000003" );
assertValidRRN( "010101-7000006" );
assertValidRRN( "030303-8000001" );
}

// Invalid RRN Length
@Test
void invalidLength() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ void testNeverAttr() {
assertValidRRN( "750519-1404601" );
}

@Test
void testNeverForeignerGenderDigits() {
assertValidRRN( "850101-5000000" );
assertValidRRN( "920202-6000000" );
assertValidRRN( "010101-7000000" );
assertValidRRN( "030303-8000000" );
}

/**
* The test succeeds without hyphen ('-')
*/
Expand Down