2121
2222class  TripViaLocationMapperTest  {
2323
24-   public  static  final  String  LABEL  = "TestLabel" ;
25-   public  static  final  Duration  MIN_WAIT_TIME  = Duration .ofMinutes (5 );
26-   public  static  final  List <String > LIST_IDS_INPUT  = List .of ("F:ID1" , "F:ID2" );
27-   public  static  final  String  EXPECTED_IDS_AS_STRING  = "[F:ID1, F:ID2]" ;
24+   private  static  final  String  LABEL  = "TestLabel" ;
25+   private  static  final  Duration  MIN_WAIT_TIME  = Duration .ofMinutes (5 );
26+   private  static  final  List <String > LIST_IDS_INPUT  = List .of ("F:ID1" , "F:ID2" );
27+   private  static  final  String  EXPECTED_IDS_AS_STRING  = "[F:ID1, F:ID2]" ;
28+   private  static  final  String  REASON_EMPTY_IDS_ALLOWED_PASS_THROUGH  =
29+     """ 
30+     Unfortunately the 'placeIds' is not required. Making it required would be a breaking change, 
31+     so wee just ignore it." 
32+     """ ;
2833
2934  @ BeforeEach 
3035  void  setup () {
@@ -52,10 +57,7 @@ void testMapToVisitViaLocations() {
5257
5358  @ Test 
5459  void  testMapToVisitViaLocationsWithBareMinimum () {
55-     Map <String , Object > input  = Map .of (
56-       FIELD_VISIT ,
57-       Map .of (FIELD_STOP_LOCATION_IDS , List .of ("F:1" ))
58-     );
60+     Map <String , Object > input  = mapOf (FIELD_VISIT , mapOf (FIELD_STOP_LOCATION_IDS , List .of ("F:1" )));
5961    var  result  = TripViaLocationMapper .mapToViaLocations (List .of (input ));
6062
6163    var  via  = result .getFirst ();
@@ -66,9 +68,32 @@ void testMapToVisitViaLocationsWithBareMinimum() {
6668    assertFalse (via .isPassThroughLocation ());
6769  }
6870
71+   @ Test 
72+   void  testMapToVisitViaLocationsWithoutIds () {
73+     Map <String , Object > input  = mapOf (FIELD_VISIT , mapOf (FIELD_STOP_LOCATION_IDS , null ));
74+     var  ex  = assertThrows (
75+       IllegalArgumentException .class ,
76+       () -> TripViaLocationMapper .mapToViaLocations (List .of (input ))
77+     );
78+     assertEquals ("'stopLocationIds' is not set!" , ex .getMessage ());
79+   }
80+ 
81+   @ Test 
82+   void  testMapToVisitViaLocationsWithAnEmptyListOfIds () {
83+     Map <String , Object > input  = mapOf (FIELD_VISIT , mapOf (FIELD_STOP_LOCATION_IDS , List .of ()));
84+     var  ex  = assertThrows (
85+       IllegalArgumentException .class ,
86+       () -> TripViaLocationMapper .mapToViaLocations (List .of (input ))
87+     );
88+     assertEquals (
89+       "A via location must have at least one stop location or a coordinate." ,
90+       ex .getMessage ()
91+     );
92+   }
93+ 
6994  @ Test 
7095  void  tetMapToPassThrough () {
71-     Map <String , Object > input  = Map . of (FIELD_PASS_THROUGH , passThroughInput (LABEL , LIST_IDS_INPUT ));
96+     Map <String , Object > input  = mapOf (FIELD_PASS_THROUGH , passThroughInput (LABEL , LIST_IDS_INPUT ));
7297    var  result  = TripViaLocationMapper .mapToViaLocations (List .of (input ));
7398    var  via  = result .getFirst ();
7499
@@ -83,9 +108,9 @@ void tetMapToPassThrough() {
83108
84109  @ Test 
85110  void  tetMapToPassThroughWithBareMinimum () {
86-     Map <String , Object > input  = Map . of (
111+     Map <String , Object > input  = mapOf (
87112      FIELD_PASS_THROUGH ,
88-       Map . of (FIELD_STOP_LOCATION_IDS , List .of ("F:1" ))
113+       mapOf (FIELD_STOP_LOCATION_IDS , List .of ("F:1" ))
89114    );
90115    var  result  = TripViaLocationMapper .mapToViaLocations (List .of (input ));
91116    var  via  = result .getFirst ();
@@ -95,6 +120,32 @@ void tetMapToPassThroughWithBareMinimum() {
95120    assertTrue (via .isPassThroughLocation ());
96121  }
97122
123+   @ Test 
124+   void  tetMapToPassThroughWithoutIds () {
125+     Map <String , Object > input  = mapOf (FIELD_PASS_THROUGH , mapOf (FIELD_STOP_LOCATION_IDS , null ));
126+     var  ex  = assertThrows (
127+       IllegalArgumentException .class ,
128+       () -> TripViaLocationMapper .mapToViaLocations (List .of (input ))
129+     );
130+     assertEquals ("'stopLocationIds' is not set!" , ex .getMessage ());
131+   }
132+ 
133+   @ Test 
134+   void  testMapToPassThroughWithAnEmptyListOfIds () {
135+     Map <String , Object > input  = mapOf (
136+       FIELD_PASS_THROUGH ,
137+       mapOf (FIELD_STOP_LOCATION_IDS , List .of ())
138+     );
139+     var  ex  = assertThrows (
140+       IllegalArgumentException .class ,
141+       () -> TripViaLocationMapper .mapToViaLocations (List .of (input ))
142+     );
143+     assertEquals (
144+       "A pass through via location must have at least one stop location." ,
145+       ex .getMessage ()
146+     );
147+   }
148+ 
98149  @ Test 
99150  void  testOneOf () {
100151    Map <String , Object > input  = Map .ofEntries (
@@ -121,6 +172,48 @@ void testOneOf() {
121172    );
122173  }
123174
175+   @ Test 
176+   void  testToLegacyPassThroughLocations () {
177+     Map <String , Object > input  = Map .of ("name" , LABEL , "placeIds" , LIST_IDS_INPUT );
178+     var  result  = TripViaLocationMapper .toLegacyPassThroughLocations (List .of (input ));
179+     var  via  = result .getFirst ();
180+ 
181+     assertEquals (LABEL , via .label ());
182+     assertEquals (EXPECTED_IDS_AS_STRING , via .stopLocationIds ().toString ());
183+     assertTrue (via .isPassThroughLocation ());
184+     assertEquals (
185+       "PassThroughViaLocation{label: TestLabel, stopLocationIds: [F:ID1, F:ID2]}" ,
186+       via .toString ()
187+     );
188+   }
189+ 
190+   @ Test 
191+   void  testToLegacyPassThroughLocationsWithBareMinimum () {
192+     Map <String , Object > input  = mapOf ("placeIds" , LIST_IDS_INPUT );
193+     var  result  = TripViaLocationMapper .toLegacyPassThroughLocations (List .of (input ));
194+     var  via  = result .getFirst ();
195+ 
196+     assertNull (via .label ());
197+     assertEquals (EXPECTED_IDS_AS_STRING , via .stopLocationIds ().toString ());
198+     assertTrue (via .isPassThroughLocation ());
199+     assertEquals ("PassThroughViaLocation{stopLocationIds: [F:ID1, F:ID2]}" , via .toString ());
200+   }
201+ 
202+   @ Test 
203+   void  testToLegacyPassThroughLocationsWithoutIds () {
204+     var  result  = TripViaLocationMapper .toLegacyPassThroughLocations (
205+       List .of (mapOf ("placeIds" , null ))
206+     );
207+     assertTrue (result .isEmpty (), REASON_EMPTY_IDS_ALLOWED_PASS_THROUGH );
208+   }
209+ 
210+   @ Test 
211+   void  testToLegacyPassThroughLocationsWithEmptyList () {
212+     Map <String , Object > input  = Map .ofEntries (entry ("name" , LABEL ), entry ("placeIds" , List .of ()));
213+     var  result  = TripViaLocationMapper .toLegacyPassThroughLocations (List .of (input ));
214+     assertTrue (result .isEmpty (), REASON_EMPTY_IDS_ALLOWED_PASS_THROUGH );
215+   }
216+ 
124217  private  Map <String , Object > visitInput (String  label , Duration  minWaitTime , List <String > ids ) {
125218    var  map  = new  HashMap <String , Object >();
126219    if  (label  != null ) {
@@ -138,4 +231,14 @@ private Map<String, Object> visitInput(String label, Duration minWaitTime, List<
138231  private  Map <String , Object > passThroughInput (String  label , List <String > ids ) {
139232    return  visitInput (label , null , ids );
140233  }
234+ 
235+   /** 
236+    * Create a new HashMap with the {@code key} and {@code value}, the value may be {@code null}. 
237+    * The {@link Map#of(Object, Object)} does not support {@code null} values. 
238+    */ 
239+   private  static  Map <String , Object > mapOf (String  key , Object  value ) {
240+     var  map  = new  HashMap <String , Object >();
241+     map .put (key , value );
242+     return  map ;
243+   }
141244}
0 commit comments