Background: I am doing the unit test in ECLIPSE 2021-06 (4.20.0) on method viewApplication() in HallSystem class. When I am doing testViewApplication2() in testHallSystem class, I am trying to test finding an std2’s application but there is no std2’ application. Steps to Reproduce: Run the package with testHall_Admission Run the method “void testViewApplication2” in testHallSystem class Actual result: The system output the error message of “java.lang.NullPointerException: Cannot invoke “HallAdmissionSystem.Application.toString()” because the return value of “HallAdmissionSystem.HallSystem.findApplication(HallAdmissionSystem.Student)” is null” in the console after the test run. Expected result: I expected the system to output “null” or message of “No such student”.
I just tried this test case, there is a null problem. I suspect the code forgot to take account of the null situation. The system shout just outputs empty if there is a null value. I will pass it to the developer to solve this error.
Currently, the system did not check if there is a null value, it run “Display.runDisplay("View Application", findApplication(std).toString(), false);” directly. Therefore, such errors appear when passing the null to the display object. To solve the null error, the null value will be converted into an empty string. Solution: =============== public void viewApplication(Student std) { Application application = findApplication(std); if(application != null) { Display.runDisplay("View Application", findApplication(std).toString(), false); } else { System.out.println(""); } }