test emprunt <=3 livres
This commit is contained in:
4
aLire.txt
Normal file
4
aLire.txt
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
dépôt gitea : https://gitea.lyc-lecastel.fr/delphine.thevenot/2026TestsBibliotheque.git
|
||||||
|
branche : developpement
|
||||||
|
|
||||||
|
multibranches, fusions difficiles, à revoir
|
@@ -14,6 +14,7 @@ import com.mycompany.bibliotheque.Metier.Bibliotheque;
|
|||||||
import com.mycompany.bibliotheque.Metier.Emprunt;
|
import com.mycompany.bibliotheque.Metier.Emprunt;
|
||||||
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.Scanner;
|
import java.util.Scanner;
|
||||||
|
|
||||||
public class GestionBibliotheque {
|
public class GestionBibliotheque {
|
||||||
@@ -21,8 +22,9 @@ public class GestionBibliotheque {
|
|||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
int choix=0;
|
int choix=0;
|
||||||
Bibliotheque laBibli = new Bibliotheque();
|
Bibliotheque laBibli = new Bibliotheque();
|
||||||
|
ArrayList<Livre> mesLivres = new ArrayList<>();
|
||||||
Livre l1 = new Livre("Le secret des secrets","Dan Brown","9782709668385",true);
|
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 !");
|
System.out.println("Bienvenue dans la bibliothèque !");
|
||||||
while (choix!=4){
|
while (choix!=4){
|
||||||
|
@@ -15,9 +15,9 @@ 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) {
|
public Utilisateur(String nom, ArrayList<Livre> mesLivres) {
|
||||||
this.nom = nom;
|
this.nom = nom;
|
||||||
this.emprunts = new ArrayList<>();
|
this.emprunts = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -30,8 +30,17 @@ public class Utilisateur {
|
|||||||
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
|
||||||
|
/**
|
||||||
|
* @author Medhi
|
||||||
|
*/
|
||||||
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,6 +6,7 @@ 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 org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
@@ -54,17 +55,27 @@ public class UtilisateurTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of emprunterLivre method, of class Utilisateur.
|
* Test of emprunterLivre method, of class Utilisateur.
|
||||||
|
* @author Madhi
|
||||||
*/
|
*/
|
||||||
@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<>();
|
||||||
|
|
||||||
|
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