Background: I am doing the unit testing in eclipse 2021-06 (4.20.0) on method convertScore() in Area_Eca class. Steps to Reproduce: 1. Run the package with testHall_Admission 2. Run the method “void testConvertScore” in testArea_eca class 3. Run @ParameterizedTest with “/testResource/testCreateArea_eca.csv” 4. Input the test case "Other String,true,,Test invalid input and then throw exception" Actual result: After the run the above steps, the system return “java.lang.NumberFormatException: For input string:Other String” in the console. Expected result: I expect the system to indicate the value is wrong if the input was wrong. I think the system should throw an exception and return nothing.
For now, the system only accepts the number string and special strings like float number and DSE characters. Therefore when having other strings like "Other String", the system will throw a Java Exception directly as Java predefine error. Adding a function to allow validate input and telling users the input have an error. I will pass it to the developer to design a new function to do validation.
I just added a class for validation of the input. The class is named Validation. To validate the score, use the following method. I also added validation for other input. Now the bug is solved. Solution: =============== public static boolean validationScore(String input, String academicType) { Double temp = 0.0; if(input==null||academicType==null) return false; if(academicType.equals("DSE")) { if(input.equals("5**")||input.equals("5*")||input.equals("5")||input.equals("4")||input.equals("3")||input.equals("2")||input.equals("1")||input.equals("U")) return true; }else { if(!checkDouble(input)) return false; temp = Double.parseDouble(input); if(temp<=4.3 && temp>=0) return true; } return false; }