谁能告诉我如何使用 assertThrows 有几个例外?
例如,这是一个类:
protected void checkViolation(Set<ConstraintViolation<EcritureComptable>> vViolations) throws FunctionalException {
if (!vViolations.isEmpty()) {
throw new FunctionalException("L'écriture comptable ne respecte pas les règles de gestion.",
new ConstraintViolationException(
"L'écriture comptable ne respecte pas les contraintes de validation",
vViolations));
}
}
和我的测试方法:
@Test
void checkViolation(){
comptabiliteManager = spy(ComptabiliteManagerImpl.class);
when(vViolations.isEmpty()).thenReturn(false);
assertThrows( ConstraintViolationException.class, () ->comptabiliteManager.checkViolation(vViolations), "a string should be provided!");
}
我想匹配该方法并完全抛出ConstraintViolationException和FunctionalException
任何想法?
谢谢