【发布时间】:2020-04-01 17:29:16
【问题描述】:
我有一个方法调用内部称为“burn”的方法,该方法引发数据异常,如果是这样,则将其捕获在 try/catch 块中并记录到记录器。然而,该类使用注解 @Slf4j 和 lombok.extern.slf4j:
@Slf4j
public class MyClass {
private void myMethod(Type parameter) throws Exception {
try {
dataGateway.burn(id);
}
catch {
log.error("Failed to burn({})",id);
}
}
我已经模拟了数据网关并让它在调用burn时抛出异常,我知道异常被捕获但是我如何使用验证来断言记录器是用.error调用的? DateGateway dBMock = mock(DateGateway.class);
when(dBMock.burn(anyString())).thenReturn(new DataException("exception"));
【问题讨论】:
标签: unit-testing annotations mockito slf4j lombok