Commit Medhi Rodrigues test intégration
This commit is contained in:
@@ -15,8 +15,14 @@ import java.util.List;
|
||||
|
||||
public class Utilisateur {
|
||||
private String nom;
|
||||
private List<Livre> emprunts;
|
||||
private ArrayList<Livre> emprunts;
|
||||
|
||||
public Utilisateur(String nom, ArrayList<Livre> emprunts) {
|
||||
this.nom = nom;
|
||||
this.emprunts = emprunts;
|
||||
}
|
||||
|
||||
|
||||
public Utilisateur(String nom) {
|
||||
this.nom = nom;
|
||||
this.emprunts = new ArrayList<>();
|
||||
@@ -26,12 +32,17 @@ public class Utilisateur {
|
||||
return nom;
|
||||
}
|
||||
|
||||
public List<Livre> getEmprunts() {
|
||||
public ArrayList<Livre> getEmprunts() {
|
||||
return emprunts;
|
||||
}
|
||||
|
||||
// TODO: ajouter un emprunt si l'utilisateur a moins de 3 livres
|
||||
public boolean emprunterLivre(Livre livre) {
|
||||
return false; // à compléter
|
||||
if (emprunts.size() < 3) {
|
||||
emprunts.add(livre);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,9 @@ package com.mycompany.bibliotheque;
|
||||
|
||||
import com.mycompany.bibliotheque.Metier.Utilisateur;
|
||||
import com.mycompany.bibliotheque.Metier.Livre;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import static jdk.internal.foreign.LayoutPath.SequenceElement.instance;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
@@ -58,13 +60,24 @@ public class UtilisateurTest {
|
||||
@Test
|
||||
public void testEmprunterLivre() {
|
||||
System.out.println("emprunterLivre");
|
||||
Livre livre = null;
|
||||
Utilisateur instance = null;
|
||||
boolean expResult = false;
|
||||
boolean result = instance.emprunterLivre(livre);
|
||||
assertEquals(expResult, result);
|
||||
// TODO review the generated test code and remove the default call to fail.
|
||||
fail("The test case is a prototype.");
|
||||
|
||||
Livre a = new Livre("1984", "George Orwell", "1234567890123", false);
|
||||
Livre b = new Livre("1984", "Test2", "1232667890123", false);
|
||||
Livre c = new Livre ("1888","Test3","1232667890123",false);
|
||||
Livre d = new Livre ("1263","Test4","1236267890123",false);
|
||||
|
||||
ArrayList<Livre> mesLivres = new ArrayList<>();
|
||||
mesLivres.add(a);
|
||||
mesLivres.add(b);
|
||||
|
||||
Utilisateur utilisateur = new Utilisateur("Medhi", mesLivres);
|
||||
|
||||
boolean result = utilisateur.emprunterLivre(c);
|
||||
//assertFalse("L'utilisateur a plus de trois livres",result);
|
||||
assertTrue("L'utilisateur a trop de livres",result);
|
||||
mesLivres.add(d);
|
||||
result = utilisateur.emprunterLivre(d);
|
||||
assertFalse("L'utilisateur n'a pas encore trois emprunts ",result);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user