mardi 30 juin 2020

Test JPA repository for void functions and updates and deletes

I working on writing tests for a crud application. I need to test the service and repository for Delete and Update statements. How would I go about mocking the repository for delete and update since they won't be returning data?

For example:

@Override
public void makeUserActive(long userId) {
   try {
       Optional<UserEntity> userEntityList = usersJpaRepository.findById(userId);
       UserEntity userEntity = userEntityList.get();
       userEntity.setIsActive(1);
       usersJpaRepository.save(userEntity);
   } catch (Exception e) {
       logger.error("Cant make active user", e);
   }
 }

How do i test the service that mocks this repository and also the repository itself since it wont be returning a value

Aucun commentaire:

Enregistrer un commentaire