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 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));
|
||||
}
|
||||
}
|
||||
|
||||
+39
-5
@@ -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() {
|
||||
@@ -275,7 +273,7 @@ public class CommandeRepositoryTest {
|
||||
lignesCommande.add(commande2);
|
||||
|
||||
|
||||
Commande nonExistentCommande =Commande.builder()
|
||||
Commande nonExistentCommande = Commande.builder()
|
||||
.lignesCommande(lignesCommande)
|
||||
.rue("non")
|
||||
.ville("non")
|
||||
@@ -292,7 +290,10 @@ public class CommandeRepositoryTest {
|
||||
|
||||
|
||||
@Test
|
||||
void TestDeleteAllCommandeByCustomerID(){
|
||||
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());
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user