@@ -496,4 +496,38 @@ public void substringBefore() throws Exception {
496496 assertEquals ("x" , StringUtils .substringBefore ("xaba" , "a" ));
497497 assertEquals (" " , StringUtils .substringBefore (" a" , "a" ));
498498 }
499+
500+ /**
501+ * @throws Exception if the test fails
502+ */
503+ @ Test
504+ public void toInt () throws Exception {
505+ assertEquals (17 , StringUtils .toInt (null , 17 ));
506+ assertEquals (17 , StringUtils .toInt ("" , 17 ));
507+ assertEquals (17 , StringUtils .toInt (" " , 17 ));
508+ assertEquals (4 , StringUtils .toInt ("\t " , 4 ));
509+ assertEquals (4 , StringUtils .toInt ("two" , 4 ));
510+
511+ assertEquals (21 , StringUtils .toInt ("21" , 4 ));
512+ assertEquals (-21 , StringUtils .toInt ("-21" , 4 ));
513+ assertEquals (0 , StringUtils .toInt (" 21 " , 0 ));
514+ assertEquals (0 , StringUtils .toInt (" - 21 \t " , 0 ));
515+ }
516+
517+ /**
518+ * @throws Exception if the test fails
519+ */
520+ @ Test
521+ public void toFloat () throws Exception {
522+ assertEquals (17.2f , StringUtils .toFloat (null , 17.2f ));
523+ assertEquals (17.2f , StringUtils .toFloat ("" , 17.2f ));
524+ assertEquals (17.2f , StringUtils .toFloat (" " , 17.2f ));
525+ assertEquals (4f , StringUtils .toFloat ("\t " , 4f ));
526+ assertEquals (4f , StringUtils .toFloat ("two" , 4 ));
527+
528+ assertEquals (21f , StringUtils .toFloat ("21" , 4.1f ));
529+ assertEquals (-21f , StringUtils .toFloat ("-21" , 4.1f ));
530+ assertEquals (21f , StringUtils .toFloat (" 21 " , 0 ));
531+ assertEquals (0 , StringUtils .toFloat (" - 21 \t " , 0f ));
532+ }
499533}
0 commit comments