271 |
aurelien |
1 |
package org.tela_botanica.del.test.modeles;
|
|
|
2 |
|
|
|
3 |
import static org.junit.Assert.*;
|
|
|
4 |
|
|
|
5 |
import java.util.ArrayList;
|
|
|
6 |
import java.util.Date;
|
|
|
7 |
import java.util.HashMap;
|
|
|
8 |
import java.util.Map;
|
|
|
9 |
|
|
|
10 |
import org.junit.Before;
|
|
|
11 |
import org.junit.Test;
|
|
|
12 |
import org.tela_botanica.del.client.modeles.Commentaire;
|
|
|
13 |
import org.tela_botanica.del.client.modeles.PropositionDetermination;
|
|
|
14 |
import org.tela_botanica.del.client.modeles.VoteDetermination;
|
|
|
15 |
|
|
|
16 |
|
|
|
17 |
public class PropositionDeterminationTest {
|
|
|
18 |
|
|
|
19 |
PropositionDetermination propositionDetermination;
|
|
|
20 |
VoteDetermination voteDetermination1;
|
|
|
21 |
Commentaire commentaireInitial;
|
|
|
22 |
Date dateInitiale;
|
|
|
23 |
ArrayList<Commentaire> commentairesInitiaux = new ArrayList<Commentaire>();
|
|
|
24 |
Map<String, VoteDetermination> votesDeterminationsInitiaux = new HashMap<String, VoteDetermination>();
|
|
|
25 |
|
|
|
26 |
@Before
|
|
|
27 |
public void setUp() {
|
|
|
28 |
propositionDetermination = new PropositionDetermination();
|
|
|
29 |
propositionDetermination.setContributeur("Aurélien");
|
|
|
30 |
propositionDetermination.setId("5");
|
|
|
31 |
dateInitiale = new Date();
|
|
|
32 |
propositionDetermination.setDate(dateInitiale);
|
|
|
33 |
commentaireInitial = new Commentaire("Aurélien", new Date(), "Oui c'est interessant");
|
|
|
34 |
commentairesInitiaux.add(commentaireInitial);
|
307 |
aurelien |
35 |
propositionDetermination.setListeCommentaires(commentairesInitiaux);
|
271 |
aurelien |
36 |
propositionDetermination.setEspece("Acer monsp. L.");
|
|
|
37 |
|
|
|
38 |
voteDetermination1 = new VoteDetermination();
|
|
|
39 |
voteDetermination1.setVote(1);
|
|
|
40 |
voteDetermination1.setDate(new Date());
|
|
|
41 |
voteDetermination1.setContributeur("benjamin");
|
|
|
42 |
votesDeterminationsInitiaux.put("benjamin", voteDetermination1);
|
|
|
43 |
propositionDetermination.setVotesDeterminations(votesDeterminationsInitiaux);
|
|
|
44 |
}
|
|
|
45 |
|
|
|
46 |
@Test
|
|
|
47 |
public void testAjouterVoteDetermination() {
|
|
|
48 |
|
|
|
49 |
assertEquals(1, propositionDetermination.getVotesDeterminations().size());
|
|
|
50 |
|
|
|
51 |
VoteDetermination voteDeterminationTest = new VoteDetermination();
|
|
|
52 |
voteDeterminationTest.setVote(1);
|
|
|
53 |
voteDeterminationTest.setDate(new Date());
|
|
|
54 |
voteDeterminationTest.setContributeur("gregoire");
|
|
|
55 |
propositionDetermination.ajouterVoteDetermination(voteDeterminationTest);
|
|
|
56 |
assertEquals(2, propositionDetermination.getVotesDeterminations().size());
|
|
|
57 |
|
|
|
58 |
VoteDetermination voteDeterminationTest2 = new VoteDetermination();
|
|
|
59 |
voteDeterminationTest2.setVote(0);
|
|
|
60 |
voteDeterminationTest2.setDate(new Date());
|
|
|
61 |
voteDeterminationTest2.setContributeur("gregoire");
|
|
|
62 |
propositionDetermination.ajouterVoteDetermination(voteDeterminationTest2);
|
|
|
63 |
|
|
|
64 |
// la taille ne doit pas avoir changé après l'ajout du vote de Grégoire car le contributeur
|
|
|
65 |
// est la clé la map (i.e. 1 vote par personne pour une determination)
|
|
|
66 |
assertEquals(2, propositionDetermination.getVotesDeterminations().size());
|
|
|
67 |
assertEquals(0, propositionDetermination.getVotesDeterminations().get("gregoire").getVote());
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
@Test
|
|
|
71 |
public void testGetContributeur() {
|
|
|
72 |
assertEquals("Aurélien", propositionDetermination.getContributeur());
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
@Test
|
|
|
76 |
public void testSetContributeur() {
|
|
|
77 |
propositionDetermination.setContributeur("Grégoire");
|
|
|
78 |
assertEquals("Grégoire", propositionDetermination.getContributeur());
|
|
|
79 |
}
|
|
|
80 |
|
|
|
81 |
@Test
|
|
|
82 |
public void testGetId() {
|
|
|
83 |
assertEquals("5", propositionDetermination.getId());
|
|
|
84 |
}
|
|
|
85 |
|
|
|
86 |
@Test
|
|
|
87 |
public void testSetId() {
|
|
|
88 |
propositionDetermination.setId("325");
|
|
|
89 |
assertEquals("325", propositionDetermination.getId());
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
@Test
|
|
|
93 |
public void testGetDate() {
|
|
|
94 |
assertEquals(dateInitiale, propositionDetermination.getDate());
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
@Test
|
|
|
98 |
public void testSetDate() {
|
|
|
99 |
Date dateTest = new Date();
|
|
|
100 |
propositionDetermination.setDate(dateTest);
|
|
|
101 |
assertEquals(dateTest, propositionDetermination.getDate());
|
|
|
102 |
}
|
|
|
103 |
|
|
|
104 |
@Test
|
|
|
105 |
public void testGetCommentaires() {
|
307 |
aurelien |
106 |
assertEquals(1, propositionDetermination.getListeCommentaires().size());
|
|
|
107 |
assertEquals("Aurélien", propositionDetermination.getListeCommentaires().get(0).getAuteur());
|
271 |
aurelien |
108 |
}
|
|
|
109 |
|
|
|
110 |
@Test
|
|
|
111 |
public void testSetCommentaires() {
|
|
|
112 |
ArrayList<Commentaire> listeVide = new ArrayList<Commentaire>();
|
307 |
aurelien |
113 |
propositionDetermination.setListeCommentaires(listeVide);
|
|
|
114 |
assertEquals(0, propositionDetermination.getListeCommentaires().size());
|
271 |
aurelien |
115 |
}
|
|
|
116 |
|
|
|
117 |
@Test
|
|
|
118 |
public void testAjouterCommentaire() {
|
307 |
aurelien |
119 |
propositionDetermination.setListeCommentaires(commentairesInitiaux);
|
|
|
120 |
assertEquals(1, propositionDetermination.getListeCommentaires().size());
|
271 |
aurelien |
121 |
Commentaire nouveauCommentaire = new Commentaire("Grégoire", new Date(), "Rochonner c'est bien !");
|
|
|
122 |
propositionDetermination.ajouterCommentaire(nouveauCommentaire);
|
307 |
aurelien |
123 |
assertEquals(2, propositionDetermination.getListeCommentaires().size());
|
|
|
124 |
assertEquals("Grégoire", propositionDetermination.getListeCommentaires().get(1).getAuteur());
|
271 |
aurelien |
125 |
}
|
|
|
126 |
|
|
|
127 |
@Test
|
|
|
128 |
public void testGetEspece() {
|
|
|
129 |
assertEquals("Acer monsp. L.", propositionDetermination.getEspece());
|
|
|
130 |
}
|
|
|
131 |
|
|
|
132 |
@Test
|
|
|
133 |
public void testSetEspece() {
|
|
|
134 |
propositionDetermination.setEspece("Acer monsp. subsp. monsp.");
|
|
|
135 |
assertEquals("Acer monsp. subsp. monsp.", propositionDetermination.getEspece());
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
@Test
|
|
|
139 |
public void testGetVotesDeterminations() {
|
|
|
140 |
assertEquals(1, propositionDetermination.getVotesDeterminations().size());
|
|
|
141 |
assertEquals(voteDetermination1, propositionDetermination.getVotesDeterminations().get("benjamin"));
|
|
|
142 |
}
|
|
|
143 |
|
|
|
144 |
@Test
|
|
|
145 |
public void testSetVotesDeterminations() {
|
|
|
146 |
HashMap<String, VoteDetermination> votesDeterminationVides = new HashMap<String, VoteDetermination>();
|
|
|
147 |
propositionDetermination.setVotesDeterminations(votesDeterminationVides);
|
|
|
148 |
assertEquals(0,propositionDetermination.getVotesDeterminations().size());
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
}
|