public static void checkException(ExceptionGenerator exceptionGenerator, Class expectedException) {
        try {
            exceptionGenerator.generateException();
            //no exception was caught
            System.out.println("no exception; expected " + expectedException.getSimpleName());
        } catch (Exception ex) {
            if (expectedException.isInstance(ex)) { //expected exception is caught
                System.out.println("caught expected " + expectedException.getSimpleName());
            } else { //some exception is caught, but not the expected one
                System.out.println("caught " + ex.getClass().getSimpleName() +
                        "; expected: " + expectedException.getSimpleName());
            }
        }
    }