@@ -200,4 +200,195 @@ public void testMapToString() {
200200 String emptyResult = VeniceProperties .mapToString (emptyMap );
201201 assertEquals (emptyResult , "" );
202202 }
203+
204+ @ Test
205+ public void testGetLongWithEmptyString () {
206+ // Test getLong with default value when property is empty string
207+ Properties properties = new Properties ();
208+ properties .put ("empty.long" , "" );
209+ properties .put ("whitespace.long" , " " );
210+ properties .put ("valid.long" , "12345" );
211+ VeniceProperties veniceProperties = new VeniceProperties (properties );
212+
213+ // Empty string should return default value
214+ assertEquals (veniceProperties .getLong ("empty.long" , 999L ), 999L );
215+
216+ // Whitespace-only string should return default value
217+ assertEquals (veniceProperties .getLong ("whitespace.long" , 888L ), 888L );
218+
219+ // Valid value should be parsed
220+ assertEquals (veniceProperties .getLong ("valid.long" , 999L ), 12345L );
221+
222+ // Missing property should return default value
223+ assertEquals (veniceProperties .getLong ("missing.long" , 777L ), 777L );
224+ }
225+
226+ @ Test
227+ public void testGetLongWithoutDefaultThrowsOnEmptyString () {
228+ // Test getLong without default value when property is empty string
229+ Properties properties = new Properties ();
230+ properties .put ("empty.long" , "" );
231+ properties .put ("whitespace.long" , " " );
232+ VeniceProperties veniceProperties = new VeniceProperties (properties );
233+
234+ // Empty string should throw VeniceException
235+ VeniceException ex1 = expectThrows (VeniceException .class , () -> veniceProperties .getLong ("empty.long" ));
236+ Assert .assertTrue (ex1 .getMessage ().contains ("empty value" ));
237+
238+ // Whitespace-only string should throw VeniceException
239+ VeniceException ex2 = expectThrows (VeniceException .class , () -> veniceProperties .getLong ("whitespace.long" ));
240+ Assert .assertTrue (ex2 .getMessage ().contains ("empty value" ));
241+
242+ // Missing property should throw UndefinedPropertyException
243+ expectThrows (UndefinedPropertyException .class , () -> veniceProperties .getLong ("missing.long" ));
244+ }
245+
246+ @ Test
247+ public void testGetIntWithEmptyString () {
248+ // Test getInt with default value when property is empty string
249+ Properties properties = new Properties ();
250+ properties .put ("empty.int" , "" );
251+ properties .put ("whitespace.int" , " " );
252+ properties .put ("valid.int" , "42" );
253+ VeniceProperties veniceProperties = new VeniceProperties (properties );
254+
255+ // Empty string should return default value
256+ assertEquals (veniceProperties .getInt ("empty.int" , 100 ), 100 );
257+
258+ // Whitespace-only string should return default value
259+ assertEquals (veniceProperties .getInt ("whitespace.int" , 200 ), 200 );
260+
261+ // Valid value should be parsed
262+ assertEquals (veniceProperties .getInt ("valid.int" , 100 ), 42 );
263+
264+ // Missing property should return default value
265+ assertEquals (veniceProperties .getInt ("missing.int" , 300 ), 300 );
266+ }
267+
268+ @ Test
269+ public void testGetIntWithoutDefaultThrowsOnEmptyString () {
270+ // Test getInt without default value when property is empty string
271+ Properties properties = new Properties ();
272+ properties .put ("empty.int" , "" );
273+ properties .put ("whitespace.int" , " " );
274+ VeniceProperties veniceProperties = new VeniceProperties (properties );
275+
276+ // Empty string should throw VeniceException
277+ VeniceException ex1 = expectThrows (VeniceException .class , () -> veniceProperties .getInt ("empty.int" ));
278+ Assert .assertTrue (ex1 .getMessage ().contains ("empty value" ));
279+
280+ // Whitespace-only string should throw VeniceException
281+ VeniceException ex2 = expectThrows (VeniceException .class , () -> veniceProperties .getInt ("whitespace.int" ));
282+ Assert .assertTrue (ex2 .getMessage ().contains ("empty value" ));
283+
284+ // Missing property should throw UndefinedPropertyException
285+ expectThrows (UndefinedPropertyException .class , () -> veniceProperties .getInt ("missing.int" ));
286+ }
287+
288+ @ Test
289+ public void testGetOptionalIntWithEmptyString () {
290+ // Test getOptionalInt when property is empty string
291+ Properties properties = new Properties ();
292+ properties .put ("empty.int" , "" );
293+ properties .put ("whitespace.int" , " " );
294+ properties .put ("valid.int" , "123" );
295+ VeniceProperties veniceProperties = new VeniceProperties (properties );
296+
297+ // Empty string should return Optional.empty()
298+ Assert .assertFalse (veniceProperties .getOptionalInt ("empty.int" ).isPresent ());
299+
300+ // Whitespace-only string should return Optional.empty()
301+ Assert .assertFalse (veniceProperties .getOptionalInt ("whitespace.int" ).isPresent ());
302+
303+ // Valid value should be present
304+ Assert .assertTrue (veniceProperties .getOptionalInt ("valid.int" ).isPresent ());
305+ assertEquals (veniceProperties .getOptionalInt ("valid.int" ).get (), Integer .valueOf (123 ));
306+
307+ // Missing property should return Optional.empty()
308+ Assert .assertFalse (veniceProperties .getOptionalInt ("missing.int" ).isPresent ());
309+ }
310+
311+ @ Test
312+ public void testGetDoubleWithEmptyString () {
313+ // Test getDouble with default value when property is empty string
314+ Properties properties = new Properties ();
315+ properties .put ("empty.double" , "" );
316+ properties .put ("whitespace.double" , " " );
317+ properties .put ("valid.double" , "3.14" );
318+ VeniceProperties veniceProperties = new VeniceProperties (properties );
319+
320+ // Empty string should return default value
321+ assertEquals (veniceProperties .getDouble ("empty.double" , 1.5 ), 1.5 );
322+
323+ // Whitespace-only string should return default value
324+ assertEquals (veniceProperties .getDouble ("whitespace.double" , 2.5 ), 2.5 );
325+
326+ // Valid value should be parsed
327+ assertEquals (veniceProperties .getDouble ("valid.double" , 1.5 ), 3.14 );
328+
329+ // Missing property should return default value
330+ assertEquals (veniceProperties .getDouble ("missing.double" , 4.5 ), 4.5 );
331+ }
332+
333+ @ Test
334+ public void testGetDoubleWithoutDefaultThrowsOnEmptyString () {
335+ // Test getDouble without default value when property is empty string
336+ Properties properties = new Properties ();
337+ properties .put ("empty.double" , "" );
338+ properties .put ("whitespace.double" , " " );
339+ VeniceProperties veniceProperties = new VeniceProperties (properties );
340+
341+ // Empty string should throw VeniceException
342+ VeniceException ex1 = expectThrows (VeniceException .class , () -> veniceProperties .getDouble ("empty.double" ));
343+ Assert .assertTrue (ex1 .getMessage ().contains ("empty value" ));
344+
345+ // Whitespace-only string should throw VeniceException
346+ VeniceException ex2 = expectThrows (VeniceException .class , () -> veniceProperties .getDouble ("whitespace.double" ));
347+ Assert .assertTrue (ex2 .getMessage ().contains ("empty value" ));
348+
349+ // Missing property should throw UndefinedPropertyException
350+ expectThrows (UndefinedPropertyException .class , () -> veniceProperties .getDouble ("missing.double" ));
351+ }
352+
353+ @ Test
354+ public void testGetSizeInBytesWithEmptyString () {
355+ // Test getSizeInBytes with default value when property is empty string
356+ Properties properties = new Properties ();
357+ properties .put ("empty.size" , "" );
358+ properties .put ("whitespace.size" , " " );
359+ properties .put ("valid.size" , "10MB" );
360+ VeniceProperties veniceProperties = new VeniceProperties (properties );
361+
362+ // Empty string should return default value
363+ assertEquals (veniceProperties .getSizeInBytes ("empty.size" , 1024L ), 1024L );
364+
365+ // Whitespace-only string should return default value
366+ assertEquals (veniceProperties .getSizeInBytes ("whitespace.size" , 2048L ), 2048L );
367+
368+ // Valid value should be parsed
369+ assertEquals (veniceProperties .getSizeInBytes ("valid.size" , 1024L ), 10 * 1024 * 1024L );
370+
371+ // Missing property should return default value
372+ assertEquals (veniceProperties .getSizeInBytes ("missing.size" , 4096L ), 4096L );
373+ }
374+
375+ @ Test
376+ public void testGetSizeInBytesWithoutDefaultThrowsOnEmptyString () {
377+ // Test getSizeInBytes without default value when property is empty string
378+ Properties properties = new Properties ();
379+ properties .put ("empty.size" , "" );
380+ properties .put ("whitespace.size" , " " );
381+ VeniceProperties veniceProperties = new VeniceProperties (properties );
382+
383+ // Empty string should throw VeniceException
384+ VeniceException ex1 = expectThrows (VeniceException .class , () -> veniceProperties .getSizeInBytes ("empty.size" ));
385+ Assert .assertTrue (ex1 .getMessage ().contains ("empty value" ));
386+
387+ // Whitespace-only string should throw VeniceException
388+ VeniceException ex2 = expectThrows (VeniceException .class , () -> veniceProperties .getSizeInBytes ("whitespace.size" ));
389+ Assert .assertTrue (ex2 .getMessage ().contains ("empty value" ));
390+
391+ // Missing property should throw UndefinedPropertyException
392+ expectThrows (UndefinedPropertyException .class , () -> veniceProperties .getSizeInBytes ("missing.size" ));
393+ }
203394}
0 commit comments