Multiple choice technology testing

How to test the methods, which contain System.exit() statement?

  1. a.) There is no option to test it in Junit

  2. b.) Modifying the testcase to run with SecurityManager that prevents calling System.exit, then catch the SecurityException.

  3. c.) Remove the System.Exit() line then continue the testing with that methods.

  4. d.) Test it everything as-is.

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

To test methods containing System.exit(), you can configure a custom SecurityManager that throws a SecurityException when checkExit is called. The test case can then catch this exception to verify that the exit was triggered without terminating the JVM.