révisions terminées, tests unitaires et tests d'intégration
This commit is contained in:
@@ -4,6 +4,7 @@
|
|||||||
*/
|
*/
|
||||||
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;
|
||||||
|
|
||||||
@@ -17,8 +18,25 @@ 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
|
||||||
lesLivres.add(b);
|
String issues = "";
|
||||||
return false;
|
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);
|
||||||
|
|
||||||
|
return true;
|
||||||
|
} else return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Livre> getLesLivres() {
|
public List<Livre> getLesLivres() {
|
||||||
|
@@ -9,13 +9,12 @@ 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 String nom;
|
private final String nom;
|
||||||
private ArrayList<Livre> emprunts;
|
private final ArrayList<Livre> emprunts;
|
||||||
|
|
||||||
public Utilisateur(String nom, ArrayList<Livre> mesLivres) {
|
public Utilisateur(String nom, ArrayList<Livre> mesLivres) {
|
||||||
this.nom = nom;
|
this.nom = nom;
|
||||||
@@ -34,6 +33,7 @@ public class Utilisateur {
|
|||||||
// 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
|
* @author Medhi
|
||||||
|
* @param livre
|
||||||
*/
|
*/
|
||||||
public boolean emprunterLivre(Livre livre) {
|
public boolean emprunterLivre(Livre livre) {
|
||||||
if (emprunts.size() < 3) {
|
if (emprunts.size() < 3) {
|
||||||
|
@@ -29,14 +29,50 @@ 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;
|
|
||||||
boolean result = instance.addLivre(b);
|
// Ajout d'un livre avec ISBN invalide
|
||||||
assertEquals(expResult, result);
|
Livre livre = new Livre("Naruto", "Masashi Kishimoto", "1234ABCD567", false);
|
||||||
// TODO review the generated test code and remove the default call to fail.
|
boolean ajoutLivre = instance.addLivre(livre);
|
||||||
fail("The test case is a prototype.");
|
System.out.println("Refus de l'ISBN invalide");
|
||||||
|
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);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -138,9 +138,15 @@ public class LivreValideTest {
|
|||||||
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);
|
||||||
|
|
||||||
auteurFalse2 = "George Sand";
|
//Verification avec des espace
|
||||||
result2 = LivreValide.isValidAuteur(auteurFalse2);
|
String auteurTrue3 = "George Orwell";
|
||||||
assertTrue("Non valide car des espaces", result2);
|
boolean result3 = LivreValide.isValidAuteur(auteurTrue3);
|
||||||
|
assertTrue("",result3);
|
||||||
|
|
||||||
|
//Verification avec -
|
||||||
|
String auteurTrue4 = "George-Orwell";
|
||||||
|
boolean result4 = LivreValide.isValidAuteur(auteurTrue4);
|
||||||
|
assertTrue("",result4);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user