Testing if a java program calls System.exist - without exiting Junit

Roy Shtoyerman :

I am trying to test a file processing program with Junit. In some cases, the program should print an error and finish its run. However, using "System.exit(-1)" causes the program to exit the entire Junit tests. Is there some way of avoiding it?

I can instead print the error and then return null, however I find it quite inelegant.

    private List<String> parseData(String[] args){
        if (args.length != 2){
            System.err.println(ERROR + INPUT_ERROR + "\n");
            System.exit(EXIT_CODE);

Is there a way to check if the program called "System.exit" without closing it? Thank you.

AdrianM :

I think it's more inelegant to use System.exit to validate input parameters. Why not just throw an exception and let the caller of this method handle it ?

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related