11package de .symeda .sormas .backend .externaljournal ;
22
3+ import de .symeda .sormas .api .externaljournal .PatientDiaryPersonQueryResponse ;
34import de .symeda .sormas .api .person .PersonDto ;
45
56import de .symeda .sormas .api .person .Sex ;
67import de .symeda .sormas .api .person .SymptomJournalStatus ;
78import de .symeda .sormas .api .utils .DataHelper ;
89import de .symeda .sormas .backend .AbstractBeanTest ;
910
11+ import org .junit .Before ;
1012import org .junit .Test ;
13+ import org .mockito .MockitoAnnotations ;
14+ import org .mockito .Spy ;
1115
1216import java .lang .reflect .InvocationTargetException ;
1317import java .lang .reflect .Method ;
1418import java .util .HashMap ;
1519import java .util .Map ;
20+ import java .util .Optional ;
1621
1722import static org .junit .Assert .assertFalse ;
1823import static org .junit .Assert .assertTrue ;
24+ import static org .mockito .Mockito .doReturn ;
1925
2026public class ExternalJournalServiceTest extends AbstractBeanTest {
2127
28+ @ Spy
29+ private ExternalJournalService externalJournalService ;
30+
31+ @ Before
32+ public void setUp () {
33+ MockitoAnnotations .initMocks (this );
34+ PatientDiaryPersonQueryResponse patientDiaryPersonQueryResponse = new PatientDiaryPersonQueryResponse ();
35+ patientDiaryPersonQueryResponse .setCount (0 );
36+ doReturn (
Optional .
ofNullable (
patientDiaryPersonQueryResponse )).
when (
externalJournalService ).
queryPatientDiary (
"Email" ,
"[email protected] " );
37+ doReturn (Optional .ofNullable (patientDiaryPersonQueryResponse )).when (externalJournalService ).queryPatientDiary ("Email" , "test@test" );
38+ doReturn (
Optional .
ofNullable (
patientDiaryPersonQueryResponse )).
when (
externalJournalService ).
queryPatientDiary (
"Email" ,
"[email protected] " );
39+ doReturn (Optional .ofNullable (patientDiaryPersonQueryResponse )).when (externalJournalService )
40+ .queryPatientDiary ("Mobile phone" , "+49 621 1218490" );
41+ doReturn (Optional .ofNullable (patientDiaryPersonQueryResponse )).when (externalJournalService )
42+ .queryPatientDiary ("Mobile phone" , "+49 621 1218491" );
43+ doReturn (Optional .ofNullable (patientDiaryPersonQueryResponse )).when (externalJournalService ).queryPatientDiary ("Mobile phone" , "0" );;
44+ }
45+
2246 @ Test
2347 /*
2448 * If you need to change this test to make it pass, you probably changed the behaviour of the ExternalVisitsResource.
@@ -27,10 +51,11 @@ public class ExternalJournalServiceTest extends AbstractBeanTest {
2751 * https://gitter.im/SORMAS-Project!
2852 */
2953 public void givenValidEmailIsExportable () {
30-
54+ PatientDiaryPersonQueryResponse response = new PatientDiaryPersonQueryResponse ();
55+ response .setCount (0 );
3156 PersonDto person = new PersonDto ();
3257 person .
setEmailAddress (
"[email protected] " );
33- assertTrue (getExternalJournalService () .validatePatientDiaryPerson (person , true ).isValid ());
58+ assertTrue (externalJournalService .validatePatientDiaryPerson (person ).isValid ());
3459 }
3560
3661 @ Test
@@ -43,9 +68,9 @@ public void givenValidEmailIsExportable() {
4368 public void givenInvalidEmailIsNotExportable () {
4469 PersonDto person = new PersonDto ();
4570 person .setEmailAddress ("test@test" );
46- assertFalse (getExternalJournalService () .validatePatientDiaryPerson (person , true ).isValid ());
71+ assertFalse (externalJournalService .validatePatientDiaryPerson (person ).isValid ());
4772 person .setPhone ("+496211218490" );
48- assertFalse (getExternalJournalService () .validatePatientDiaryPerson (person , true ).isValid ());
73+ assertFalse (externalJournalService .validatePatientDiaryPerson (person ).isValid ());
4974 }
5075
5176 @ Test
@@ -59,7 +84,7 @@ public void givenValidPhoneIsExportable() {
5984
6085 PersonDto person = new PersonDto ();
6186 person .setPhone ("+496211218490" );
62- assertTrue (getExternalJournalService () .validatePatientDiaryPerson (person , true ).isValid ());
87+ assertTrue (externalJournalService .validatePatientDiaryPerson (person ).isValid ());
6388 }
6489
6590 @ Test
@@ -73,9 +98,9 @@ public void givenInvalidPhoneIsNotExportable() {
7398
7499 PersonDto person = new PersonDto ();
75100 person .setPhone ("0" );
76- assertFalse (getExternalJournalService ().validatePatientDiaryPerson (person , true ).isValid ());
101+ assertFalse (getExternalJournalService ().validatePatientDiaryPerson (person ).isValid ());
77102 person .
setEmailAddress (
"[email protected] " );
78- assertFalse (getExternalJournalService () .validatePatientDiaryPerson (person , true ).isValid ());
103+ assertFalse (externalJournalService .validatePatientDiaryPerson (person ).isValid ());
79104 }
80105
81106 @ Test
@@ -91,7 +116,7 @@ public void givenNeitherEmailNorPhoneIsNotExportable() {
91116 person .setBirthdateYYYY (2000 );
92117 person .setBirthdateMM (6 );
93118 person .setBirthdateDD (1 );
94- assertFalse (getExternalJournalService () .validatePatientDiaryPerson (person , true ).isValid ());
119+ assertFalse (externalJournalService .validatePatientDiaryPerson (person ).isValid ());
95120 }
96121
97122 @ Test
@@ -106,12 +131,12 @@ public void givenIncompleteBirthdateIsNotExportable() {
106131 person .
setEmailAddress (
"[email protected] " );
107132 person .setPhone ("+496211218490" );
108133 person .setBirthdateYYYY (2000 );
109- assertFalse (getExternalJournalService () .validatePatientDiaryPerson (person , true ).isValid ());
134+ assertFalse (externalJournalService .validatePatientDiaryPerson (person ).isValid ());
110135 person .setBirthdateMM (6 );
111- assertFalse (getExternalJournalService () .validatePatientDiaryPerson (person , true ).isValid ());
136+ assertFalse (externalJournalService .validatePatientDiaryPerson (person ).isValid ());
112137 person .setBirthdateYYYY (null );
113138 person .setBirthdateDD (1 );
114- assertFalse (getExternalJournalService () .validatePatientDiaryPerson (person , true ).isValid ());
139+ assertFalse (externalJournalService .validatePatientDiaryPerson (person ).isValid ());
115140 }
116141
117142 @ Test
0 commit comments