Commit Medhi Rodrigues test intégration #12
@@ -15,7 +15,13 @@ import java.util.List;
|
|||||||
|
|
||||||
public class Utilisateur {
|
public class Utilisateur {
|
||||||
private String nom;
|
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) {
|
public Utilisateur(String nom) {
|
||||||
this.nom = nom;
|
this.nom = nom;
|
||||||
@@ -26,12 +32,17 @@ public class Utilisateur {
|
|||||||
return nom;
|
return nom;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Livre> getEmprunts() {
|
public ArrayList<Livre> getEmprunts() {
|
||||||
return emprunts;
|
return emprunts;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: ajouter un emprunt si l'utilisateur a moins de 3 livres
|
// TODO: ajouter un emprunt si l'utilisateur a moins de 3 livres
|
||||||
public boolean emprunterLivre(Livre livre) {
|
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.Utilisateur;
|
||||||
import com.mycompany.bibliotheque.Metier.Livre;
|
import com.mycompany.bibliotheque.Metier.Livre;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import static jdk.internal.foreign.LayoutPath.SequenceElement.instance;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
@@ -58,13 +60,24 @@ public class UtilisateurTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testEmprunterLivre() {
|
public void testEmprunterLivre() {
|
||||||
System.out.println("emprunterLivre");
|
System.out.println("emprunterLivre");
|
||||||
Livre livre = null;
|
|
||||||
Utilisateur instance = null;
|
Livre a = new Livre("1984", "George Orwell", "1234567890123", false);
|
||||||
boolean expResult = false;
|
Livre b = new Livre("1984", "Test2", "1232667890123", false);
|
||||||
boolean result = instance.emprunterLivre(livre);
|
Livre c = new Livre ("1888","Test3","1232667890123",false);
|
||||||
assertEquals(expResult, result);
|
Livre d = new Livre ("1263","Test4","1236267890123",false);
|
||||||
// TODO review the generated test code and remove the default call to fail.
|
|
||||||
fail("The test case is a prototype.");
|
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