Skip to content
Snippets Groups Projects
Commit 2fb1424c authored by Ester Vilímková's avatar Ester Vilímková
Browse files

Changing ResourceNotFoundException to ResponseStatusException

parent c549fe4f
No related branches found
No related tags found
2 merge requests!31M2,!24M2 certificate response entity
Pipeline #
......@@ -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)
......
......@@ -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()));
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment