diff --git a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateService.java b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateService.java index 133fa1b9e472ab973e80f1aded54b1624717630d..245c88c35ea55f4d59d0d01ed2b15290fddc42ed 100644 --- a/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateService.java +++ b/application/module-certificate/src/main/java/org/fuseri/modulecertificate/service/CertificateService.java @@ -4,8 +4,10 @@ import org.fuseri.modulecertificate.Certificate; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; +import org.springframework.http.HttpStatus; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.server.ResponseStatusException; import java.util.List; @@ -22,7 +24,7 @@ public class CertificateService { @Transactional(readOnly = true) public Certificate findById(Long id) { return certificateRepository.findById(id) - .orElseThrow(() -> new ResourceNotFoundException("Certificate with id: " + id + " was not found.")); + .orElseThrow(() -> new ResponseStatusException(HttpStatus.NOT_FOUND, "Certificate with id: " + id + " was not found.")); } @Transactional(readOnly = true) diff --git a/application/module-certificate/src/test/java/org/fuseri/modulecertificate/CertificateServiceTests.java b/application/module-certificate/src/test/java/org/fuseri/modulecertificate/CertificateServiceTests.java index a60759ff82403b93a1cb5263fa6e3e55ced14dad..372e649060e89bd3c164f64d1c4b3039656598ff 100644 --- a/application/module-certificate/src/test/java/org/fuseri/modulecertificate/CertificateServiceTests.java +++ b/application/module-certificate/src/test/java/org/fuseri/modulecertificate/CertificateServiceTests.java @@ -7,10 +7,8 @@ import org.fuseri.model.dto.user.AddressDto; import org.fuseri.model.dto.user.UserDto; import org.fuseri.modulecertificate.service.CertificateRepository; import org.fuseri.modulecertificate.service.CertificateService; -import org.fuseri.modulecertificate.service.ResourceNotFoundException; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; -import org.mockito.stubbing.OngoingStubbing; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.boot.test.mock.mockito.MockBean; @@ -18,6 +16,7 @@ import org.springframework.data.domain.Page; import org.springframework.data.domain.PageImpl; import org.springframework.data.domain.PageRequest; import org.springframework.data.domain.Pageable; +import org.springframework.web.server.ResponseStatusException; import java.time.Instant; import java.util.Collections; @@ -57,7 +56,7 @@ final class CertificateServiceTests { void notFoundById() { when(certificateRepository.findById(certificate.getId())).thenReturn(Optional.empty()); - Assertions.assertThrows(ResourceNotFoundException.class, () -> certificateService.findById(certificate.getId())); + Assertions.assertThrows(ResponseStatusException.class, () -> certificateService.findById(certificate.getId())); }