Background: I am doing the unit testing in Eclipse 2021-06 (4.20.0) on method viewResult() in HallSystem class. In testHallSystem(), when I try to run the viewResult() before processing the application. Steps to Reproduce: 1. Run the package with testHall_Admission 2. Run the method “void testViewResult” in testViewResult class Actual result: After the run the above steps, the system returns the error message “Cannot invoke "HallAdmissionSystem.ProcessApplication.getFinalResult()" because "this.processApplication" is null”. Expected result: I expect the system will show “Waiting for processing to finish” if I view the result before the processing is done.
The system should show “waiting for processing to finish” or “need to run process function”, instead of error of null. I will pass it to the developer to solve this error.
As the set of process objects have not been created, so the system cannot output any result. But as the code is to run “Display.runDisplay("All Result", content, false);” and will not check if the process function has been run successfully. Therefore the ArrayList is null. To solve the showing empty ArrayList problem, a check if the sets of process objects are created needed to be implemented. Solution: =============== public void viewResult() { if(processApplication != null){ String content = processApplication.getFinalResult(); Display.runDisplay("All Result", content, false); } else { String content = "Waiting for processing to finish."; Display.runDisplay("All Result",content , false); } }