22
33import ee .sk .smartid .AuthenticationIdentity ;
44import ee .sk .smartid .AuthenticationResponseValidator ;
5+ import ee .sk .smartid .exception .UnprocessableSmartIdResponseException ;
6+ import org .junit .Assert ;
57import org .junit .Test ;
68
79import java .security .cert .CertificateException ;
1012
1113import static ee .sk .smartid .AuthenticationResponseValidatorTest .*;
1214import static org .hamcrest .MatcherAssert .assertThat ;
13- import static org .hamcrest .Matchers .is ;
14- import static org .hamcrest .Matchers .notNullValue ;
15+ import static org .hamcrest .Matchers .*;
1516
1617public class NationalIdentityNumberUtilTest {
1718
@@ -32,15 +33,15 @@ public void getDateOfBirthFromIdCode_estonianIdCode_returns() throws Certificate
3233
3334 @ Test
3435 public void getDateOfBirthFromIdCode_latvianIdCode_returns () throws CertificateException {
35- X509Certificate lvCertificate = getX509Certificate (getX509CertificateBytes (AUTH_CERTIFICATE_LV ));
36+ X509Certificate lvCertificate = getX509Certificate (getX509CertificateBytes (AUTH_CERTIFICATE_LV_DOB_03_APRIL_1903 ));
3637
3738 AuthenticationResponseValidator validator = new AuthenticationResponseValidator ();
3839 AuthenticationIdentity identity = validator .constructAuthenticationIdentity (lvCertificate );
3940
4041 LocalDate dateOfBirth = NationalIdentityNumberUtil .getDateOfBirth (identity );
4142
4243 assertThat (dateOfBirth , is (notNullValue ()));
43- assertThat (dateOfBirth , is (LocalDate .of (2017 , 1 , 1 )));
44+ assertThat (dateOfBirth , is (LocalDate .of (1903 , 4 , 3 )));
4445 }
4546
4647 @ Test
@@ -56,4 +57,46 @@ public void getDateOfBirthFromIdCode_lithuanianIdCode_returns() throws Certifica
5657 assertThat (dateOfBirth , is (LocalDate .of (1960 , 9 , 6 )));
5758 }
5859
60+ @ Test
61+ public void parseLvDateOfBirth_withoutDateOfBirth_returnsNull () {
62+ LocalDate birthDate = NationalIdentityNumberUtil .parseLvDateOfBirth ("321205-1234" );
63+ assertThat (birthDate , is (nullValue ()));
64+ }
65+
66+ @ Test
67+ public void parseLvDateOfBirth_21century () {
68+ LocalDate birthDate = NationalIdentityNumberUtil .parseLvDateOfBirth ("131205-2234" );
69+ assertThat (birthDate , is (LocalDate .of (2005 , 12 , 13 )));
70+ }
71+
72+ @ Test
73+ public void parseLvDateOfBirth_20century () {
74+ LocalDate birthDate = NationalIdentityNumberUtil .parseLvDateOfBirth ("131265-1234" );
75+ assertThat (birthDate , is (LocalDate .of (1965 , 12 , 13 )));
76+ }
77+
78+ @ Test
79+ public void parseLvDateOfBirth_19century () {
80+ LocalDate birthDate = NationalIdentityNumberUtil .parseLvDateOfBirth ("131265-0234" );
81+ assertThat (birthDate , is (LocalDate .of (1865 , 12 , 13 )));
82+ }
83+
84+ @ Test
85+ public void parseLvDateOfBirth_invalidMonth_throwsException () {
86+ UnprocessableSmartIdResponseException exception = Assert .assertThrows (UnprocessableSmartIdResponseException .class , () -> {
87+ NationalIdentityNumberUtil .parseLvDateOfBirth ("131365-1234" );
88+ });
89+
90+ assertThat (exception .getMessage (), is ("Unable get birthdate from Latvian personal code 131365-1234" ));
91+ }
92+
93+ @ Test
94+ public void parseLvDateOfBirth_invalidIdCode_throwsException () {
95+ UnprocessableSmartIdResponseException exception = Assert .assertThrows (UnprocessableSmartIdResponseException .class , () -> {
96+ NationalIdentityNumberUtil .parseLvDateOfBirth ("331265-0234" );
97+ });
98+
99+ assertThat (exception .getMessage (), is ("Unable get birthdate from Latvian personal code 331265-0234" ));
100+ }
101+
59102}
0 commit comments