1165 |
aurelien |
1 |
package org.tela_botanica.del.test.composants.motsclesimage;
|
|
|
2 |
|
|
|
3 |
import static org.junit.Assert.*;
|
|
|
4 |
|
|
|
5 |
import java.util.ArrayList;
|
|
|
6 |
import java.util.Iterator;
|
|
|
7 |
import java.util.List;
|
|
|
8 |
|
|
|
9 |
import org.junit.Before;
|
|
|
10 |
import org.junit.Test;
|
|
|
11 |
import org.tela_botanica.del.client.modeles.MotCle;
|
|
|
12 |
import org.tela_botanica.del.client.utils.StringUtils;
|
|
|
13 |
|
|
|
14 |
public class MotsClesImageTest {
|
|
|
15 |
|
|
|
16 |
List<MotCle> motsCles;
|
|
|
17 |
List<String> motClesCelAFiltrer;
|
|
|
18 |
|
|
|
19 |
@Before
|
|
|
20 |
public void setUp() {
|
|
|
21 |
String chaineMotsClesCelAFiltrer = "fleur,feuille,ecorce,fruit,port,defiphoto";
|
|
|
22 |
this.motClesCelAFiltrer = new ArrayList<String>();
|
|
|
23 |
String[] tabMotsClesCelAFiltrer = chaineMotsClesCelAFiltrer.split(",");
|
|
|
24 |
for (int i = 0; i < tabMotsClesCelAFiltrer.length; i++) {
|
|
|
25 |
this.motClesCelAFiltrer.add(StringUtils.normaliser(tabMotsClesCelAFiltrer[i]));
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
motsCles = new ArrayList<MotCle>();
|
|
|
29 |
}
|
|
|
30 |
|
|
|
31 |
@Test
|
|
|
32 |
public void testFiltreMotClesCelAvecAccents() {
|
|
|
33 |
|
|
|
34 |
MotCle mc1 = new MotCle("1", "1", "écorce");
|
|
|
35 |
MotCle mc2 = new MotCle("2", "1", "pôrt");
|
|
|
36 |
MotCle mc3 = new MotCle("3", "1", "ucorce");
|
|
|
37 |
MotCle mc4 = new MotCle("4", "1", "Défi Photo");
|
|
|
38 |
MotCle mc5 = new MotCle("5", "1", "FeuIlle");
|
|
|
39 |
MotCle mc6 = new MotCle("6", "1", "fruIT");
|
|
|
40 |
|
|
|
41 |
motsCles.add(mc1);
|
|
|
42 |
motsCles.add(mc2);
|
|
|
43 |
motsCles.add(mc3);
|
|
|
44 |
motsCles.add(mc4);
|
|
|
45 |
motsCles.add(mc5);
|
|
|
46 |
motsCles.add(mc6);
|
|
|
47 |
|
|
|
48 |
List<String> resultat = afficherMotsClesCel(motsCles, motClesCelAFiltrer);
|
|
|
49 |
assertEquals(5, resultat.size());
|
|
|
50 |
}
|
|
|
51 |
|
|
|
52 |
@Test
|
|
|
53 |
public void testNormalisation() {
|
|
|
54 |
String avecEspaces = "mot cle espaces";
|
|
|
55 |
String sansEspaces = "motcleespaces";
|
|
|
56 |
|
|
|
57 |
assertEquals(StringUtils.normaliser(avecEspaces), StringUtils.normaliser(sansEspaces));
|
|
|
58 |
|
|
|
59 |
String avecAccents = "motcléaccentué";
|
|
|
60 |
String sansAccents = "motcleaccentue";
|
|
|
61 |
|
|
|
62 |
assertEquals(StringUtils.normaliser(avecAccents), StringUtils.normaliser(sansAccents));
|
|
|
63 |
|
|
|
64 |
String avecEspacesAccents = "mot clé èspâces";
|
|
|
65 |
String sansEspacesAccents = "motcleespaces";
|
|
|
66 |
|
|
|
67 |
assertEquals(StringUtils.normaliser(avecEspacesAccents), StringUtils.normaliser(sansEspacesAccents));
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
private List<String> afficherMotsClesCel(List<MotCle> motsClesCelImages, List<String> motsClesCelAFiltrer) {
|
|
|
71 |
List<String> motsClesCel = new ArrayList<String>();
|
|
|
72 |
|
|
|
73 |
for (Iterator<MotCle> iterator = motsClesCelImages.iterator(); iterator.hasNext();) {
|
|
|
74 |
String mot = iterator.next().getMotCle();
|
|
|
75 |
if(!mot.trim().isEmpty() && motsClesCelAFiltrer.contains(StringUtils.normaliser(mot))) {
|
|
|
76 |
motsClesCel.add(mot);
|
|
|
77 |
}
|
|
|
78 |
}
|
|
|
79 |
return motsClesCel;
|
|
|
80 |
}
|
|
|
81 |
}
|