bonne utilisation de nom de variable en anglais pour rester cohérent pour avis via la commande

"find src/test/java/fr/iut_fbleau/but3/dev62/mylibrary/review -name "*.java" -exec sed -i 's/AVIS/REVIEW/g; s/Avis/Review/g; s/avis/review/g' {} +" pour les fichier test et remplacer le chemin pour les fichier main
This commit was merged in pull request #2.
This commit is contained in:
2026-06-12 01:25:15 +02:00
parent 1d8b4c0ac9
commit 13f8cab3ed
11 changed files with 107 additions and 106 deletions
@@ -10,7 +10,7 @@ import java.util.UUID;
@Builder @Builder
public class ReviewDTO { public class ReviewDTO {
private UUID avisId; private UUID reviewId;
private UUID customerId; private UUID customerId;
private UUID bookId; private UUID bookId;
private Integer note; private Integer note;
@@ -19,6 +19,7 @@ public class ReviewConverter {
public static ReviewDTO toDTO(Review review) { public static ReviewDTO toDTO(Review review) {
return ReviewDTO.builder() return ReviewDTO.builder()
.reviewId(review.getReviewId())
.customerId(review.getCustomerId()) .customerId(review.getCustomerId())
.bookId(review.getBookId()) .bookId(review.getBookId())
.note(review.getNote()) .note(review.getNote())
@@ -10,7 +10,7 @@ import java.util.UUID;
@Builder @Builder
public class Review { public class Review {
private UUID avisId; private UUID reviewId;
private UUID customerId; private UUID customerId;
private UUID bookId; private UUID bookId;
private Integer note; private Integer note;
@@ -18,7 +18,7 @@ public class Review {
private LocalDate purchaseDate; private LocalDate purchaseDate;
public void setRandomUUID() { public void setRandomUUID() {
this.avisId = UUID.randomUUID(); this.reviewId = UUID.randomUUID();
} }
public void setRandomUUIDCustomerAndBook() { public void setRandomUUIDCustomerAndBook() {
@@ -8,18 +8,18 @@ public class ReviewNotFoundException extends RuntimeException {
public static final String THE_REVIEWS_WITH_CUSTOMER_ID_DOES_NOT_EXIST_MESSAGE = "The reviews with the customer id {0} does not exists"; public static final String THE_REVIEWS_WITH_CUSTOMER_ID_DOES_NOT_EXIST_MESSAGE = "The reviews with the customer id {0} does not exists";
public static final String THE_REVIEWS_WITH_BOOK_ID_DOES_NOT_EXIST_MESSAGE = "The reviews with the book id {0} does not exists"; public static final String THE_REVIEWS_WITH_BOOK_ID_DOES_NOT_EXIST_MESSAGE = "The reviews with the book id {0} does not exists";
public static final String THE_REVIEWS_WITH_AVIS_ID_DOES_NOT_EXIST_MESSAGE = "The review with avis id {0} does not exists"; public static final String THE_REVIEWS_WITH_REVIEW_ID_DOES_NOT_EXIST_MESSAGE = "The review with review id {0} does not exists";
public ReviewNotFoundException(Optional<UUID> customerUUID, Optional<UUID> bookUUID, Optional<UUID> avisUUID) { public ReviewNotFoundException(Optional<UUID> customerUUID, Optional<UUID> bookUUID, Optional<UUID> reviewUUID) {
super(buildMessage(customerUUID, bookUUID, avisUUID)); super(buildMessage(customerUUID, bookUUID, reviewUUID));
} }
private static String buildMessage(Optional<UUID> customerUUID, Optional<UUID> bookUUID, Optional<UUID> avisUUID) { private static String buildMessage(Optional<UUID> customerUUID, Optional<UUID> bookUUID, Optional<UUID> reviewUUID) {
if (customerUUID.isPresent()) { if (customerUUID.isPresent()) {
return MessageFormat.format(THE_REVIEWS_WITH_CUSTOMER_ID_DOES_NOT_EXIST_MESSAGE, customerUUID.get()); return MessageFormat.format(THE_REVIEWS_WITH_CUSTOMER_ID_DOES_NOT_EXIST_MESSAGE, customerUUID.get());
}else if (bookUUID.isPresent()) { }else if (bookUUID.isPresent()) {
return MessageFormat.format(THE_REVIEWS_WITH_BOOK_ID_DOES_NOT_EXIST_MESSAGE, bookUUID.get()); return MessageFormat.format(THE_REVIEWS_WITH_BOOK_ID_DOES_NOT_EXIST_MESSAGE, bookUUID.get());
} }
return MessageFormat.format(THE_REVIEWS_WITH_AVIS_ID_DOES_NOT_EXIST_MESSAGE, avisUUID.get()); return MessageFormat.format(THE_REVIEWS_WITH_REVIEW_ID_DOES_NOT_EXIST_MESSAGE, reviewUUID.get());
} }
} }
@@ -23,8 +23,8 @@ public class ReviewRepository {
} }
public Review save(Review newReview) { public Review save(Review newReview) {
Optional<Review> optionalReviewWithSameAvisId = this.findByAvisId(newReview.getAvisId()); Optional<Review> optionalReviewWithSameReviewId = this.findByReviewId(newReview.getReviewId());
optionalReviewWithSameAvisId.ifPresent(reviews::remove); optionalReviewWithSameReviewId.ifPresent(reviews::remove);
this.reviews.add(newReview); this.reviews.add(newReview);
return newReview; return newReview;
} }
@@ -41,9 +41,9 @@ public class ReviewRepository {
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
} }
public Optional<Review> findByAvisId(UUID avisUUID) { public Optional<Review> findByReviewId(UUID reviewUUID) {
return this.reviews.stream() return this.reviews.stream()
.filter(review -> review.getAvisId().equals(avisUUID)) .filter(review -> review.getReviewId().equals(reviewUUID))
.findFirst(); .findFirst();
} }
@@ -57,9 +57,9 @@ public class ReviewRepository {
.anyMatch(review -> review.getBookId().equals(bookUUID)); .anyMatch(review -> review.getBookId().equals(bookUUID));
} }
public boolean existsByAvisId(UUID avisUUID) { public boolean existsByReviewId(UUID reviewUUID) {
return this.reviews.stream() return this.reviews.stream()
.anyMatch(review -> review.getAvisId().equals(avisUUID)); .anyMatch(review -> review.getReviewId().equals(reviewUUID));
} }
public void deleteCustomerReviews(UUID customerUUID) { public void deleteCustomerReviews(UUID customerUUID) {
@@ -26,7 +26,7 @@ public class ReviewUseCase {
ReviewValidator.validate(newReview); ReviewValidator.validate(newReview);
Review reviewToRegister = ReviewConverter.toDomain(newReview); Review reviewToRegister = ReviewConverter.toDomain(newReview);
Review reviewToRegistered = reviewRepository.save(reviewToRegister); Review reviewToRegistered = reviewRepository.save(reviewToRegister);
return reviewToRegistered.getAvisId(); return reviewToRegistered.getReviewId();
} }
public ArrayList<ReviewDTO> findReviewByCustomerId(UUID customerId) { public ArrayList<ReviewDTO> findReviewByCustomerId(UUID customerId) {
@@ -43,30 +43,30 @@ public class ReviewUseCase {
.collect(Collectors.toCollection(ArrayList::new)); .collect(Collectors.toCollection(ArrayList::new));
} }
public Optional<ReviewDTO> findReviewByAvisId(UUID avisId) { public Optional<ReviewDTO> findReviewByReviewId(UUID reviewId) {
Optional<Review> optionalReview = reviewRepository.findByAvisId(avisId); Optional<Review> optionalReview = reviewRepository.findByReviewId(reviewId);
return optionalReview.map(ReviewConverter::toDTO); return optionalReview.map(ReviewConverter::toDTO);
} }
public ReviewDTO updateReview(UUID avisUUID, ReviewInfo reviewInfo) public ReviewDTO updateReview(UUID reviewUUID, ReviewInfo reviewInfo)
throws ReviewNotFoundException, NotValidReviewException { throws ReviewNotFoundException, NotValidReviewException {
ReviewValidator.validate(reviewInfo); ReviewValidator.validate(reviewInfo);
Review reviewByAvisUUID = getReviewIfDoesNotExistThrowReviewNotFoundException( Review reviewByReviewUUID = getReviewIfDoesNotExistThrowReviewNotFoundException(
avisUUID); reviewUUID);
Review review = Review.builder() Review review = Review.builder()
.avisId(avisUUID) .reviewId(reviewUUID)
.customerId(reviewByAvisUUID.getCustomerId()) .customerId(reviewByReviewUUID.getCustomerId())
.bookId(reviewByAvisUUID.getBookId()) .bookId(reviewByReviewUUID.getBookId())
.note(reviewByAvisUUID.getNote()) .note(reviewByReviewUUID.getNote())
.comment(reviewByAvisUUID.getComment()) .comment(reviewByReviewUUID.getComment())
.purchaseDate(reviewByAvisUUID.getPurchaseDate()) .purchaseDate(reviewByReviewUUID.getPurchaseDate())
.build(); .build();
Review updatedReview = reviewRepository.save(review); Review updatedReview = reviewRepository.save(review);
return ReviewConverter.toDTO(updatedReview); return ReviewConverter.toDTO(updatedReview);
} }
public void deleteReview(UUID avisUUID) throws ReviewNotFoundException { public void deleteReview(UUID reviewUUID) throws ReviewNotFoundException {
Review reviewToDelete = getReviewIfDoesNotExistThrowReviewNotFoundException(avisUUID); Review reviewToDelete = getReviewIfDoesNotExistThrowReviewNotFoundException(reviewUUID);
this.reviewRepository.delete(reviewToDelete); this.reviewRepository.delete(reviewToDelete);
} }
@@ -84,30 +84,30 @@ public class ReviewUseCase {
} }
} }
private Review getReviewIfDoesNotExistThrowReviewNotFoundException(UUID avisUUID) private Review getReviewIfDoesNotExistThrowReviewNotFoundException(UUID reviewUUID)
throws ReviewNotFoundException { throws ReviewNotFoundException {
Optional<Review> optionalReviewByAvisId = reviewRepository.findByAvisId(avisUUID); Optional<Review> optionalReviewByReviewId = reviewRepository.findByReviewId(reviewUUID);
if (optionalReviewByAvisId.isEmpty()) { if (optionalReviewByReviewId.isEmpty()) {
throw new ReviewNotFoundException(Optional.empty(), Optional.empty(),Optional.of(avisUUID)); throw new ReviewNotFoundException(Optional.empty(), Optional.empty(),Optional.of(reviewUUID));
} }
return optionalReviewByAvisId.get(); return optionalReviewByReviewId.get();
} }
private ArrayList<Review> getReviewByCustomerIdIfDoesNotExistThrowReviewNotFoundException(UUID customerUUID) private ArrayList<Review> getReviewByCustomerIdIfDoesNotExistThrowReviewNotFoundException(UUID customerUUID)
throws ReviewNotFoundException { throws ReviewNotFoundException {
ArrayList<Review> optionalReviewByAvisId = reviewRepository.findByCustomerId(customerUUID); ArrayList<Review> optionalReviewByReviewId = reviewRepository.findByCustomerId(customerUUID);
if (optionalReviewByAvisId.isEmpty()) { if (optionalReviewByReviewId.isEmpty()) {
throw new ReviewNotFoundException(Optional.of(customerUUID), Optional.empty(),Optional.empty()); throw new ReviewNotFoundException(Optional.of(customerUUID), Optional.empty(),Optional.empty());
} }
return optionalReviewByAvisId; return optionalReviewByReviewId;
} }
private ArrayList<Review> getReviewByBookIfDoesNotExistThrowReviewNotFoundException(UUID bookUUID) private ArrayList<Review> getReviewByBookIfDoesNotExistThrowReviewNotFoundException(UUID bookUUID)
throws ReviewNotFoundException { throws ReviewNotFoundException {
ArrayList<Review> optionalReviewByAvisId = reviewRepository.findByBookId(bookUUID); ArrayList<Review> optionalReviewByReviewId = reviewRepository.findByBookId(bookUUID);
if (optionalReviewByAvisId.isEmpty()) { if (optionalReviewByReviewId.isEmpty()) {
throw new ReviewNotFoundException(Optional.empty(), Optional.empty(), Optional.of(bookUUID)); throw new ReviewNotFoundException(Optional.empty(), Optional.empty(), Optional.of(bookUUID));
} }
return optionalReviewByAvisId; return optionalReviewByReviewId;
} }
} }
@@ -47,7 +47,7 @@ public class ReviewConverterTest {
void shouldConvertReviewToDTO() { void shouldConvertReviewToDTO() {
LocalDate purchaseDate = LocalDate.of(2026, 3, 24); LocalDate purchaseDate = LocalDate.of(2026, 3, 24);
Review review = Review.builder() Review review = Review.builder()
.avisId(UUID.randomUUID()) .reviewId(UUID.randomUUID())
.customerId(UUID.randomUUID()) .customerId(UUID.randomUUID())
.bookId(UUID.randomUUID()) .bookId(UUID.randomUUID())
.note(5) .note(5)
@@ -38,17 +38,17 @@ public class ReviewTest {
@DisplayName("setRandomUUID should change the ID to a new random UUID") @DisplayName("setRandomUUID should change the ID to a new random UUID")
void testSetRandomUUID() { void testSetRandomUUID() {
Review review = Review.builder().build(); Review review = Review.builder().build();
UUID originalAvisId = review.getAvisId(); UUID originalReviewId = review.getReviewId();
UUID originalCustomerId = review.getCustomerId(); UUID originalCustomerId = review.getCustomerId();
UUID originalBookId = review.getCustomerId(); UUID originalBookId = review.getCustomerId();
review.setRandomUUID(); review.setRandomUUID();
review.setRandomUUIDCustomerAndBook(); review.setRandomUUIDCustomerAndBook();
assertNotNull(review.getAvisId()); assertNotNull(review.getReviewId());
assertNotNull(review.getCustomerId()); assertNotNull(review.getCustomerId());
assertNotNull(review.getBookId()); assertNotNull(review.getBookId());
assertNotEquals(originalAvisId, review.getAvisId()); assertNotEquals(originalReviewId, review.getReviewId());
assertNotEquals(originalCustomerId, review.getCustomerId()); assertNotEquals(originalCustomerId, review.getCustomerId());
assertNotEquals(originalBookId, review.getBookId()); assertNotEquals(originalBookId, review.getBookId());
} }
@@ -36,11 +36,11 @@ public class ReviewNotFoundExceptionTest {
@Test @Test
@DisplayName("Exception message should contain the UUID provided for customer and book") @DisplayName("Exception message should contain the UUID provided for customer and book")
void testExceptionMessageContainsUUIDForCustomerAndBook() { void testExceptionMessageContainsUUIDForCustomerAndBook() {
UUID avisUUID = UUID.randomUUID(); UUID reviewUUID = UUID.randomUUID();
ReviewNotFoundException exception = new ReviewNotFoundException(Optional.empty(), Optional.empty(), Optional.of(avisUUID)); ReviewNotFoundException exception = new ReviewNotFoundException(Optional.empty(), Optional.empty(), Optional.of(reviewUUID));
String expectedMessage = String.format("The review with avis id %s does not exists", avisUUID); String expectedMessage = String.format("The review with review id %s does not exists", reviewUUID);
assertEquals(expectedMessage, exception.getMessage()); assertEquals(expectedMessage, exception.getMessage());
} }
@@ -73,25 +73,25 @@ public class ReviewNotFoundExceptionTest {
@Test @Test
@DisplayName("Exception should use the correct constant message format for review") @DisplayName("Exception should use the correct constant message format for review")
void testExceptionUsesConstantMessageReviewFormat() { void testExceptionUsesConstantMessageReviewFormat() {
UUID avisUUID = UUID.randomUUID(); UUID reviewUUID = UUID.randomUUID();
ReviewNotFoundException exception = new ReviewNotFoundException(Optional.empty(), Optional.empty(), Optional.of(avisUUID)); ReviewNotFoundException exception = new ReviewNotFoundException(Optional.empty(), Optional.empty(), Optional.of(reviewUUID));
String expectedFormatWithPlaceholder = "The review with avis id {0} does not exists"; String expectedFormatWithPlaceholder = "The review with review id {0} does not exists";
assertEquals(ReviewNotFoundException.THE_REVIEWS_WITH_AVIS_ID_DOES_NOT_EXIST_MESSAGE, assertEquals(ReviewNotFoundException.THE_REVIEWS_WITH_REVIEW_ID_DOES_NOT_EXIST_MESSAGE,
expectedFormatWithPlaceholder); expectedFormatWithPlaceholder);
assertTrue(exception.getMessage().contains(avisUUID.toString())); assertTrue(exception.getMessage().contains(reviewUUID.toString()));
} }
@Test @Test
@DisplayName("Exception should be properly thrown and caught") @DisplayName("Exception should be properly thrown and caught")
void testExceptionCanBeThrownAndCaught() { void testExceptionCanBeThrownAndCaught() {
UUID avisUUID = UUID.randomUUID(); UUID reviewUUID = UUID.randomUUID();
try { try {
throw new ReviewNotFoundException(Optional.empty(),Optional.empty(), Optional.of(avisUUID)); throw new ReviewNotFoundException(Optional.empty(),Optional.empty(), Optional.of(reviewUUID));
} catch (ReviewNotFoundException e) { } catch (ReviewNotFoundException e) {
String expectedMessage = String.format("The review with avis id %s does not exists", avisUUID); String expectedMessage = String.format("The review with review id %s does not exists", reviewUUID);
assertEquals(expectedMessage, e.getMessage()); assertEquals(expectedMessage, e.getMessage());
} }
} }
@@ -99,11 +99,11 @@ public class ReviewRepositoryTest {
repository.save(review1); repository.save(review1);
LocalDate purchaseDate = LocalDate.of(2026, 5, 24); LocalDate purchaseDate = LocalDate.of(2026, 5, 24);
UUID avisId = review1.getAvisId(); UUID reviewId = review1.getReviewId();
UUID customerId = UUID.randomUUID(); UUID customerId = UUID.randomUUID();
UUID bookId = UUID.randomUUID(); UUID bookId = UUID.randomUUID();
Review updatedReview = Review.builder() Review updatedReview = Review.builder()
.avisId(avisId) .reviewId(reviewId)
.customerId(customerId) .customerId(customerId)
.bookId(bookId) .bookId(bookId)
.note(4) .note(4)
@@ -114,7 +114,7 @@ public class ReviewRepositoryTest {
Review savedReview = repository.save(updatedReview); Review savedReview = repository.save(updatedReview);
assertEquals(1, repository.findAll().size()); assertEquals(1, repository.findAll().size());
assertEquals(avisId, savedReview.getAvisId()); assertEquals(reviewId, savedReview.getReviewId());
assertEquals(customerId, savedReview.getCustomerId()); assertEquals(customerId, savedReview.getCustomerId());
assertEquals(bookId, savedReview.getBookId()); assertEquals(bookId, savedReview.getBookId());
assertEquals(4, savedReview.getNote()); assertEquals(4, savedReview.getNote());
@@ -203,9 +203,9 @@ public class ReviewRepositoryTest {
} }
@Test @Test
@DisplayName("findByAvisId should return review with matching avis ID") @DisplayName("findByReviewId should return review with matching review ID")
void testFindByAvisId() { void testFindByReviewId() {
Optional<Review> foundreview = repository.findByAvisId(review1.getAvisId()); Optional<Review> foundreview = repository.findByReviewId(review1.getReviewId());
assertTrue(foundreview.isPresent()); assertTrue(foundreview.isPresent());
assertEquals(review1.getNote(), foundreview.get().getNote()); assertEquals(review1.getNote(), foundreview.get().getNote());
@@ -213,11 +213,11 @@ public class ReviewRepositoryTest {
} }
@Test @Test
@DisplayName("findByAvisId should return empty Optional when a review with avis ID doesn't exist") @DisplayName("findByReviewId should return empty Optional when a review with review ID doesn't exist")
void testFindByAvisIdNotFound() { void testFindByReviewIdNotFound() {
UUID nonExistentAvisId = UUID.randomUUID(); UUID nonExistentReviewId = UUID.randomUUID();
Optional<Review> foundreview = repository.findByAvisId(nonExistentAvisId); Optional<Review> foundreview = repository.findByReviewId(nonExistentReviewId);
assertTrue(foundreview.isEmpty()); assertTrue(foundreview.isEmpty());
} }
@@ -259,19 +259,19 @@ public class ReviewRepositoryTest {
} }
@Test @Test
@DisplayName("existsByAvisId should return true when a review with avis ID exists") @DisplayName("existsByReviewId should return true when a review with review ID exists")
void testExistsByAvisIdExists() { void testExistsByReviewIdExists() {
boolean exists = repository.existsByAvisId(review1.getAvisId()); boolean exists = repository.existsByReviewId(review1.getReviewId());
assertTrue(exists); assertTrue(exists);
} }
@Test @Test
@DisplayName("existsByAvisId should return false when avis ID doesn't exist") @DisplayName("existsByReviewId should return false when review ID doesn't exist")
void testExistsByAvisIdNotExists() { void testExistsByReviewIdNotExists() {
UUID nonExistentAvisId = UUID.randomUUID(); UUID nonExistentReviewId = UUID.randomUUID();
boolean exists = repository.existsByAvisId(nonExistentAvisId); boolean exists = repository.existsByReviewId(nonExistentReviewId);
assertFalse(exists); assertFalse(exists);
} }
@@ -38,7 +38,7 @@ public class ReviewUseCaseTest {
@InjectMocks @InjectMocks
private ReviewUseCase reviewUseCase; private ReviewUseCase reviewUseCase;
private UUID avisId; private UUID reviewId;
private UUID customerId; private UUID customerId;
private UUID bookId; private UUID bookId;
private LocalDate purchaseDate; private LocalDate purchaseDate;
@@ -47,12 +47,12 @@ public class ReviewUseCaseTest {
@BeforeEach @BeforeEach
void setUp() { void setUp() {
avisId = UUID.randomUUID(); reviewId = UUID.randomUUID();
customerId = UUID.randomUUID(); customerId = UUID.randomUUID();
bookId = UUID.randomUUID(); bookId = UUID.randomUUID();
purchaseDate = LocalDate.of(2026, 5, 24); purchaseDate = LocalDate.of(2026, 5, 24);
testReview = Review.builder() testReview = Review.builder()
.avisId(avisId) .reviewId(reviewId)
.customerId(customerId) .customerId(customerId)
.bookId(bookId) .bookId(bookId)
.note(2) .note(2)
@@ -75,7 +75,7 @@ public class ReviewUseCaseTest {
UUID registeredId = reviewUseCase.registerReview(validReviewInfo); UUID registeredId = reviewUseCase.registerReview(validReviewInfo);
assertNotNull(registeredId); assertNotNull(registeredId);
assertEquals(avisId, registeredId); assertEquals(reviewId, registeredId);
verify(reviewRepository, times(1)).save(any(Review.class)); verify(reviewRepository, times(1)).save(any(Review.class));
} }
@@ -148,28 +148,28 @@ public class ReviewUseCaseTest {
} }
@Test @Test
@DisplayName("Should return review when Avis ID exists") @DisplayName("Should return review when Review ID exists")
void testFindReviewByAvisId() { void testFindReviewByReviewId() {
when(reviewRepository.findByAvisId(avisId)).thenReturn(Optional.of(testReview)); when(reviewRepository.findByReviewId(reviewId)).thenReturn(Optional.of(testReview));
Optional<ReviewDTO> foundReview = reviewUseCase.findReviewByAvisId(avisId); Optional<ReviewDTO> foundReview = reviewUseCase.findReviewByReviewId(reviewId);
assertTrue(foundReview.isPresent()); assertTrue(foundReview.isPresent());
assertEquals(testReview.getBookId(), foundReview.get().getBookId()); assertEquals(testReview.getBookId(), foundReview.get().getBookId());
assertEquals(testReview.getNote(), foundReview.get().getNote()); assertEquals(testReview.getNote(), foundReview.get().getNote());
verify(reviewRepository, times(1)).findByAvisId(avisId); verify(reviewRepository, times(1)).findByReviewId(reviewId);
} }
@Test @Test
@DisplayName("Should return empty Optional when avis ID doesn't exist") @DisplayName("Should return empty Optional when review ID doesn't exist")
void testFindReviewByAvisIdNotFound() { void testFindReviewByReviewIdNotFound() {
UUID nonExistentAvisId = UUID.randomUUID(); UUID nonExistentReviewId = UUID.randomUUID();
when(reviewRepository.findByAvisId(nonExistentAvisId)).thenReturn(Optional.empty()); when(reviewRepository.findByReviewId(nonExistentReviewId)).thenReturn(Optional.empty());
Optional<ReviewDTO> foundReview = reviewUseCase.findReviewByAvisId(nonExistentAvisId); Optional<ReviewDTO> foundReview = reviewUseCase.findReviewByReviewId(nonExistentReviewId);
assertTrue(foundReview.isEmpty()); assertTrue(foundReview.isEmpty());
verify(reviewRepository, times(1)).findByAvisId(nonExistentAvisId); verify(reviewRepository, times(1)).findByReviewId(nonExistentReviewId);
} }
} }
@@ -180,11 +180,11 @@ public class ReviewUseCaseTest {
@Test @Test
@DisplayName("Should update review when valid data is provided") @DisplayName("Should update review when valid data is provided")
void testUpdateReviewWithValidData() throws ReviewNotFoundException, NotValidReviewException { void testUpdateReviewWithValidData() throws ReviewNotFoundException, NotValidReviewException {
when(reviewRepository.findByAvisId(avisId)).thenReturn(Optional.of(testReview)); when(reviewRepository.findByReviewId(reviewId)).thenReturn(Optional.of(testReview));
LocalDate updatePurchaseDate = LocalDate.of(2026, 5, 30); LocalDate updatePurchaseDate = LocalDate.of(2026, 5, 30);
Review updatedReview = Review.builder() Review updatedReview = Review.builder()
.avisId(avisId) .reviewId(reviewId)
.customerId(customerId) .customerId(customerId)
.bookId(bookId) .bookId(bookId)
.note(4) .note(4)
@@ -196,29 +196,29 @@ public class ReviewUseCaseTest {
ReviewInfo updateInfo = new ReviewInfo(4, "en fait c'est bien", updatePurchaseDate); ReviewInfo updateInfo = new ReviewInfo(4, "en fait c'est bien", updatePurchaseDate);
ReviewDTO result = reviewUseCase.updateReview(avisId, updateInfo); ReviewDTO result = reviewUseCase.updateReview(reviewId, updateInfo);
assertNotNull(result); assertNotNull(result);
assertEquals(customerId, result.getCustomerId()); assertEquals(customerId, result.getCustomerId());
assertEquals(4, result.getNote()); assertEquals(4, result.getNote());
assertEquals("en fait c'est bien", result.getComment()); assertEquals("en fait c'est bien", result.getComment());
verify(reviewRepository, times(1)).findByAvisId(avisId); verify(reviewRepository, times(1)).findByReviewId(reviewId);
verify(reviewRepository, times(1)).save(any(Review.class)); verify(reviewRepository, times(1)).save(any(Review.class));
} }
@Test @Test
@DisplayName("Should throw exception when avis ID doesn't exist") @DisplayName("Should throw exception when review ID doesn't exist")
void testUpdateReviewNotFound() { void testUpdateReviewNotFound() {
UUID nonExistentAvisId = UUID.randomUUID(); UUID nonExistentReviewId = UUID.randomUUID();
when(reviewRepository.findByAvisId(nonExistentAvisId)).thenReturn(Optional.empty()); when(reviewRepository.findByReviewId(nonExistentReviewId)).thenReturn(Optional.empty());
LocalDate updatePurchaseDate = LocalDate.of(2026, 5, 24); LocalDate updatePurchaseDate = LocalDate.of(2026, 5, 24);
ReviewInfo updateInfo = new ReviewInfo(3, "moyen", updatePurchaseDate); ReviewInfo updateInfo = new ReviewInfo(3, "moyen", updatePurchaseDate);
assertThrows(ReviewNotFoundException.class, assertThrows(ReviewNotFoundException.class,
() -> reviewUseCase.updateReview(nonExistentAvisId, updateInfo)); () -> reviewUseCase.updateReview(nonExistentReviewId, updateInfo));
verify(reviewRepository, times(1)).findByAvisId(nonExistentAvisId); verify(reviewRepository, times(1)).findByReviewId(nonExistentReviewId);
verify(reviewRepository, never()).save(any(Review.class)); verify(reviewRepository, never()).save(any(Review.class));
} }
@@ -229,9 +229,9 @@ public class ReviewUseCaseTest {
ReviewInfo invalidUpdateInfo = new ReviewInfo(0, "éclaté au sol", updatePurchaseDate); ReviewInfo invalidUpdateInfo = new ReviewInfo(0, "éclaté au sol", updatePurchaseDate);
assertThrows(NotValidReviewException.class, assertThrows(NotValidReviewException.class,
() -> reviewUseCase.updateReview(avisId, invalidUpdateInfo)); () -> reviewUseCase.updateReview(reviewId, invalidUpdateInfo));
verify(reviewRepository, never()).findByAvisId(any(UUID.class)); verify(reviewRepository, never()).findByReviewId(any(UUID.class));
verify(reviewRepository, never()).save(any(Review.class)); verify(reviewRepository, never()).save(any(Review.class));
} }
} }
@@ -291,27 +291,27 @@ public class ReviewUseCaseTest {
} }
@Test @Test
@DisplayName("Should delete review when avis ID exists") @DisplayName("Should delete review when review ID exists")
void testDeleteReview() throws ReviewNotFoundException { void testDeleteReview() throws ReviewNotFoundException {
when(reviewRepository.findByAvisId(avisId)).thenReturn(Optional.of(testReview)); when(reviewRepository.findByReviewId(reviewId)).thenReturn(Optional.of(testReview));
doNothing().when(reviewRepository).delete(testReview); doNothing().when(reviewRepository).delete(testReview);
reviewUseCase.deleteReview(avisId); reviewUseCase.deleteReview(reviewId);
verify(reviewRepository, times(1)).findByAvisId(avisId); verify(reviewRepository, times(1)).findByReviewId(reviewId);
verify(reviewRepository, times(1)).delete(testReview); verify(reviewRepository, times(1)).delete(testReview);
} }
@Test @Test
@DisplayName("Should throw exception when avis ID doesn't exist") @DisplayName("Should throw exception when review ID doesn't exist")
void testDeleteReviewNotFound() { void testDeleteReviewNotFound() {
UUID nonExistentAvisId = UUID.randomUUID(); UUID nonExistentReviewId = UUID.randomUUID();
when(reviewRepository.findByAvisId(nonExistentAvisId)).thenReturn(Optional.empty()); when(reviewRepository.findByReviewId(nonExistentReviewId)).thenReturn(Optional.empty());
assertThrows(ReviewNotFoundException.class, assertThrows(ReviewNotFoundException.class,
() -> reviewUseCase.deleteReview(nonExistentAvisId)); () -> reviewUseCase.deleteReview(nonExistentReviewId));
verify(reviewRepository, times(1)).findByAvisId(nonExistentAvisId); verify(reviewRepository, times(1)).findByReviewId(nonExistentReviewId);
verify(reviewRepository, never()).delete(any(Review.class)); verify(reviewRepository, never()).delete(any(Review.class));
} }
} }