假设我有以下代码:
protected int returnFourtyTwo() {
evilMethod(new Object, "");
return 42;
}
protected static void evilMethod(Object obj, String string) {
throw new RuntimeException("This is me being evil.");
}
我想要做的是运行我的 returnFourtyTwo() 方法而不在我的单元测试中抛出运行时异常。之前我已经能够使用 suppress() 方法绕过类构造函数,但这是我第一次不得不绕过非静态类中的静态方法(具有多个参数)。不幸的是,有关该主题的资源有点稀缺。