Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 1164 → Rev 1165

/trunk/src/org/tela_botanica/del/test/composants/motsclesimage/MotsClesImageTest.java
New file
0,0 → 1,81
package org.tela_botanica.del.test.composants.motsclesimage;
 
import static org.junit.Assert.*;
 
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
 
import org.junit.Before;
import org.junit.Test;
import org.tela_botanica.del.client.modeles.MotCle;
import org.tela_botanica.del.client.utils.StringUtils;
 
public class MotsClesImageTest {
List<MotCle> motsCles;
List<String> motClesCelAFiltrer;
 
@Before
public void setUp() {
String chaineMotsClesCelAFiltrer = "fleur,feuille,ecorce,fruit,port,defiphoto";
this.motClesCelAFiltrer = new ArrayList<String>();
String[] tabMotsClesCelAFiltrer = chaineMotsClesCelAFiltrer.split(",");
for (int i = 0; i < tabMotsClesCelAFiltrer.length; i++) {
this.motClesCelAFiltrer.add(StringUtils.normaliser(tabMotsClesCelAFiltrer[i]));
}
motsCles = new ArrayList<MotCle>();
}
 
@Test
public void testFiltreMotClesCelAvecAccents() {
MotCle mc1 = new MotCle("1", "1", "écorce");
MotCle mc2 = new MotCle("2", "1", "pôrt");
MotCle mc3 = new MotCle("3", "1", "ucorce");
MotCle mc4 = new MotCle("4", "1", "Défi Photo");
MotCle mc5 = new MotCle("5", "1", "FeuIlle");
MotCle mc6 = new MotCle("6", "1", "fruIT");
motsCles.add(mc1);
motsCles.add(mc2);
motsCles.add(mc3);
motsCles.add(mc4);
motsCles.add(mc5);
motsCles.add(mc6);
List<String> resultat = afficherMotsClesCel(motsCles, motClesCelAFiltrer);
assertEquals(5, resultat.size());
}
@Test
public void testNormalisation() {
String avecEspaces = "mot cle espaces";
String sansEspaces = "motcleespaces";
 
assertEquals(StringUtils.normaliser(avecEspaces), StringUtils.normaliser(sansEspaces));
String avecAccents = "motcléaccentué";
String sansAccents = "motcleaccentue";
 
assertEquals(StringUtils.normaliser(avecAccents), StringUtils.normaliser(sansAccents));
String avecEspacesAccents = "mot clé èspâces";
String sansEspacesAccents = "motcleespaces";
 
assertEquals(StringUtils.normaliser(avecEspacesAccents), StringUtils.normaliser(sansEspacesAccents));
}
private List<String> afficherMotsClesCel(List<MotCle> motsClesCelImages, List<String> motsClesCelAFiltrer) {
List<String> motsClesCel = new ArrayList<String>();
for (Iterator<MotCle> iterator = motsClesCelImages.iterator(); iterator.hasNext();) {
String mot = iterator.next().getMotCle();
if(!mot.trim().isEmpty() && motsClesCelAFiltrer.contains(StringUtils.normaliser(mot))) {
motsClesCel.add(mot);
}
}
return motsClesCel;
}
}