forked from pierront/mylibrary-template
Implementation des méthode de delete ainsi que la modification des test pour qu'il fonctionne
This commit is contained in:
+13
@@ -15,6 +15,11 @@ public class ComandeRepository {
|
|||||||
|
|
||||||
public List<Commande> findAll(){return commande;}
|
public List<Commande> findAll(){return commande;}
|
||||||
|
|
||||||
|
|
||||||
|
public void deleteAll() {
|
||||||
|
commande.clear();
|
||||||
|
}
|
||||||
|
|
||||||
public Commande save(Commande newCommande){
|
public Commande save(Commande newCommande){
|
||||||
Optional<Commande> optionalCommandeWithSameIsbn = this.findById(newCommande.getCommandeId());
|
Optional<Commande> optionalCommandeWithSameIsbn = this.findById(newCommande.getCommandeId());
|
||||||
optionalCommandeWithSameIsbn.ifPresent(commande::remove);
|
optionalCommandeWithSameIsbn.ifPresent(commande::remove);
|
||||||
@@ -33,4 +38,12 @@ public class ComandeRepository {
|
|||||||
.anyMatch(customer -> customer.getCommandeId().equals(uuid));
|
.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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+37
-3
@@ -67,7 +67,6 @@ public class CommandeRepositoryTest {
|
|||||||
.pays(pays)
|
.pays(pays)
|
||||||
.modePaiement(modePayement)
|
.modePaiement(modePayement)
|
||||||
.build();
|
.build();
|
||||||
commandeN2.setRandomUUID();
|
|
||||||
commandeN2.setRandomUUIDCommande();
|
commandeN2.setRandomUUIDCommande();
|
||||||
|
|
||||||
List<LigneCommandeInfo> lignesCommande3 = new ArrayList<>();
|
List<LigneCommandeInfo> lignesCommande3 = new ArrayList<>();
|
||||||
@@ -229,7 +228,7 @@ public class CommandeRepositoryTest {
|
|||||||
@Nested
|
@Nested
|
||||||
@DisplayName("Delete operations")
|
@DisplayName("Delete operations")
|
||||||
class DeleteOperations {
|
class DeleteOperations {
|
||||||
}
|
|
||||||
|
|
||||||
@BeforeEach
|
@BeforeEach
|
||||||
void setUpCustomers() {
|
void setUpCustomers() {
|
||||||
@@ -239,7 +238,6 @@ public class CommandeRepositoryTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@DisplayName("Delete should remove the specified customer")
|
@DisplayName("Delete should remove the specified customer")
|
||||||
void testDelete() {
|
void testDelete() {
|
||||||
@@ -293,6 +291,9 @@ public class CommandeRepositoryTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
void TestDeleteAllCommandeByCustomerID() {
|
void TestDeleteAllCommandeByCustomerID() {
|
||||||
|
System.out.println(commandeN1.getClientId());
|
||||||
|
System.out.println(commandeN2.getClientId());
|
||||||
|
System.out.println(commandeN3.getClientId());
|
||||||
repository.deleteById(commandeN1.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());
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user