test emprunt <=3 livres
This commit is contained in:
@@ -14,6 +14,7 @@ import com.mycompany.bibliotheque.Metier.Bibliotheque;
|
||||
import com.mycompany.bibliotheque.Metier.Emprunt;
|
||||
import com.mycompany.bibliotheque.Metier.Utilisateur;
|
||||
import com.mycompany.bibliotheque.Metier.Livre;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Scanner;
|
||||
|
||||
public class GestionBibliotheque {
|
||||
@@ -21,8 +22,9 @@ public class GestionBibliotheque {
|
||||
Scanner sc = new Scanner(System.in);
|
||||
int choix=0;
|
||||
Bibliotheque laBibli = new Bibliotheque();
|
||||
ArrayList<Livre> mesLivres = new ArrayList<>();
|
||||
Livre l1 = new Livre("Le secret des secrets","Dan Brown","9782709668385",true);
|
||||
Utilisateur u1 = new Utilisateur("Alice");
|
||||
//Utilisateur u1 = new Utilisateur("Alice", mesLivres.add(l1));
|
||||
|
||||
System.out.println("Bienvenue dans la bibliothèque !");
|
||||
while (choix!=4){
|
||||
|
@@ -15,9 +15,9 @@ import java.util.List;
|
||||
|
||||
public class Utilisateur {
|
||||
private String nom;
|
||||
private List<Livre> emprunts;
|
||||
private ArrayList<Livre> emprunts;
|
||||
|
||||
public Utilisateur(String nom) {
|
||||
public Utilisateur(String nom, ArrayList<Livre> mesLivres) {
|
||||
this.nom = nom;
|
||||
this.emprunts = new ArrayList<>();
|
||||
}
|
||||
@@ -30,8 +30,17 @@ public class Utilisateur {
|
||||
return emprunts;
|
||||
}
|
||||
|
||||
|
||||
// TODO: ajouter un emprunt si l'utilisateur a moins de 3 livres
|
||||
/**
|
||||
* @author Medhi
|
||||
*/
|
||||
public boolean emprunterLivre(Livre livre) {
|
||||
return false; // à compléter
|
||||
if (emprunts.size() < 3) {
|
||||
emprunts.add(livre);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -6,6 +6,7 @@ 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 org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -52,19 +53,29 @@ public class UtilisateurTest {
|
||||
fail("The test case is a prototype.");
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Test of emprunterLivre method, of class Utilisateur.
|
||||
* @author Madhi
|
||||
*/
|
||||
@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<>();
|
||||
|
||||
Utilisateur utilisateur = new Utilisateur("Medhi", mesLivres);
|
||||
boolean result = utilisateur.emprunterLivre(a);
|
||||
|
||||
assertTrue("L'utilisateur a trop de livres",result);
|
||||
result = utilisateur.emprunterLivre(b);
|
||||
result = utilisateur.emprunterLivre(c);
|
||||
result = utilisateur.emprunterLivre(d);
|
||||
assertFalse("L'utilisateur n'a pas encore trois emprunts ",result);
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user