Xbr*_*izh 6 java exception mockito juniper
谁能告诉我如何使用断言抛出几个异常?
\n\n例如,这是一个类:
\n\n protected void checkViolation(Set<ConstraintViolation<EcritureComptable>> vViolations) throws FunctionalException {\n    if (!vViolations.isEmpty()) {\n        throw new FunctionalException("L\'\xc3\xa9criture comptable ne respecte pas les r\xc3\xa8gles de gestion.",\n                                      new ConstraintViolationException(\n                                          "L\'\xc3\xa9criture comptable ne respecte pas les contraintes de validation",\n                                          vViolations));\n    }\n}\n和我的测试方法:
\n\n @Test\nvoid checkViolation(){\n    comptabiliteManager = spy(ComptabiliteManagerImpl.class);\n    when(vViolations.isEmpty()).thenReturn(false);\n\n    assertThrows(  ConstraintViolationException.class, () ->comptabiliteManager.checkViolation(vViolations), "a string should be provided!");\n}\n我想匹配该方法并完全抛出ConstraintViolationException和FunctionException
\n\n任何想法?
\n\n谢谢
\n抛出一个异常,其类型为FunctionalException。这是cause一个.FunctionalExceptionConstraintViolationException
假设assertThrows是JUnit 5 方法,它返回抛出的异常。因此,您可以简单地了解其原因并对此原因添加额外的检查。
| 归档时间: | 
 | 
| 查看次数: | 6696 次 | 
| 最近记录: |