forked from pierront/mylibrary-template
✅ création des test sur l'objet review
This commit is contained in:
@@ -0,0 +1,51 @@
|
|||||||
|
package fr.iut_fbleau.but3.dev62.mylibrary.review.entity;
|
||||||
|
|
||||||
|
import org.junit.jupiter.api.DisplayName;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
public class ReviewTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Builder should create a valid review instance")
|
||||||
|
void testReviewBuilder() {
|
||||||
|
UUID customerId = UUID.randomUUID();
|
||||||
|
UUID bookId = UUID.randomUUID();
|
||||||
|
Integer note = 5;
|
||||||
|
String comment = "très bon livre";
|
||||||
|
LocalDate purchaseDate = LocalDate.of(2026, 3, 24);
|
||||||
|
|
||||||
|
Review review = Review.builder()
|
||||||
|
.customerId(customerId)
|
||||||
|
.bookId(bookId)
|
||||||
|
.note(note)
|
||||||
|
.comment(comment)
|
||||||
|
.purchaseDate(purchaseDate)
|
||||||
|
.build();
|
||||||
|
|
||||||
|
assertEquals(customerId, review.getCustomerId());
|
||||||
|
assertEquals(bookId, review.getBookId());
|
||||||
|
assertEquals(note, review.getNote());
|
||||||
|
assertEquals(comment, review.getComment());
|
||||||
|
assertEquals(purchaseDate, review.getPurchaseDate());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("setRandomUUID should change the ID to a new random UUID")
|
||||||
|
void testSetRandomUUID() {
|
||||||
|
Review review = Review.builder().build();
|
||||||
|
UUID originalCustomerId = review.getCustomerId();
|
||||||
|
UUID originalBookId = review.getCustomerId();
|
||||||
|
|
||||||
|
review.setRandomUUID();
|
||||||
|
|
||||||
|
assertNotNull(review.getCustomerId());
|
||||||
|
assertNotNull(review.getBookId());
|
||||||
|
assertNotEquals(originalCustomerId, review.getCustomerId());
|
||||||
|
assertNotEquals(originalBookId, review.getBookId());
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user