@@ -55,21 +55,21 @@ void setUp() {
55
55
@ Test
56
56
void testPopulateSchoolMap_WhenApiCallSucceeds_ShouldPopulateMaps () {
57
57
// Given
58
- val school1ID = String . valueOf ( UUID .randomUUID () );
59
- val school2ID = String . valueOf ( UUID .randomUUID () );
60
- val school3ID = String . valueOf ( UUID .randomUUID () );
58
+ val school1ID = UUID .randomUUID ();
59
+ val school2ID = UUID .randomUUID ();
60
+ val school3ID = UUID .randomUUID ();
61
61
val school1 = SchoolTombstone .builder ()
62
- .schoolId (school1ID )
62
+ .schoolId (String . valueOf ( school1ID ) )
63
63
.displayName ("School 1" )
64
64
.independentAuthorityId ("Authority 1" )
65
65
.build ();
66
66
val school2 = SchoolTombstone .builder ()
67
- .schoolId (school2ID )
67
+ .schoolId (String . valueOf ( school2ID ) )
68
68
.displayName ("School 2" )
69
69
.independentAuthorityId ("Authority 1" )
70
70
.build ();
71
71
val school3 = SchoolTombstone .builder ()
72
- .schoolId (school3ID )
72
+ .schoolId (String . valueOf ( school3ID ) )
73
73
.displayName ("School 3" )
74
74
.independentAuthorityId ("Authority 2" )
75
75
.build ();
@@ -80,18 +80,20 @@ void testPopulateSchoolMap_WhenApiCallSucceeds_ShouldPopulateMaps() {
80
80
restUtils .populateSchoolMap ();
81
81
82
82
// Then verify the maps are populated
83
- Map <String , SchoolTombstone > schoolMap = (Map <String , SchoolTombstone >) ReflectionTestUtils .getField (restUtils , "schoolMap" );
84
- assertEquals (3 , schoolMap .size ());
85
- assertEquals (school1 , schoolMap .get (school1ID ));
86
- assertEquals (school2 , schoolMap .get (school2ID ));
87
- assertEquals (school3 , schoolMap .get (school3ID ));
83
+ List <SchoolTombstone > results = restUtils .getAllSchoolTombstones ();
84
+ assertNotNull (results );
85
+ assertEquals (3 , results .size ());
86
+ assertEquals (school1 , results .get (0 ));
87
+ assertEquals (school2 , results .get (1 ));
88
+ assertEquals (school3 , results .get (2 ));
88
89
89
- Map <String , List <UUID >> independentAuthorityToSchoolIDMap = (Map <String , List <UUID >>) ReflectionTestUtils .getField (restUtils , "independentAuthorityToSchoolIDMap" );
90
- assertEquals (2 , independentAuthorityToSchoolIDMap .size ());
91
- assertTrue (independentAuthorityToSchoolIDMap .containsKey ("Authority 1" ));
92
- assertTrue (independentAuthorityToSchoolIDMap .containsKey ("Authority 2" ));
93
- assertEquals (2 , independentAuthorityToSchoolIDMap .get ("Authority 1" ).size ());
94
- assertEquals (1 , independentAuthorityToSchoolIDMap .get ("Authority 2" ).size ());
90
+ doReturn (Optional .of (List .of (school1ID , school2ID ))).when (restUtils ).getSchoolIDsByIndependentAuthorityID ("Authority 1" );
91
+
92
+ Optional <List <UUID >> result = restUtils .getSchoolIDsByIndependentAuthorityID ("Authority 1" );
93
+
94
+ assertNotNull (result );
95
+ assertEquals (2 , result .get ().size ());
96
+ assertTrue (result .get ().equals (List .of (school1ID , school2ID )));
95
97
}
96
98
97
99
@ Test
@@ -130,42 +132,39 @@ void testPopulateDistrictMap_WhenApiCallSucceeds_ShouldPopulateMaps() {
130
132
@ Test
131
133
void testPopulateSchoolMap_WhenNoIndependentAuthorityId_ShouldPopulateMapsCorrectly () {
132
134
// Given
133
- val school1ID = String . valueOf ( UUID .randomUUID () );
134
- val school2ID = String . valueOf ( UUID .randomUUID () );
135
- val school3ID = String . valueOf ( UUID .randomUUID () );
135
+ val school1ID = UUID .randomUUID ();
136
+ val school2ID = UUID .randomUUID ();
137
+ val school3ID = UUID .randomUUID ();
136
138
val school1 = SchoolTombstone .builder ()
137
- .schoolId (school1ID )
139
+ .schoolId (String . valueOf ( school1ID ) )
138
140
.displayName ("School 1" )
139
141
.independentAuthorityId ("Authority 1" )
140
142
.build ();
141
143
val school2 = SchoolTombstone .builder ()
142
- .schoolId (school2ID )
144
+ .schoolId (String . valueOf ( school2ID ) )
143
145
.displayName ("School 2" )
144
146
.build ();
145
147
val school3 = SchoolTombstone .builder ()
146
- .schoolId (school3ID )
148
+ .schoolId (String . valueOf ( school3ID ) )
147
149
.displayName ("School 3" )
148
150
.independentAuthorityId ("Authority 2" )
149
151
.build ();
150
152
151
153
doReturn (List .of (school1 , school2 , school3 )).when (restUtils ).getAllSchoolTombstones ();
152
154
153
155
// When
154
- restUtils .populateSchoolMap ();
156
+ restUtils .getAllSchoolTombstones ();
155
157
156
158
// Then verify the maps are populated
157
- Map <String , SchoolTombstone > schoolMap = (Map <String , SchoolTombstone >) ReflectionTestUtils .getField (restUtils , "schoolMap" );
158
- assertEquals (3 , schoolMap .size ());
159
- assertEquals (school1 , schoolMap .get (school1ID ));
160
- assertEquals (school2 , schoolMap .get (school2ID ));
161
- assertEquals (school3 , schoolMap .get (school3ID ));
159
+ List <SchoolTombstone > results = restUtils .getAllSchoolTombstones ();
160
+ assertEquals (3 , results .size ());
162
161
163
- Map < String , List < UUID >> independentAuthorityToSchoolIDMap = ( Map < String , List < UUID >>) ReflectionTestUtils . getField (restUtils , "independentAuthorityToSchoolIDMap " );
164
- assertEquals ( 2 , independentAuthorityToSchoolIDMap . size ());
165
- assertTrue ( independentAuthorityToSchoolIDMap . containsKey ("Authority 1" ) );
166
- assertTrue ( independentAuthorityToSchoolIDMap . containsKey ( "Authority 2" ));
167
- assertEquals (1 , independentAuthorityToSchoolIDMap .get ("Authority 1" ).size ());
168
- assertEquals ( 1 , independentAuthorityToSchoolIDMap .get ("Authority 2" ). size ( ));
162
+ doReturn ( Optional . of ( List . of ( school1ID ))). when (restUtils ). getSchoolIDsByIndependentAuthorityID ( "Authority 1 " );
163
+
164
+ Optional < List < UUID >> result = restUtils . getSchoolIDsByIndependentAuthorityID ("Authority 1" );
165
+
166
+ assertEquals (1 , result .get ().size ());
167
+ assertTrue ( result .get (). equals ( List . of ( school1ID ) ));
169
168
}
170
169
171
170
@@ -242,21 +241,35 @@ void testPopulateSchoolMincodeMap_WhenApiCallSucceeds_ShouldPopulateMap() {
242
241
doReturn (List .of (school1 , school2 , school3 )).when (restUtils ).getAllSchoolTombstones ();
243
242
244
243
// When
245
- restUtils .populateSchoolMincodeMap ();
244
+ List < SchoolTombstone > results = restUtils .getAllSchoolTombstones ();
246
245
247
246
// Then verify the maps are populated
248
- Map <String , SchoolTombstone > schoolMincodeMap = (Map <String , SchoolTombstone >) ReflectionTestUtils .getField (restUtils , "schoolMincodeMap" );
249
- assertEquals (3 , schoolMincodeMap .size ());
250
- assertEquals (school1 , schoolMincodeMap .get (school1Mincode ));
251
- assertEquals (school2 , schoolMincodeMap .get (school2Mincode ));
252
- assertEquals (school3 , schoolMincodeMap .get (school3Mincode ));
253
-
247
+ assertEquals (3 , results .size ());
254
248
}
255
249
256
250
@ Test
257
251
void testGetSchoolFromMincodeMap_WhenApiCallSucceeds_ShouldReturnSchool () {
258
252
// Given
259
253
val school1Mincode = "97083" ;
254
+
255
+ val school1 = SchoolTombstone .builder ()
256
+ .schoolId (String .valueOf (UUID .randomUUID ()))
257
+ .displayName ("School 1" )
258
+ .independentAuthorityId ("Authority 1" )
259
+ .mincode (school1Mincode )
260
+ .build ();
261
+
262
+ doReturn (Optional .of (school1 )).when (restUtils ).getSchoolByMincode (school1Mincode );
263
+
264
+ // When
265
+ var result = restUtils .getSchoolByMincode (school1Mincode );
266
+ assertEquals (school1 , result .get ());
267
+ }
268
+
269
+ @ Test
270
+ void testGetSchoolsFromMincodeMap_WhenApiCallSucceeds_ShouldReturnSchools () {
271
+ // Given
272
+ val school1Mincode = "97083" ;
260
273
val school2Mincode = "97084" ;
261
274
val school3Mincode = "97085" ;
262
275
val school1 = SchoolTombstone .builder ()
@@ -279,8 +292,8 @@ void testGetSchoolFromMincodeMap_WhenApiCallSucceeds_ShouldReturnSchool() {
279
292
doReturn (List .of (school1 , school2 , school3 )).when (restUtils ).getAllSchoolTombstones ();
280
293
281
294
// When
282
- var result = restUtils .getSchoolByMincode ( school1Mincode );
283
- assertEquals (school1 , result . get () );
295
+ var result = restUtils .getAllSchoolTombstones ( );
296
+ assertEquals (List . of ( school1 , school2 , school3 ), result );
284
297
}
285
298
286
299
@ Test
@@ -436,3 +449,4 @@ void testGetMergedStudentIds_WhenExceptionOccurs_ShouldThrowStudentDataCollectio
436
449
);
437
450
}
438
451
}
452
+
0 commit comments