Feature/manage reviews #2

Merged
Patrick FELIX-VIMALARATNAM merged 20 commits from feature/manage_reviews into main 2026-06-12 20:48:07 +02:00
2 changed files with 23 additions and 15 deletions
Showing only changes of commit 9ee039a32e - Show all commits
@@ -6,6 +6,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import java.util.stream.Collectors;
public class ReviewRepository {
@@ -28,16 +29,16 @@ public class ReviewRepository {
return newReview;
}
public Optional<Review> findByCustomerId(UUID customerUUID) {
public ArrayList<Review> findByCustomerId(UUID customerUUID) {
return this.reviews.stream()
.filter(review -> review.getCustomerId().equals(customerUUID))
.findFirst();
.collect(Collectors.toCollection(ArrayList::new));
}
public Optional<Review> findByBookId(UUID bookUUID) {
public ArrayList<Review> findByBookId(UUID bookUUID) {
return this.reviews.stream()
.filter(review -> review.getBookId().equals(bookUUID))
.findFirst();
.collect(Collectors.toCollection(ArrayList::new));
}
public Optional<Review> findByAvisId(UUID avisUUID) {
@@ -7,6 +7,7 @@ import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
@@ -143,6 +144,8 @@ public class ReviewRepositoryTest {
void setUpReviews() {
repository.save(review1);
repository.save(review2);
repository.save(review3);
repository.save(review4);
}
@Test
@@ -150,19 +153,22 @@ public class ReviewRepositoryTest {
void testFindAll() {
List<Review> reviews = repository.findAll();
assertEquals(2, reviews.size());
assertEquals(4, reviews.size());
assertTrue(reviews.contains(review1));
assertTrue(reviews.contains(review2));
assertTrue(reviews.contains(review3));
assertTrue(reviews.contains(review4));
}
@Test
@DisplayName("findByCustomerId should return review with matching customer ID")
void testFindByCustomerId() {
Optional<Review> foundreview = repository.findByCustomerId(review1.getCustomerId());
ArrayList<Review> foundreviews = repository.findByCustomerId(review2.getCustomerId());
assertTrue(foundreview.isPresent());
assertEquals(review1.getNote(), foundreview.get().getNote());
assertEquals(review1.getComment(), foundreview.get().getComment());
assertTrue(!foundreviews.isEmpty());
boolean allSameCustomer = foundreviews.stream()
.allMatch(review -> review.getCustomerId().equals(review2.getCustomerId()));
assertTrue(allSameCustomer);
}
@Test
@@ -170,7 +176,7 @@ public class ReviewRepositoryTest {
void testFindByCustomerIdNotFound() {
UUID nonExistentCustomerId = UUID.randomUUID();
Optional<Review> foundreview = repository.findByCustomerId(nonExistentCustomerId);
ArrayList<Review> foundreview = repository.findByCustomerId(nonExistentCustomerId);
assertTrue(foundreview.isEmpty());
}
@@ -178,11 +184,12 @@ public class ReviewRepositoryTest {
@Test
@DisplayName("findByBookId should return review with matching book ID")
void testFindByBookId() {
Optional<Review> foundreview = repository.findByBookId(review1.getBookId());
ArrayList<Review> foundreviews = repository.findByBookId(review2.getBookId());
assertTrue(foundreview.isPresent());
assertEquals(review1.getNote(), foundreview.get().getNote());
assertEquals(review1.getComment(), foundreview.get().getComment());
assertTrue(!foundreviews.isEmpty());
boolean allSameCustomer = foundreviews.stream()
.allMatch(review -> review.getBookId().equals(review2.getBookId()));
assertTrue(allSameCustomer);
}
@Test
@@ -190,7 +197,7 @@ public class ReviewRepositoryTest {
void testFindByBookIdNotFound() {
UUID nonExistentBookId = UUID.randomUUID();
Optional<Review> foundreview = repository.findByBookId(nonExistentBookId);
ArrayList<Review> foundreview = repository.findByBookId(nonExistentBookId);
assertTrue(foundreview.isEmpty());
}