Код: Выделить всё
@Override
public Page getWalletListByWalletTypes(List walletTypesIds, Pageable pageable) throws NotFoundException {
if(walletTypesIds == null) {
Page walletsDTOList = this.walletRepository.findAll(pageable);
return walletsDTOList.map(m -> conversionService.convert(m, WalletDTO.class));
}
List walletsTypesEntity = new ArrayList();
for(String wt : walletTypesIds){
//WalletType wtEntity = this.walletTypeRepository.findByName(wt);
WalletType wtEntity = this.walletTypeRepository.findById(Integer.parseInt(wt)).get();
if(wtEntity == null) throw new NotFoundException("WalletType not found: " + wt);
walletsTypesEntity.add(wtEntity);
}
Page walletsDTOList = this.walletRepository.findByWalletTypeIn(walletsTypesEntity,pageable);
return walletsDTOList.map(m -> conversionService.convert(m, WalletDTO.class));
}
Затем Я создал метод тестирования JUnit следующим образом:
Код: Выделить всё
@Test
@Order(2)
public void getWalletListByWalletTypesTest() throws NotFoundException {
List singleItemList = Arrays.asList("1");
List multiItemsList = Arrays.asList("1", "2", "3");
Page walletsType1DTOList = this.walletService.getWalletListByWalletTypes(singleItemList, null);
Page walletsAlltypesDTOList = this.walletService.getWalletListByWalletTypes(multiItemsList, null);
assertTrue(walletsType1DTOList.getNumberOfElements() > 0, "Exist at least one wallet");
assertTrue(walletsAlltypesDTOList.getNumberOfElements() > 0, "Exist at least one wallet");
assertTrue(walletsAlltypesDTOList.getNumberOfElements() < walletsType1DTOList.getNumberOfElements(),
"The wallets belonging to all the wallets types are > then the wallet belonging to a single wallet type");
}
Код: Выделить всё
Page walletsDTOList = this.walletRepository.findByWalletTypeIn(walletsTypesEntity,pageable);
Что такое как правильно протестировать такой метод?
Подробнее здесь: https://stackoverflow.com/questions/711 ... d-that-nee