diff --git a/pom.xml b/pom.xml index 97fb890..d81552a 100644 --- a/pom.xml +++ b/pom.xml @@ -30,7 +30,25 @@ maven-surefire-plugin 3.1.2 + + org.apache.maven.plugins + maven-compiler-plugin + 3.14.0 + + ${project.build.sourceEncoding} + + + + org.apache.maven.plugins + maven-resources-plugin + 3.3.1 + + ${project.build.sourceEncoding} + + - + + UTF-8 + diff --git a/src/main/java/com/mycompany/bibliotheque/Contrôle/LivreValide.java b/src/main/java/com/mycompany/bibliotheque/Contrôle/LivreValide.java index bc09dcb..cd0979d 100644 --- a/src/main/java/com/mycompany/bibliotheque/Contrôle/LivreValide.java +++ b/src/main/java/com/mycompany/bibliotheque/Contrôle/LivreValide.java @@ -36,6 +36,12 @@ public class LivreValide { // 5. Titre : non null et au moins 2 caractères public static boolean isContenuTitreValide(String titre) { // TODO Steve: implémenter la validation - return false; + if (titre == null) { + return false; + } + + boolean contenuValide = titre.matches(".*[a-zA-Z].*[a-zA-Z].*"); + + return contenuValide; } } diff --git a/src/main/java/com/mycompany/bibliotheque/GestionBibliotheque.java b/src/main/java/com/mycompany/bibliotheque/GestionBibliotheque.java index 9b145a5..83a1d7a 100644 --- a/src/main/java/com/mycompany/bibliotheque/GestionBibliotheque.java +++ b/src/main/java/com/mycompany/bibliotheque/GestionBibliotheque.java @@ -24,7 +24,7 @@ public class GestionBibliotheque { Livre l1 = new Livre("Le secret des secrets","Dan Brown","9782709668385",true); Utilisateur u1 = new Utilisateur("Alice"); - System.out.println("Bienvenue dans la bibliothèque !"); + System.out.println("Bienvenue dans la bibliothèque !"); while (choix!=4){ System.out.println("1. Afficher un livre"); System.out.println("2. Ajouter un livre"); diff --git a/src/main/java/com/mycompany/bibliotheque/Métier/Bibliotheque.java b/src/main/java/com/mycompany/bibliotheque/Métier/Bibliotheque.java index 176cb3e..87ee721 100644 --- a/src/main/java/com/mycompany/bibliotheque/Métier/Bibliotheque.java +++ b/src/main/java/com/mycompany/bibliotheque/Métier/Bibliotheque.java @@ -8,15 +8,15 @@ import java.util.ArrayList; import java.util.List; /** - * Classe métier + * Classe métier * @author dthev */ public class Bibliotheque { private List lesLivres = new ArrayList<>(); - // 5. ISBN doit être unique + // 5. ISBN doit être unique 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); return false; } diff --git a/src/main/java/com/mycompany/bibliotheque/Métier/Livre.java b/src/main/java/com/mycompany/bibliotheque/Métier/Livre.java index c16ddc1..679b0c1 100644 --- a/src/main/java/com/mycompany/bibliotheque/Métier/Livre.java +++ b/src/main/java/com/mycompany/bibliotheque/Métier/Livre.java @@ -12,7 +12,7 @@ package com.mycompany.bibliotheque.Métier; public class Livre { private String titre; private String auteur; - private String isbn; // ISBN sous forme de chaîne + private String isbn; // ISBN sous forme de chaîne private Boolean emprunte; public Livre(String titre, String auteur, String isbn, Boolean emprunte) { diff --git a/src/test/java/com/mycompany/bibliotheque/LivreTest.java b/src/test/java/com/mycompany/bibliotheque/LivreTest.java index 45d22d3..89886f8 100644 --- a/src/test/java/com/mycompany/bibliotheque/LivreTest.java +++ b/src/test/java/com/mycompany/bibliotheque/LivreTest.java @@ -14,10 +14,10 @@ public class LivreTest { public void testCreationLivre() { Livre b = new Livre("1984", "George Orwell", "1234567890123", false); - assertNotNull(b); - assertEquals("1984", b.getTitre()); - assertEquals("George Orwel", b.getAuteur()); // corrigé - assertEquals("1234567890123", b.getIsbn()); - assertFalse(b.isEmprunte()); // si la méthode existe + assertNotNull("L'objet Livre ne peut pas être nulle !", b); + assertEquals("Titre du Livre incorrect", "1984", b.getTitre()); + assertEquals("Auteur du Livre incorrect", "George Orwel", b.getAuteur()); // corrigé + assertEquals("ISBN du Livre incorrect", "1234567890123", b.getIsbn()); + assertFalse("Le livre n'est pas censé être emprunté", b.isEmprunte()); // si la méthode existe } } \ No newline at end of file diff --git a/src/test/java/com/mycompany/bibliotheque/LivreValideTest.java b/src/test/java/com/mycompany/bibliotheque/LivreValideTest.java index 399998e..3826df6 100644 --- a/src/test/java/com/mycompany/bibliotheque/LivreValideTest.java +++ b/src/test/java/com/mycompany/bibliotheque/LivreValideTest.java @@ -39,7 +39,7 @@ public class LivreValideTest { /** * Test of isValidTitre method, of class LivreValide. - * @author Salomé/Emile + * @author Salomé/Emile */ @Test public void testIsValidTitre() { @@ -90,11 +90,21 @@ public class LivreValideTest { public void testIsContenuTitreValide() { System.out.println("isTitreValid"); String titre = ""; - boolean expResult = false; - boolean result = LivreValide.isContenuTitreValide(titre); - assertEquals(expResult, result); - // TODO review the generated test code and remove the default call to fail. - fail("The test case is a prototype."); + assertFalse("Le titre ne doit pas être vide !", LivreValide.isContenuTitreValide(titre)); + titre = null; + assertFalse("Le titre ne peut pas être nul !", LivreValide.isContenuTitreValide(titre)); + titre = "Ti"; + assertTrue("Le titre fait au moins 2 caractères alphabétiques !", LivreValide.isContenuTitreValide(titre)); + titre = "T"; + assertFalse("Le titre fait au moins 2 caractères alphabétiques !", LivreValide.isContenuTitreValide(titre)); + titre = "1234"; + assertFalse("Le titre fait au moins 2 caractères alphabétiques !", LivreValide.isContenuTitreValide(titre)); + titre = "Ti2"; + assertTrue("Le titre fait au moins 2 caractères alphabétiques !", LivreValide.isContenuTitreValide(titre)); + titre = "*$!"; + assertFalse("Le titre fait au moins 2 caractères alphabétiques !", LivreValide.isContenuTitreValide(titre)); + titre = "Ti!"; + assertTrue("Le titre fait au moins 2 caractères alphabétiques !", LivreValide.isContenuTitreValide(titre)); } }