/* * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license * Click nbfs://nbhost/SystemFileSystem/Templates/UnitTests/JUnit4TestClass.java to edit this template */ package métiers; import java.util.HashMap; import org.junit.Before; import org.junit.Test; import static org.junit.Assert.*; /** * * @author famille Thevenot */ public class CommandeTest { public CommandeTest() { } @Before public void setUp() { } /** * Test of ajouter method, of class Commande. */ @Test public void testAjouter() { Instrument instr1=new Instrument(1,"Piano",10, 8300f); Instrument instr2=new Instrument(2,"Violon",9, 105f); Commande laCommande = new Commande(1,1,"12/09/2024"); System.out.println("ajouter"); boolean ajoutRes= laCommande.ajouter(instr1, 2); boolean ajoutAttendu = true; System.out.println("cas0 : cas normal, ajout une ligne de commande"); assertEquals("Test0 ajout 2 instr1",ajoutAttendu,ajoutRes); int stockRes=instr1.getQteStock(); int stockAttendu=8; assertEquals("Test0 stock",stockAttendu,stockRes); int qteRes=laCommande.getLesLignes().get(instr1); int qteAttendu=2; assertEquals("Test0 quantite",qteRes, qteAttendu); System.out.println("Cas1 : ajout autre ligne de commande"); laCommande.ajouter(instr2, 6); int tailleR=laCommande.getLesLignes().size(); int tailleAttendue=2; assertEquals("Test1 taille",tailleAttendue,tailleR); /* System.out.println("Cas2 : màj quantité commandée d'une ligne existante"); laCommande.ajouter(instr2, 5); stockRes=instr2.getQteStock(); stockAttendu=4; assertEquals("test2 stock",stockAttendu,stockRes ); /*qteRes=laCommande.getLesLignes().get(instr2); qteAttendu=5; assertEquals("Test2 quantite", qteAttendu,qteRes); System.out.println("Cas3 : ajout nouvelle ligne avec quantité > stock"); System.out.println("Cas4 : ajout nouvelle ligne avec quantité 0"); System.out.println("Cas5 : mise à 0 quantité commandée d'une ligne existante"); System.out.println("Cas6 : màj d'une ligne existante avec qté>stock");*/ } @Test public void testSupprimer(){ Instrument instr1 = new Instrument(1,"Piano",10,8300f); Instrument instr2 = new Instrument(2,"Violon",9,105f); Commande laCommande2 = new Commande(1,1,"12/09/2024"); laCommande2.ajouter(instr1,2); boolean expectedResult=false; boolean expectedResult2=true; int stockAttendu=10; System.out.println("Test de la méthode supprimer"); boolean test = laCommande2.supprimer(instr2); boolean test2 = laCommande2.supprimer(instr1); int test3 = instr1.getQteStock(); assertEquals("suppression impossible : ",expectedResult,test); assertEquals("suppression possible : ",expectedResult2,test2); assertEquals("Quantité d'instr1 en stock",stockAttendu,test3); } }