Compare commits
2 Commits
a606a72476
...
steve
Author | SHA1 | Date | |
---|---|---|---|
d8ec5254df | |||
bc740d970e |
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,5 +1 @@
|
|||||||
/target/
|
/target/
|
||||||
<<<<<<< HEAD
|
|
||||||
=======
|
|
||||||
*.xml
|
|
||||||
>>>>>>> 6e8f63e2c0b4f89a6f46070511e8ce4223af4bb7
|
|
||||||
|
20
pom.xml
20
pom.xml
@@ -30,7 +30,25 @@
|
|||||||
<artifactId>maven-surefire-plugin</artifactId>
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
<version>3.1.2</version>
|
<version>3.1.2</version>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.14.0</version>
|
||||||
|
<configuration>
|
||||||
|
<encoding>${project.build.sourceEncoding}</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>3.3.1</version>
|
||||||
|
<configuration>
|
||||||
|
<encoding>${project.build.sourceEncoding}</encoding>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
</properties>
|
||||||
</project>
|
</project>
|
||||||
|
@@ -12,22 +12,7 @@ public class LivreValide {
|
|||||||
// 1. ISBN : exactement 13 chiffres
|
// 1. ISBN : exactement 13 chiffres
|
||||||
public static boolean isValidIsbn(String isbn) {
|
public static boolean isValidIsbn(String isbn) {
|
||||||
// TODO Emile: implémenter la validation
|
// TODO Emile: implémenter la validation
|
||||||
|
return false;
|
||||||
boolean valide = true;
|
|
||||||
if(isbn.length() == 13){
|
|
||||||
int i = 0;
|
|
||||||
while (i < 13 && valide) {
|
|
||||||
if(!Character.isDigit(isbn.charAt(i))){
|
|
||||||
valide = false;
|
|
||||||
}else{
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
valide = false;
|
|
||||||
}
|
|
||||||
return valide;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// 2. Titre : pas de balises HTML/JS (<script>, <img>, etc.)
|
// 2. Titre : pas de balises HTML/JS (<script>, <img>, etc.)
|
||||||
@@ -51,6 +36,12 @@ public class LivreValide {
|
|||||||
// 5. Titre : non null et au moins 2 caractères
|
// 5. Titre : non null et au moins 2 caractères
|
||||||
public static boolean isContenuTitreValide(String titre) {
|
public static boolean isContenuTitreValide(String titre) {
|
||||||
// TODO Steve: implémenter la validation
|
// 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;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -24,7 +24,7 @@ public class GestionBibliotheque {
|
|||||||
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");
|
||||||
|
|
||||||
System.out.println("Bienvenue dans la bibliothèque !");
|
System.out.println("Bienvenue dans la bibliothèque !");
|
||||||
while (choix!=4){
|
while (choix!=4){
|
||||||
System.out.println("1. Afficher un livre");
|
System.out.println("1. Afficher un livre");
|
||||||
System.out.println("2. Ajouter un livre");
|
System.out.println("2. Ajouter un livre");
|
||||||
|
@@ -8,15 +8,15 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Classe métier
|
* Classe métier
|
||||||
* @author dthev
|
* @author dthev
|
||||||
*/
|
*/
|
||||||
public class Bibliotheque {
|
public class Bibliotheque {
|
||||||
private List<Livre> lesLivres = new ArrayList<>();
|
private List<Livre> lesLivres = new ArrayList<>();
|
||||||
|
|
||||||
// 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);
|
lesLivres.add(b);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@@ -12,7 +12,7 @@ package com.mycompany.bibliotheque.Métier;
|
|||||||
public class Livre {
|
public class Livre {
|
||||||
private String titre;
|
private String titre;
|
||||||
private String auteur;
|
private String auteur;
|
||||||
private String isbn; // ISBN sous forme de chaîne
|
private String isbn; // ISBN sous forme de chaîne
|
||||||
private Boolean emprunte;
|
private Boolean emprunte;
|
||||||
|
|
||||||
public Livre(String titre, String auteur, String isbn, Boolean emprunte) {
|
public Livre(String titre, String auteur, String isbn, Boolean emprunte) {
|
||||||
|
@@ -14,10 +14,10 @@ public class LivreTest {
|
|||||||
public void testCreationLivre() {
|
public void testCreationLivre() {
|
||||||
Livre b = new Livre("1984", "George Orwell", "1234567890123", false);
|
Livre b = new Livre("1984", "George Orwell", "1234567890123", false);
|
||||||
|
|
||||||
assertNotNull(b);
|
assertNotNull("L'objet Livre ne peut pas être nulle !", b);
|
||||||
assertEquals("1984", b.getTitre());
|
assertEquals("Titre du Livre incorrect", "1984", b.getTitre());
|
||||||
assertEquals("George Orwel", b.getAuteur()); // corrigé
|
assertEquals("Auteur du Livre incorrect", "George Orwel", b.getAuteur()); // corrigé
|
||||||
assertEquals("1234567890123", b.getIsbn());
|
assertEquals("ISBN du Livre incorrect", "1234567890123", b.getIsbn());
|
||||||
assertFalse(b.isEmprunte()); // si la méthode existe
|
assertFalse("Le livre n'est pas censé être emprunté", b.isEmprunte()); // si la méthode existe
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -29,54 +29,17 @@ public class LivreValideTest {
|
|||||||
@Test
|
@Test
|
||||||
public void testIsValidIsbn() {
|
public void testIsValidIsbn() {
|
||||||
System.out.println("isValidIsbn");
|
System.out.println("isValidIsbn");
|
||||||
|
String isbn = "";
|
||||||
|
boolean expResult = false;
|
||||||
//Test 1 : un isbn avec moins de 13 carractères
|
boolean result = LivreValide.isValidIsbn(isbn);
|
||||||
System.out.println("Test1 : un isbn avec moins de 13 carractères");
|
assertEquals(expResult, result);
|
||||||
String isbn1 = "1234568912";
|
// TODO review the generated test code and remove the default call to fail.
|
||||||
boolean expResult1 = false;
|
fail("The test case is a prototype.");
|
||||||
boolean result1 = LivreValide.isValidIsbn(isbn1);
|
|
||||||
assertEquals("Le nombre de carractère est censé est trop petit",expResult1, result1);
|
|
||||||
assertFalse("Trop petit",LivreValide.isValidIsbn(isbn1));
|
|
||||||
System.out.println("Le test1 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
|
|
||||||
//Test2 : lettre dans l'isbn
|
|
||||||
System.out.println("Test2 : lettre dans l'isbn");
|
|
||||||
String isbn2 = "123456789ABC2";
|
|
||||||
boolean expResult2 = false;
|
|
||||||
boolean result2 = LivreValide.isValidIsbn(isbn2);
|
|
||||||
assertEquals("Les alphas ne sont pas autorisés", expResult2, result2);
|
|
||||||
System.out.println("Le test2 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
|
|
||||||
//Test3 : mauvais nombre de carratère 15
|
|
||||||
System.out.println("Test3: isbn comportant plus de 13 chiffres");
|
|
||||||
String isbn3 = "1234568912123568";
|
|
||||||
boolean expResult3 = false;
|
|
||||||
boolean result3 = LivreValide.isValidIsbn(isbn3);
|
|
||||||
assertEquals("Le nombre de carractère est censé est trop grand",expResult3, result3);
|
|
||||||
System.out.println("Le test3 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
|
|
||||||
//Test4 : Un isbn valide
|
|
||||||
System.out.println("Test4: Un isbn valide");
|
|
||||||
String isbn4 = "1234568912126";
|
|
||||||
boolean expResult4 = true;
|
|
||||||
boolean result4 = LivreValide.isValidIsbn(isbn4);
|
|
||||||
assertEquals("L'isbn est censé être valide",expResult4, result4);
|
|
||||||
System.out.println("Le test4 est validé");
|
|
||||||
System.out.println("--------------------------------------------------");
|
|
||||||
System.out.println(" ");
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test of isValidTitre method, of class LivreValide.
|
* Test of isValidTitre method, of class LivreValide.
|
||||||
* @author Salomé/Emile
|
* @author Salomé/Emile
|
||||||
*/
|
*/
|
||||||
@Test
|
@Test
|
||||||
public void testIsValidTitre() {
|
public void testIsValidTitre() {
|
||||||
@@ -119,14 +82,6 @@ public class LivreValideTest {
|
|||||||
fail("The test case is a prototype.");
|
fail("The test case is a prototype.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void testIsContenuTitreValid() {
|
|
||||||
System.out.println("isLongueurTitreValid");
|
|
||||||
String titre = "";
|
|
||||||
boolean expResult = false;
|
|
||||||
boolean result = LivreValide.isLongueurTitreValid(titre);
|
|
||||||
}
|
|
||||||
/**
|
/**
|
||||||
* Test of isTitreValid method, of class LivreValide.
|
* Test of isTitreValid method, of class LivreValide.
|
||||||
* @author Steve
|
* @author Steve
|
||||||
@@ -135,12 +90,21 @@ public class LivreValideTest {
|
|||||||
public void testIsContenuTitreValide() {
|
public void testIsContenuTitreValide() {
|
||||||
System.out.println("isTitreValid");
|
System.out.println("isTitreValid");
|
||||||
String titre = "";
|
String titre = "";
|
||||||
boolean expResult = false;
|
assertFalse("Le titre ne doit pas être vide !", LivreValide.isContenuTitreValide(titre));
|
||||||
boolean result = LivreValide.isContenuTitreValide(titre);
|
titre = null;
|
||||||
|
assertFalse("Le titre ne peut pas être nul !", LivreValide.isContenuTitreValide(titre));
|
||||||
assertEquals(expResult, result);
|
titre = "Ti";
|
||||||
// TODO review the generated test code and remove the default call to fail.
|
assertTrue("Le titre fait au moins 2 caractères alphabétiques !", LivreValide.isContenuTitreValide(titre));
|
||||||
fail("The test case is a prototype.");
|
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));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user