forked from pierront/mylibrary-template
premeir test avis
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package fr.iut_fbleau.but3.dev62.mylibrary.avis.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.*;
|
||||
|
||||
class AvisTest {
|
||||
|
||||
@Test
|
||||
@DisplayName("Builder should create a valid Avis instance")
|
||||
void testAvisBuilder() {
|
||||
UUID id = UUID.randomUUID();
|
||||
UUID clientId = UUID.randomUUID();
|
||||
UUID livreId = UUID.randomUUID();
|
||||
|
||||
Avis avis = Avis.builder()
|
||||
.id(id)
|
||||
.clientId(clientId)
|
||||
.livreId(livreId)
|
||||
.note(5)
|
||||
.commentaire("Excellent livre !")
|
||||
.dateAchat(LocalDate.of(2024, 1, 15))
|
||||
.build();
|
||||
|
||||
assertEquals(id, avis.getId());
|
||||
assertEquals(clientId, avis.getClientId());
|
||||
assertEquals(livreId, avis.getLivreId());
|
||||
assertEquals(5, avis.getNote());
|
||||
assertEquals("Excellent livre !", avis.getCommentaire());
|
||||
assertEquals(LocalDate.of(2024, 1, 15), avis.getDateAchat());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("setRandomUUID should set a new non-null UUID")
|
||||
void testSetRandomUUID() {
|
||||
Avis avis = Avis.builder().build();
|
||||
UUID originalId = avis.getId();
|
||||
|
||||
avis.setRandomUUID();
|
||||
|
||||
assertNotNull(avis.getId());
|
||||
assertNotEquals(originalId, avis.getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Two setRandomUUID calls should produce different UUIDs")
|
||||
void testSetRandomUUIDTwice() {
|
||||
Avis avis = Avis.builder().build();
|
||||
avis.setRandomUUID();
|
||||
UUID firstId = avis.getId();
|
||||
|
||||
avis.setRandomUUID();
|
||||
|
||||
assertNotEquals(firstId, avis.getId());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user