Skip to content

Commit 99b398b

Browse files
🔀 Merge pull request #34 from DevLab-umontp/Couverture-des-tests
🚨 Correction bug professeur
2 parents 37c0042 + 34b1d0d commit 99b398b

File tree

7 files changed

+188
-19
lines changed

7 files changed

+188
-19
lines changed

‎pom.xml‎

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,29 @@
235235
</executions>
236236
</plugin>
237237

238+
<plugin>
239+
<groupId>org.pitest</groupId>
240+
<artifactId>pitest-maven</artifactId>
241+
<version>1.6.2</version>
242+
<dependencies>
243+
<dependency>
244+
<groupId>org.pitest</groupId>
245+
<artifactId>pitest-junit5-plugin</artifactId>
246+
<version>0.12</version>
247+
</dependency>
248+
<dependency>
249+
<groupId>io.github.wmaarts</groupId>
250+
<artifactId>pitest-mutation-testing-elements-plugin</artifactId>
251+
<version>0.3.1</version>
252+
</dependency>
253+
</dependencies>
254+
<configuration>
255+
<outputFormats>
256+
<format>HTML2</format>
257+
</outputFormats>
258+
</configuration>
259+
</plugin>
260+
238261
</plugins>
239262
</build>
240263
</project>

‎src/main/java/fr/umontp/edt/EmploiDuTemps.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ private File getFichierIcsDepuisLienIcal() {
123123
}
124124

125125
@Override
126-
public void actualiser() {
126+
public synchronized void actualiser() {
127127
File fichierIcs = getFichierIcsDepuisLienIcal();
128128
Calendar calendar = convertieFichierIcsEnCalendar(fichierIcs);
129129
ArrayList<Cours> coursList = new ArrayList<>();

‎src/main/java/fr/umontp/edt/Professeur.java‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package fr.umontp.edt;
22

3-
import java.util.Locale;
3+
import fr.umontp.edt.outils.OutilsProfesseur;
44

55
/**
66
* <b>Professeur est la classe représentant un professeur au sein de l'emploi du
@@ -17,9 +17,10 @@
1717
* </p>
1818
*
1919
* @see RepertoireProfesseur
20+
* @see OutilsProfesseur
2021
*
2122
* @author MathieuSoysal
22-
* @version 1.0.0
23+
* @version 1.0.1
2324
*/
2425
public class Professeur {
2526
private String denomination;
@@ -36,15 +37,7 @@ public class Professeur {
3637
String[] infosProf = nomPrenom.split(" ");
3738
nom = infosProf[0];
3839
prenom = infosProf[1];
39-
denomination = formater(nom, prenom);
40-
}
41-
42-
static String formater(String nom, String prenom) {
43-
return formater(nom + " " + prenom);
44-
}
45-
46-
static String formater(String nomPrenom) {
47-
return nomPrenom.toUpperCase(Locale.FRANCE).replaceAll("[^A-Z ]", " ");
40+
denomination = OutilsProfesseur.formater(nom, prenom);
4841
}
4942

5043
/**

‎src/main/java/fr/umontp/edt/RepertoireProfesseur.java‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
import java.util.regex.Matcher;
77
import java.util.regex.Pattern;
88

9+
import fr.umontp.edt.outils.OutilsProfesseur;
10+
911
/**
1012
* <b>RepertoireProfesseur est la classe qui repertorie tous les professeurs de
1113
* l'emploi du temps.</b>
@@ -43,7 +45,7 @@ static Professeur[] getProfesseurDepuisDescriptionEtAjouterSiNonPresent(String d
4345
Matcher m = Pattern.compile(regex).matcher(description);
4446
final List<Professeur> matches = new ArrayList<>();
4547
while (m.find()) {
46-
String nomPrenomProf = Professeur.formater(m.group(0));
48+
String nomPrenomProf = OutilsProfesseur.formater(m.group(0));
4749
matches.add(repertoire.computeIfAbsent(nomPrenomProf, k -> new Professeur(nomPrenomProf)));
4850
}
4951
return matches.toArray(new Professeur[matches.size()]);
@@ -61,7 +63,7 @@ static Professeur[] getProfesseurDepuisDescriptionEtAjouterSiNonPresent(String d
6163
* @see java.util.HashMap#get(java.lang.Object)
6264
*/
6365
public static Professeur get(String nom, String prenom) {
64-
return repertoire.get(Professeur.formater(nom, prenom));
66+
return repertoire.get(OutilsProfesseur.formater(nom, prenom));
6567
}
6668

6769
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package fr.umontp.edt.outils;
2+
3+
import java.text.Normalizer;
4+
import java.util.Locale;
5+
import java.util.regex.Pattern;
6+
7+
import fr.umontp.edt.Professeur;
8+
9+
/**
10+
* <b>ProfesseurOutils est la classe utilitaire pour le fonctionnement interne
11+
* de la class {@link Professeur}.</b>
12+
*
13+
* @see Professeur
14+
*
15+
* @author MathieuSoysal
16+
* @version 1.0.0
17+
*/
18+
public class OutilsProfesseur {
19+
private OutilsProfesseur() {
20+
throw new IllegalStateException("Class utilitaire");
21+
}
22+
23+
/**
24+
* @param str {@code String} auquel l'on doit enlever l'accentuation
25+
*
26+
* @return {@code String} sans accentuation.
27+
*
28+
* @see Normalizer
29+
*
30+
* @since 1.0.0
31+
*/
32+
public static String supprimerAccentuation(String str) {
33+
String nfdNormalizedString = Normalizer.normalize(str, Normalizer.Form.NFD);
34+
Pattern pattern = Pattern.compile("\\p{InCombiningDiacriticalMarks}+");
35+
return pattern.matcher(nfdNormalizedString).replaceAll("");
36+
}
37+
38+
/**
39+
* Concatène les deux variables {@code nom} et {@code prenom}, et renvoie une
40+
* variable formaté pour la class {@link Professeur}.
41+
*
42+
* @param nom du professeur
43+
* @param prenom du professeur
44+
*
45+
* @return {@code String} formaté pour la class {@link Professeur}.
46+
*
47+
* @see String#toUpperCase(Locale)
48+
* @see OutilsProfesseur#supprimerAccentuation(String)
49+
*
50+
* @since 1.0.0
51+
*/
52+
public static String formater(String nom, String prenom) {
53+
return OutilsProfesseur.formater(nom + " " + prenom);
54+
}
55+
56+
/**
57+
* @param nomPrenom non et prénom du professeur séparé par 3 espaces.
58+
*
59+
* @return la variable {@code nomPrenom} formaté pour la class
60+
* {@link Professeur}.
61+
*
62+
* @see String#toUpperCase(Locale)
63+
* @see OutilsProfesseur#supprimerAccentuation(String)
64+
*
65+
* @since 1.0.0
66+
*/
67+
public static String formater(String nomPrenom) {
68+
nomPrenom = supprimerAccentuation(nomPrenom);
69+
return nomPrenom.toUpperCase(Locale.FRANCE).replaceAll("[^A-Z ]|(?<=\\S)\\s(?=\\S)", "");
70+
}
71+
72+
}

‎src/test/java/fr/umontp/edt/ProfesseurTest.java‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,12 @@
22

33
import static org.junit.jupiter.api.Assertions.assertEquals;
44

5+
import java.util.stream.Stream;
6+
57
import org.junit.jupiter.api.Test;
8+
import org.junit.jupiter.params.ParameterizedTest;
9+
import org.junit.jupiter.params.provider.Arguments;
10+
import org.junit.jupiter.params.provider.MethodSource;
611

712
class ProfesseurTest {
813

@@ -13,11 +18,18 @@ void testConstructeur_UnStrings_prenomNomCombine() {
1318
assertEquals("Jean", professeur.getPrenom());
1419
}
1520

16-
@Test
17-
void testEquals_deuxProfesseursIdentiqueAvecConstructeurDifferent_avecDifferenceMajuscule() {
18-
Professeur professeur1 = new Professeur("DUpuis JeAN");
19-
Professeur professeur2 = new Professeur("DupUis JEan");
20-
assertEquals(professeur1, professeur2);
21+
@ParameterizedTest(name = "Le professeur {0} doit être égal avec {1}")
22+
@MethodSource("genererArgumentsPourtest_equals")
23+
void test_equals(Professeur prof1, Professeur prof2) {
24+
assertEquals(prof1, prof2);
25+
}
26+
27+
private static Stream<Arguments> genererArgumentsPourtest_equals() {
28+
return Stream.of(//
29+
Arguments.of(new Professeur("DUpuis JeAN"), new Professeur("DupUis JEan")), //
30+
Arguments.of(new Professeur("prés-dupuis Jean"), new Professeur("pres-dupuis Jean")), //
31+
Arguments.of(new Professeur("D'Ôrge Jean"), new Professeur("DÔrge Jean")), //
32+
Arguments.of(new Professeur("D'Ôrge Jean"), new Professeur("D Ôrge Jean")));
2133
}
2234

2335
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
package fr.umontp.edt.outils;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import java.util.stream.Stream;
6+
7+
import org.junit.jupiter.params.ParameterizedTest;
8+
import org.junit.jupiter.params.provider.Arguments;
9+
import org.junit.jupiter.params.provider.MethodSource;
10+
11+
class OutilsProfesseurTest {
12+
13+
@ParameterizedTest(name = "la chaine de caractères {0} une fois son accentuation supprimé doit être égale à {1}")
14+
@MethodSource("genererArgumentsPourtest_supprimerAccentuation")
15+
void test_supprimerAccentuation(String input, String excepted) {
16+
assertEquals(excepted, OutilsProfesseur.supprimerAccentuation(input));
17+
}
18+
19+
private static Stream<Arguments> genererArgumentsPourtest_supprimerAccentuation() {
20+
return Stream.of(//
21+
Arguments.of("É", "E"), //
22+
Arguments.of("1234567890", "1234567890"), //
23+
Arguments.of("ô", "o"), //
24+
Arguments.of("à", "a"), //
25+
Arguments.of("è", "e"), //
26+
Arguments.of("ç", "c"), //
27+
Arguments.of("'", "'"), //
28+
Arguments.of("-", "-"), //
29+
Arguments.of(" ", " "), //
30+
Arguments.of("é", "e"));
31+
}
32+
33+
@ParameterizedTest(name = "la chaine de caractères {0} une fois formaté doit être égale à {1}")
34+
@MethodSource("genererArgumentsPourtest_formater_1parametre")
35+
void test_formater_1parametre(String input, String excepted) {
36+
assertEquals(excepted, OutilsProfesseur.formater(input));
37+
}
38+
39+
private static Stream<Arguments> genererArgumentsPourtest_formater_1parametre() {
40+
return Stream.of(//
41+
Arguments.of("", ""), //
42+
Arguments.of("test", "TEST"), //
43+
Arguments.of("D'Orge", "DORGE"), //
44+
Arguments.of("D Orge", "DORGE"), //
45+
Arguments.of("TeEsT", "TEEST"), //
46+
Arguments.of("Téèçà", "TEECA"), //
47+
Arguments.of("ÉÈÇÀ", "EECA"), //
48+
Arguments.of("test t@°0245est", "TEST TEST"));
49+
}
50+
51+
@ParameterizedTest(name = "la chaine de caractères {0} une fois formaté doit être égale à {1}")
52+
@MethodSource("genererArgumentsPourtest_formater_2parametres")
53+
void test_formater_2parametres(String input1, String input2, String excepted) {
54+
assertEquals(excepted, OutilsProfesseur.formater(input1, input2));
55+
}
56+
57+
private static Stream<Arguments> genererArgumentsPourtest_formater_2parametres() {
58+
return Stream.of(//
59+
Arguments.of("", "", " "), //
60+
Arguments.of("test", "TEST", "TEST TEST"), //
61+
Arguments.of("TeEsT", "TeEsT", "TEEST TEEST"), //
62+
Arguments.of("T eEsT", "TeE sT", "TEEST TEEST"), //
63+
Arguments.of("Téèçà", "Téèçà", "TEECA TEECA"), //
64+
Arguments.of("ÉÈÇÀ", "ÉÈÇÀ", "EECA EECA"), //
65+
Arguments.of("te93~('st", "t@°0245est", "TEST TEST"));
66+
}
67+
}

0 commit comments

Comments
 (0)