Implementation des méthode de delete ainsi que la modification des test pour qu'il fonctionne

This commit is contained in:
2026-06-14 13:26:07 +02:00
parent 69ce78a113
commit 7e8a5522d8
2 changed files with 113 additions and 66 deletions
@@ -15,6 +15,11 @@ public class ComandeRepository {
public List<Commande> findAll(){return commande;}
public void deleteAll() {
commande.clear();
}
public Commande save(Commande newCommande){
Optional<Commande> optionalCommandeWithSameIsbn = this.findById(newCommande.getCommandeId());
optionalCommandeWithSameIsbn.ifPresent(commande::remove);
@@ -33,4 +38,12 @@ public class ComandeRepository {
.anyMatch(customer -> customer.getCommandeId().equals(uuid));
}
public void delete(Commande commande) {
this.commande.remove(commande);
}
public void deleteById(UUID uuid) {
this.commande.removeIf(commande -> commande.getClientId().equals(uuid));
}
}
@@ -67,7 +67,6 @@ public class CommandeRepositoryTest {
.pays(pays)
.modePaiement(modePayement)
.build();
commandeN2.setRandomUUID();
commandeN2.setRandomUUIDCommande();
List<LigneCommandeInfo> lignesCommande3 = new ArrayList<>();
@@ -229,7 +228,7 @@ public class CommandeRepositoryTest {
@Nested
@DisplayName("Delete operations")
class DeleteOperations {
}
@BeforeEach
void setUpCustomers() {
@@ -239,7 +238,6 @@ public class CommandeRepositoryTest {
}
@Test
@DisplayName("Delete should remove the specified customer")
void testDelete() {
@@ -293,6 +291,9 @@ public class CommandeRepositoryTest {
@Test
void TestDeleteAllCommandeByCustomerID() {
System.out.println(commandeN1.getClientId());
System.out.println(commandeN2.getClientId());
System.out.println(commandeN3.getClientId());
repository.deleteById(commandeN1.getClientId());
@@ -307,8 +308,41 @@ public class CommandeRepositoryTest {
}
@Test
void TestDeleteAllCommandeByNonExistentCustomerID() {
List<LigneCommandeInfo> lignesCommande = new ArrayList<>();
LigneCommandeInfo commande1 = new LigneCommandeInfo(321);
LigneCommandeInfo commande2 = new LigneCommandeInfo(3);
lignesCommande.add(commande1);
lignesCommande.add(commande2);
Commande nonExistentCommande = Commande.builder()
.lignesCommande(lignesCommande)
.rue("non")
.ville("non")
.codePostal("Existent")
.pays("0000")
.modePaiement(ModePaiement.PAYPAL.name())
.build();
nonExistentCommande.setRandomUUIDCommande();
repository.deleteById(nonExistentCommande.getClientId());
assertDoesNotThrow(() -> repository.findAll());
assertEquals(3, repository.findAll().size());
}
}