création des test sur les UUID

This commit is contained in:
2026-05-25 18:46:21 +02:00
committed by Marvin AUBERT
parent 3ace5810f8
commit 76b60297c1
4 changed files with 70 additions and 4 deletions
@@ -18,4 +18,9 @@ public class Commande {
private String codePostal; private String codePostal;
private String pays; private String pays;
private String modePaiement; private String modePaiement;
public void setRandomUUID() {
this.clientId = UUID.randomUUID();
}
} }
@@ -11,6 +11,10 @@ import java.util.UUID;
public class LigneCommande { public class LigneCommande {
int quantite; int quantite;
UUID id; UUID livreId;
public void setRandomUUID() {
this.livreId = UUID.randomUUID();
}
} }
@@ -1,21 +1,65 @@
package fr.iut_fbleau.but3.dev62.mylibrary.commande.entity; package fr.iut_fbleau.but3.dev62.mylibrary.commande.entity;
import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo; import fr.iut_fbleau.but3.dev62.mylibrary.commande.LigneCommandeInfo;
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import static org.junit.jupiter.api.Assertions.*;
public class CommandeTest { public class CommandeTest {
@Test @Test
public void commandeTest(){ public void commandeTest(){
UUID clientId = UUID.randomUUID(); UUID clientId = UUID.randomUUID();
List<LigneCommandeInfo> lignesCommande = new ArrayList<>(); List<LigneCommandeInfo> lignesCommande = new ArrayList<>();
LigneCommandeInfo commande1 = new LigneCommandeInfo(12);
LigneCommandeInfo commande2 = new LigneCommandeInfo(13);
lignesCommande.add(commande1);
lignesCommande.add(commande2);
String rue = "rue du chien" ; String rue = "rue du chien" ;
String ville = "LKa Rochette" ; String ville = "LKa Rochette" ;
String codePostal = "7700" ; String codePostal = "7700" ;
String pays = "France" ; String pays = "France" ;
Commande commande = Commande.builder()
.clientId(clientId)
.lignesCommande(lignesCommande)
.rue(rue)
.ville(ville)
.codePostal(codePostal)
.pays(pays)
.build();
assertEquals(clientId, commande.getClientId());
assertEquals(lignesCommande, commande.getLignesCommande());
assertEquals(rue, commande.getRue());
assertEquals(ville, commande.getVille());
assertEquals(codePostal, commande.getCodePostal());
assertEquals(pays, commande.getPays());
} }
@Test
@DisplayName("setRandomUUID should change the ID to a new random UUID")
void testSetRandomUUID() {
Commande commande = Commande.builder().build();
UUID originalId = commande.getClientId();
commande.setRandomUUID();
assertNotNull(commande.getClientId());
assertNotEquals(originalId, commande.getClientId());
}
} }
@@ -1,11 +1,12 @@
package fr.iut_fbleau.but3.dev62.mylibrary.commande.entity; package fr.iut_fbleau.but3.dev62.mylibrary.commande.entity;
import fr.iut_fbleau.but3.dev62.mylibrary.customer.entity.Customer;
import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import java.util.UUID; import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.*;
public class LigneCommandeTest { public class LigneCommandeTest {
@@ -17,12 +18,24 @@ public class LigneCommandeTest {
LigneCommande ligneCommande = LigneCommande.builder() LigneCommande ligneCommande = LigneCommande.builder()
.id(id) .livreId(id)
.quantite(quantite) .quantite(quantite)
.build(); .build();
assertEquals(id, ligneCommande.getId()); assertEquals(id, ligneCommande.getLivreId());
assertEquals(quantite, ligneCommande.getQuantite()); assertEquals(quantite, ligneCommande.getQuantite());
} }
@Test
@DisplayName("setRandomUUID should change the ID to a new random UUID")
void testSetRandomUUID() {
LigneCommande ligneCommande = LigneCommande.builder().build();
UUID originalId = ligneCommande.getLivreId();
ligneCommande.setRandomUUID();
assertNotNull(ligneCommande.getLivreId());
assertNotEquals(originalId, ligneCommande.getLivreId());
}
} }