【发布时间】:2018-11-24 12:32:20
【问题描述】:
我搜索了所有我能想到的解决方案,但措辞很困难。
我有一个在 Spring Repository 上调用 delete 的单元测试。回购定义为:
public interface FileConfigurationRepository extends CasenetRepository<FileConfiguration, String> {}
我正在测试的方法有以下调用:
fileConfigurationRepository.delete(GlobalConfiguration.CUSTOM_LOGO_ID);
其中 GlobalConfiguration.CUSTOM_LOGO_ID 定义为:
public static final String CUSTOM_LOGO_ID = "customLogoId";
所以我写了我的模拟如下:
Mockito.when(fileConfigurationRepository.delete(GlobalConfiguration.CUSTOM_LOGO_ID)).thenThrow(new Exception());
然后我收到以下错误:
错误文本:
No instance(s) of type variable(s) T exist so that void conforms to T
不确定如何继续。
【问题讨论】:
-
请粘贴错误文本,图片在防火墙后不可见。
-
Exception是一个检查异常。除非你的delete()方法声明了throws Exception,否则你不能从那里扔掉它。使用RuntimeException -
@Arkadiy 切换到 RuntimeException。没有变化。
-
好的,那么我需要查看错误的文本。图片被过滤掉了:(
-
@Arkadiy 添加。感谢您的关注。
标签: java unit-testing mockito