Compare commits
1 Commits
developpem
...
dev.pomika
Author | SHA1 | Date | |
---|---|---|---|
876d092fd4 |
@@ -1,4 +0,0 @@
|
|||||||
dépôt gitea : https://gitea.lyc-lecastel.fr/delphine.thevenot/2026TestsBibliotheque.git
|
|
||||||
branche : developpement
|
|
||||||
|
|
||||||
multibranches, fusions difficiles, à revoir
|
|
@@ -1,4 +0,0 @@
|
|||||||
-- Projet Gestion d'un bibliothèque
|
|
||||||
support pour découvrir les tests : unitaire, d'intégration, fonctionnels
|
|
||||||
Java, JUNIT
|
|
||||||
promo 2026 - D5 - A01 à A04
|
|
@@ -51,13 +51,12 @@ public class LivreValide {
|
|||||||
|
|
||||||
// 3. Auteur : non vide et pas de chiffres ou caractères spéciaux
|
// 3. Auteur : non vide et pas de chiffres ou caractères spéciaux
|
||||||
public static boolean isValidAuteur(String auteur) {
|
public static boolean isValidAuteur(String auteur) {
|
||||||
|
|
||||||
//verification que auteur n'est pas vide ou null
|
//verification que auteur n'est pas vide ou null
|
||||||
if (auteur == null || auteur.isBlank()) {
|
if (auteur == null || auteur.isBlank()) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
//ajout d'un pattern pour avoir uniquement des minuscules/majuscules
|
//ajout d'un pattern pour avoir uniquement des minuscules/majuscules
|
||||||
String pattern = "^[a-zA-Z -]+$";
|
String pattern = "^[a-zA-Z]+$";
|
||||||
//verification boolean que le nom d'auteur corresponde au patterne
|
//verification boolean que le nom d'auteur corresponde au patterne
|
||||||
return auteur.matches(pattern);
|
return auteur.matches(pattern);
|
||||||
}
|
}
|
||||||
@@ -83,26 +82,6 @@ public class LivreValide {
|
|||||||
|
|
||||||
return contenuValide;
|
return contenuValide;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* IsDisponible()
|
|
||||||
* Vérifier livre pas déjà emprunté
|
|
||||||
* @author Emile
|
|
||||||
*/
|
|
||||||
public static boolean isDisponible (Livre leLivre){
|
|
||||||
boolean valide = true;
|
|
||||||
if(leLivre.isEmprunte()){
|
|
||||||
valide = false;
|
|
||||||
}
|
|
||||||
return valide;
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* IsDisponible()
|
|
||||||
* Vérifier livre pas déjà emprunté
|
|
||||||
* @author Morgann/Emile
|
|
||||||
*/
|
|
||||||
public static boolean retourLivre(Utilisateur user){
|
public static boolean retourLivre(Utilisateur user){
|
||||||
Scanner sc = new Scanner(System.in);
|
Scanner sc = new Scanner(System.in);
|
||||||
int i=0;
|
int i=0;
|
||||||
|
@@ -14,7 +14,6 @@ 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 {
|
||||||
@@ -22,9 +21,8 @@ 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", mesLivres.add(l1));
|
Utilisateur u1 = new Utilisateur("Alice");
|
||||||
|
|
||||||
System.out.println("Bienvenue dans la bibliothèque !");
|
System.out.println("Bienvenue dans la bibliothèque !");
|
||||||
while (choix!=4){
|
while (choix!=4){
|
||||||
|
@@ -4,7 +4,6 @@
|
|||||||
*/
|
*/
|
||||||
package com.mycompany.bibliotheque.Metier;
|
package com.mycompany.bibliotheque.Metier;
|
||||||
|
|
||||||
import com.mycompany.bibliotheque.Controle.LivreValide;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@@ -18,25 +17,8 @@ public class Bibliotheque {
|
|||||||
// 5. ISBN doit être unique
|
// 5. ISBN doit être unique
|
||||||
public boolean addLivre(Livre b) {
|
public boolean addLivre(Livre b) {
|
||||||
//ajoute b si valide et si n'existe pas - à écrire
|
//ajoute b si valide et si n'existe pas - à écrire
|
||||||
String issues = "";
|
|
||||||
if (!LivreValide.isValidIsbn(b.getIsbn())) issues += "1 ";
|
|
||||||
if (!LivreValide.isValidTitre(b.getTitre())) issues += "2 ";
|
|
||||||
if (!LivreValide.isValidAuteur(b.getAuteur())) issues += "3 ";
|
|
||||||
if (!LivreValide.isLongueurTitreValid(b.getTitre())) issues += "4 ";
|
|
||||||
if (!LivreValide.isContenuTitreValide(b.getTitre())) issues += "5";
|
|
||||||
|
|
||||||
System.out.println(issues);
|
|
||||||
|
|
||||||
if (issues.length() < 1) {
|
|
||||||
System.out.println("valide");
|
|
||||||
for (Livre livre : this.getLesLivres()) {
|
|
||||||
if (livre.getIsbn().equals(b.getIsbn())) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
lesLivres.add(b);
|
lesLivres.add(b);
|
||||||
|
return false;
|
||||||
return true;
|
|
||||||
} else return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Livre> getLesLivres() {
|
public List<Livre> getLesLivres() {
|
||||||
|
@@ -9,14 +9,15 @@ package com.mycompany.bibliotheque.Metier;
|
|||||||
* @author dthev
|
* @author dthev
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
import com.mycompany.bibliotheque.Metier.Livre;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class Utilisateur {
|
public class Utilisateur {
|
||||||
private final String nom;
|
private String nom;
|
||||||
private final ArrayList<Livre> emprunts;
|
private List<Livre> emprunts;
|
||||||
|
|
||||||
public Utilisateur(String nom, ArrayList<Livre> mesLivres) {
|
public Utilisateur(String nom) {
|
||||||
this.nom = nom;
|
this.nom = nom;
|
||||||
this.emprunts = new ArrayList<>();
|
this.emprunts = new ArrayList<>();
|
||||||
}
|
}
|
||||||
@@ -29,18 +30,8 @@ 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
|
|
||||||
* @param livre
|
|
||||||
*/
|
|
||||||
public boolean emprunterLivre(Livre livre) {
|
public boolean emprunterLivre(Livre livre) {
|
||||||
if (emprunts.size() < 3) {
|
return false; // à compléter
|
||||||
emprunts.add(livre);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@@ -30,49 +30,13 @@ public class BibliothequeTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testAddLivre() {
|
public void testAddLivre() {
|
||||||
System.out.println("addLivre");
|
System.out.println("addLivre");
|
||||||
|
Livre b = null;
|
||||||
Bibliotheque instance = new Bibliotheque();
|
Bibliotheque instance = new Bibliotheque();
|
||||||
|
boolean expResult = false;
|
||||||
// Ajout d'un livre avec ISBN invalide
|
boolean result = instance.addLivre(b);
|
||||||
Livre livre = new Livre("Naruto", "Masashi Kishimoto", "1234ABCD567", false);
|
assertEquals(expResult, result);
|
||||||
boolean ajoutLivre = instance.addLivre(livre);
|
// TODO review the generated test code and remove the default call to fail.
|
||||||
System.out.println("Refus de l'ISBN invalide");
|
fail("The test case is a prototype.");
|
||||||
assertFalse("L'ISBN du livre n'est pas censé être valide avec lettres !", ajoutLivre);
|
|
||||||
|
|
||||||
// Ajout d'un livre avec titre invalide
|
|
||||||
livre = new Livre("<script>Dragon Ball</script>", "Akira Toriyama", "8762709652385", false);
|
|
||||||
ajoutLivre = instance.addLivre(livre);
|
|
||||||
System.out.println("Refus de titre invalide");
|
|
||||||
assertFalse("Le titre du livre n'est pas censé être valide avec des balises !", ajoutLivre);
|
|
||||||
|
|
||||||
// Ajout d'un livre avec auteur invalide
|
|
||||||
livre = new Livre("Dr. STONE", "Bo1ch1", "8762207682385", false);
|
|
||||||
ajoutLivre = instance.addLivre(livre);
|
|
||||||
System.out.println("Refus d'auteur invalide");
|
|
||||||
assertFalse("L'auteur du livre n'est pas censé être valide avec des caractères non alphabétiques !", ajoutLivre);
|
|
||||||
|
|
||||||
// Ajout d'un livre avec longueur de titre invalide
|
|
||||||
livre = new Livre("Dandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadandadan", "Yukinobu Tatsu", "1702203672985", false);
|
|
||||||
ajoutLivre = instance.addLivre(livre);
|
|
||||||
System.out.println("Refus de longueur de titre invalide");
|
|
||||||
assertFalse("Le titre n'est pas censé être valide avec une longueur excédant les 200 caractères !", ajoutLivre);
|
|
||||||
|
|
||||||
// Ajout d'un livre avec contenu de titre invalide
|
|
||||||
livre = new Livre("007", "Steve Maingana", "3712503622788", false);
|
|
||||||
ajoutLivre = instance.addLivre(livre);
|
|
||||||
System.out.println("Refus de contenu de titre invalide invalide");
|
|
||||||
assertFalse("Le titre n'est pas censé être valide sans au moins 2 caractères alphabétiques !", ajoutLivre);
|
|
||||||
|
|
||||||
// Premier ajout de livre
|
|
||||||
livre = new Livre("Frieren", "Kanehito Yamada", "6785708652385", false);
|
|
||||||
ajoutLivre = instance.addLivre(livre);
|
|
||||||
System.out.println("Premier ajout d'un même livre");
|
|
||||||
System.out.println(ajoutLivre);
|
|
||||||
assertTrue("La bibliothèque ne permet pas de doublon !", ajoutLivre);
|
|
||||||
|
|
||||||
// Second ajout du même livre
|
|
||||||
ajoutLivre = instance.addLivre(livre);
|
|
||||||
System.out.println("Refus d'ajout du même livre");
|
|
||||||
assertFalse("La bibliothèque ne permet pas de doublon !", ajoutLivre);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -5,7 +5,6 @@
|
|||||||
package com.mycompany.bibliotheque;
|
package com.mycompany.bibliotheque;
|
||||||
|
|
||||||
import com.mycompany.bibliotheque.Controle.LivreValide;
|
import com.mycompany.bibliotheque.Controle.LivreValide;
|
||||||
import com.mycompany.bibliotheque.Metier.Livre;
|
|
||||||
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.*;
|
||||||
@@ -114,7 +113,7 @@ public class LivreValideTest {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of isValidAuteur method, of class LivreValide.
|
* Test of isValidAuteur method, of class LivreValide.
|
||||||
* @author Medhi
|
* @author Medhi/Steve
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testIsValidAuteur() {
|
public void testIsValidAuteur() {
|
||||||
@@ -137,16 +136,6 @@ public class LivreValideTest {
|
|||||||
boolean expResult2 = false;
|
boolean expResult2 = false;
|
||||||
boolean result2 = LivreValide.isValidAuteur(auteurFalse2);
|
boolean result2 = LivreValide.isValidAuteur(auteurFalse2);
|
||||||
assertEquals("Non valide car des caractères spéciaux sont présent", expResult2,result2);
|
assertEquals("Non valide car des caractères spéciaux sont présent", expResult2,result2);
|
||||||
|
|
||||||
//Verification avec des espace
|
|
||||||
String auteurTrue3 = "George Orwell";
|
|
||||||
boolean result3 = LivreValide.isValidAuteur(auteurTrue3);
|
|
||||||
assertTrue("",result3);
|
|
||||||
|
|
||||||
//Verification avec -
|
|
||||||
String auteurTrue4 = "George-Orwell";
|
|
||||||
boolean result4 = LivreValide.isValidAuteur(auteurTrue4);
|
|
||||||
assertTrue("",result4);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -182,6 +171,7 @@ public class LivreValideTest {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of isTitreValid method, of class LivreValide.
|
* Test of isTitreValid method, of class LivreValide.
|
||||||
* @author Steve
|
* @author Steve
|
||||||
@@ -206,30 +196,4 @@ public class LivreValideTest {
|
|||||||
titre = "Ti!";
|
titre = "Ti!";
|
||||||
assertTrue("Le titre fait au moins 2 caractères alphabétiques !", LivreValide.isContenuTitreValide(titre));
|
assertTrue("Le titre fait au moins 2 caractères alphabétiques !", LivreValide.isContenuTitreValide(titre));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Test testIsDisponible()
|
|
||||||
* Vérifier livre pas déjà emprunté
|
|
||||||
* @author Emile
|
|
||||||
*/
|
|
||||||
@Test
|
|
||||||
public void testIsDisponible(){
|
|
||||||
System.out.println("isDisponible");
|
|
||||||
Livre unLivre = new Livre("Le comte de MonteCristo","Alexandre Dumas", "1234567891245", false);
|
|
||||||
|
|
||||||
System.out.println("Test1 : un livre disponible");
|
|
||||||
boolean result1 = LivreValide.isDisponible(unLivre);
|
|
||||||
assertTrue("Le chevron < n'est pas censé etre accepté", result1);
|
|
||||||
System.out.println("Le test1 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
|
|
||||||
unLivre.setEmprunte(true);
|
|
||||||
System.out.println("Test2 : un livre indiisponible");
|
|
||||||
boolean result2 = LivreValide.isDisponible(unLivre);
|
|
||||||
assertFalse("Le chevron < n'est pas censé etre accepté", result2);
|
|
||||||
System.out.println("Le test2 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
@@ -6,7 +6,6 @@ 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;
|
||||||
@@ -55,27 +54,17 @@ 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;
|
||||||
Livre a = new Livre("1984", "George Orwell", "1234567890123", false);
|
Utilisateur instance = null;
|
||||||
Livre b = new Livre("1984", "Test2", "1232667890123", false);
|
boolean expResult = false;
|
||||||
Livre c = new Livre ("1888","Test3","1232667890123",false);
|
boolean result = instance.emprunterLivre(livre);
|
||||||
Livre d = new Livre ("1263","Test4","1236267890123",false);
|
assertEquals(expResult, result);
|
||||||
|
// TODO review the generated test code and remove the default call to fail.
|
||||||
ArrayList<Livre> mesLivres = new ArrayList<>();
|
fail("The test case is a prototype.");
|
||||||
|
|
||||||
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