forked from pierront/mylibrary-template
test delete
This commit is contained in:
+80
-9
@@ -15,8 +15,7 @@ import java.util.List;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
public class CommandeRepositoryTest {
|
public class CommandeRepositoryTest {
|
||||||
|
|
||||||
@@ -220,14 +219,8 @@ public class CommandeRepositoryTest {
|
|||||||
UUID nonExistentId = UUID.randomUUID();
|
UUID nonExistentId = UUID.randomUUID();
|
||||||
boolean exists = repository.existsById(nonExistentId);
|
boolean exists = repository.existsById(nonExistentId);
|
||||||
|
|
||||||
assertTrue(exists);
|
assertFalse(exists);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -238,6 +231,84 @@ public class CommandeRepositoryTest {
|
|||||||
class DeleteOperations {
|
class DeleteOperations {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
void setUpCustomers() {
|
||||||
|
repository.save(commandeN1);
|
||||||
|
repository.save(commandeN2);
|
||||||
|
repository.save(commandeN3);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Delete should remove the specified customer")
|
||||||
|
void testDelete() {
|
||||||
|
repository.delete(commandeN1);
|
||||||
|
|
||||||
|
List<Commande> commande = repository.findAll();
|
||||||
|
|
||||||
|
assertEquals(2, commande.size());
|
||||||
|
assertFalse(commande.contains(commandeN1));
|
||||||
|
assertTrue(commande.contains(commandeN2));
|
||||||
|
assertTrue(commande.contains(commandeN3));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("DeleteAll should remove all customers")
|
||||||
|
void testDeleteAll() {
|
||||||
|
repository.deleteAll();
|
||||||
|
|
||||||
|
List<Commande> commande = repository.findAll();
|
||||||
|
|
||||||
|
assertTrue(commande.isEmpty());
|
||||||
|
assertEquals(0, commande.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Delete should not throw exception when customer doesn't exist")
|
||||||
|
void testDeleteNonExistentCustomer() {
|
||||||
|
|
||||||
|
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();
|
||||||
|
|
||||||
|
assertDoesNotThrow(() -> repository.delete(nonExistentCommande));
|
||||||
|
|
||||||
|
assertEquals(3, repository.findAll().size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void TestDeleteAllCommandeByCustomerID(){
|
||||||
|
repository.deleteById(commandeN1.getClientId());
|
||||||
|
|
||||||
|
|
||||||
|
List<Commande> commande = repository.findAll();
|
||||||
|
|
||||||
|
assertEquals(1, commande.size());
|
||||||
|
assertFalse(commande.contains(commandeN1));
|
||||||
|
assertFalse(commande.contains(commandeN2));
|
||||||
|
assertTrue(commande.contains(commandeN3));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user