【发布时间】:2017-12-03 18:34:15
【问题描述】:
我有一个包含以下代码的 repo 类
@Repository
public interface ShopComponentsFramesRepository extends JpaRepository<ShopComponentFrame, Long> {
public List<ShopComponentFrame> findByComponentIdInAndShopId(Collection<Long> componentIdList,
Collection<Long> shopIdList);
public ShopComponentFrame findByComponentIdInAndShopId(Long componentId, Long shopId);
}
我有一个带有以下代码的 mockito junit 测试类,但编译器抱怨 - “方法 findByComponentIdInAndShopId(Collection, Collection) 对于 ShopComponentsFramesRepository 类型不明确"
@Test
public void testRequestReceivingDropdownElements() {
ReceivingDropdownsView sampleDropdownsView = getReceivingDropdownsSample();
when(authorityManager.retrieveAuthorities(USER_NAME)).thenReturn(getSampleAuthoritiesView());
when(shopComponentFrameConverter.convertToView(anyObject())).thenReturn(getComponentFrame());
when(shopComponentsFramesRepository.findByComponentIdInAndShopId(anyObject(), anyObject()))
.thenReturn(getShopComponentFrameList());
when(shopComponentsFramesRepository.findByComponentIdInAndShopId(anyLong(), anyLong()))
.thenReturn(getShopComponentFrame());
知道我做错了什么吗?
【问题讨论】:
-
不确定,但请尝试将第二个重载方法中的 Long 替换为 long。 Long 仍然是一个类似于 Collection 的对象,可能会导致歧义。不过只是猜测。
标签: java spring-boot junit mockito spring-data-jpa