Subversion Repositories eFlore/Applications.del

Rev

Rev 413 | Rev 446 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 413 Rev 445
Line 1... Line 1...
1
package org.tela_botanica.del.test.composants.pagination;
1
package org.tela_botanica.del.test.composants.pagination;
Line 2... Line 2...
2
 
2
 
3
import static org.junit.Assert.*;
3
import static org.junit.Assert.assertEquals;
Line 4... Line 4...
4
import static org.mockito.Mockito.when;
4
import static org.mockito.Mockito.when;
5
 
5
 
6
import org.junit.Before;
-
 
7
import org.junit.Test;
6
import org.junit.Before;
8
import org.mockito.Mock;
7
import org.junit.Test;
9
import org.mockito.Mockito;
8
import org.mockito.Mockito;
10
import org.mockito.invocation.InvocationOnMock;
9
import org.mockito.invocation.InvocationOnMock;
11
import org.mockito.stubbing.Answer;
10
import org.mockito.stubbing.Answer;
Line 28... Line 27...
28
	boolean boutonDernierePageEstAffiche;
27
	boolean boutonDernierePageEstAffiche;
Line 29... Line 28...
29
	
28
 
30
    @Before
29
	@Before
31
	public void setUp() {
30
	public void setUp() {
32
    	PaginationPresenteur.Vue vueBas = creerMockVuePaginationPresenteurBasique();
31
		PaginationPresenteur.Vue vueBas = creerMockVuePaginationPresenteurBasique();
33
		this.paginationBasPresenteur = new PaginationPresenteur(vueBas, 100, 10) {
32
		this.paginationBasPresenteur = new PaginationPresenteur(vueBas, 100, 10, 1) {
34
			@Override
33
			@Override
35
			public void changerPage(int debut, int fin) {
34
			public void chargerElements(int debut, int fin) {
36
				//TODO: tester avec des données factices, est-ce utile ici ?
35
				// TODO: tester avec des données factices, est-ce utile ici ?
Line 37... Line 36...
37
			}
36
			}
38
 
37
 
39
			@Override
38
			@Override
40
			public void actualiserPasCache(int pas) {
39
			public void actualiserPasCache(int pas) {
Line 41... Line -...
41
				CacheClient.getInstance().setPasPagination(pas);
-
 
42
			}
-
 
43
			
-
 
44
			@Override
-
 
45
			public void synchroniser() {
-
 
46
				paginationHautPresenteur.setPas(getPas());
-
 
47
				paginationHautPresenteur.setPageCourante(getPageCourante());
-
 
48
				paginationHautPresenteur.setNbPages(getNbPages());
40
				CacheClient.getInstance().setPasPagination(pas);
Line 49... Line 41...
49
				paginationHautPresenteur.actualiserLiens();
41
			}
50
			}
42
 
Line 51... Line 43...
51
		};
43
		};
52
				
44
 
Line 53... Line 45...
53
		PaginationPresenteur.Vue vueHaut = creerMockVuePaginationPresenteurBasique();
45
		PaginationPresenteur.Vue vueHaut = creerMockVuePaginationPresenteurBasique();
Line 54... Line 46...
54
		this.paginationHautPresenteur = new PaginationPresenteur(vueHaut,100, 10) {
46
		this.paginationHautPresenteur = new PaginationPresenteur(vueHaut, 100, 10, 1) {
55
 
47
 
Line 56... Line 48...
56
			@Override
48
			@Override
Line 57... Line -...
57
			public void changerPage(int debut, int fin) {
-
 
58
 
-
 
59
			}
-
 
60
 
-
 
61
			@Override
-
 
62
			public void actualiserPasCache(int pas) {
-
 
63
				
-
 
64
			}
49
			public void chargerElements(int debut, int fin) {
Line 65... Line 50...
65
 
50
 
66
			@Override
51
			}
67
			public void synchroniser() {
-
 
68
				paginationBasPresenteur.setPas(getPas());
-
 
69
				paginationBasPresenteur.setPageCourante(getPageCourante());
-
 
70
				paginationBasPresenteur.setNbPages(getNbPages());
52
 
71
				paginationBasPresenteur.actualiserLiens();
53
			@Override
-
 
54
			public void actualiserPasCache(int pas) {
Line 72... Line 55...
72
			}
55
 
73
		};
56
			}
74
		
-
 
75
		PaginationPresenteur.Vue vueSeule = creerMockVuePaginationPresenteurBasique();
57
 
Line 76... Line 58...
76
		this.paginationPresenteurSeul = new PaginationPresenteur(vueSeule, 100, 10) {
58
		};
77
			@Override
-
 
78
			public void changerPage(int debut, int fin) {}
-
 
79
 
-
 
80
			@Override
-
 
81
			public void actualiserPasCache(int pas) {}
-
 
82
			
-
 
83
			@Override
-
 
84
			public void synchroniser() {}
-
 
85
		};
-
 
86
	}
-
 
87
	
-
 
88
	@Test
-
 
89
	public void testSynchroWidgetPagination() {
-
 
90
	
-
 
91
		HasWidgets conteneur = Mockito.mock(HasWidgets.class);
-
 
92
		
-
 
93
		paginationBasPresenteur.go(conteneur);
-
 
94
		paginationHautPresenteur.go(conteneur);
-
 
95
 
-
 
96
		assertEquals(1, paginationHautPresenteur.getPageCourante());
-
 
97
		assertEquals(1, paginationBasPresenteur.getPageCourante());
-
 
98
		
-
 
99
		paginationHautPresenteur.changerPas(20);
-
 
100
		paginationHautPresenteur.synchroniser();
-
 
101
		assertEquals(20, paginationBasPresenteur.getPas());
-
 
102
		assertEquals(20, paginationHautPresenteur.getPas());
-
 
103
		
59
 
Line 104... Line 60...
104
		paginationBasPresenteur.setPageCourante(4);
60
		PaginationPresenteur.Vue vueSeule = creerMockVuePaginationPresenteurBasique();
105
		paginationBasPresenteur.changerPage(4*20,5*20);
61
		this.paginationPresenteurSeul = new PaginationPresenteur(vueSeule, 100, 10, 1) {
Line 106... Line 62...
106
		paginationBasPresenteur.synchroniser();
62
			@Override
Line 107... Line 63...
107
		
63
			public void chargerElements(int debut, int fin) {
-
 
64
			}
108
		assertEquals(4, paginationHautPresenteur.getPageCourante());
65
 
109
		
66
			@Override
110
		paginationBasPresenteur.changerPas(10);
67
			public void actualiserPasCache(int pas) {
-
 
68
			}
-
 
69
 
111
		paginationBasPresenteur.synchroniser();
70
		};
-
 
71
	}
112
		assertEquals(8, paginationHautPresenteur.getPageCourante());
72
 
-
 
73
	@Test
Line 113... Line 74...
113
		assertEquals(8, paginationBasPresenteur.getPageCourante());
74
	public void testAffichageBoutonPremiereDernierePage() {
114
		
75
 
-
 
76
		mockerMethodeAffichageBoutons(paginationPresenteurSeul.getVue());
-
 
77
 
115
	}
78
		// TODO: voir comment mocker ces méthodes avec Benjamin car le test ne
-
 
79
		// passe alors que
116
	
80
		// ça fonctionne en pratique
-
 
81
		paginationPresenteurSeul.afficherLaPremierePage();
Line 117... Line 82...
117
	@Test
82
		assertEquals(1, paginationPresenteurSeul.getPageCourante());
Line 118... Line 83...
118
	public void testAffichageBoutonPremiereDernierePage() {
83
		/*
Line 160... Line 125...
160
		
125
 
161
		Mockito.doAnswer(new Answer<Object>() {
126
		Mockito.doAnswer(new Answer<Object>() {
162
		      public Object answer(InvocationOnMock invocation) {
127
			public Object answer(InvocationOnMock invocation) {
163
		    	  boutonPremierePageEstAffiche = true;
128
				boutonPremierePageEstAffiche = true;
164
		          return boutonPremierePageEstAffiche;
129
				return boutonPremierePageEstAffiche;
165
		      }})
130
			}
Line 166... Line 131...
166
		  .when(vueMock).afficherBoutonPrecedent();
131
		}).when(vueMock).afficherBoutonPrecedent();
167
		
132
 
168
		Mockito.doAnswer(new Answer<Object>() {
133
		Mockito.doAnswer(new Answer<Object>() {
169
		      public Object answer(InvocationOnMock invocation) {
134
			public Object answer(InvocationOnMock invocation) {
170
		    	  boutonDernierePageEstAffiche = true;
135
				boutonDernierePageEstAffiche = true;
171
		          return boutonDernierePageEstAffiche;
136
				return boutonDernierePageEstAffiche;
Line 172... Line 137...
172
		      }})
137
			}
173
		  .when(vueMock).afficherBoutonSuivant();
138
		}).when(vueMock).afficherBoutonSuivant();
174
		
139
 
175
		Mockito.doAnswer(new Answer<Object>() {
140
		Mockito.doAnswer(new Answer<Object>() {
176
		      public Object answer(InvocationOnMock invocation) {
141
			public Object answer(InvocationOnMock invocation) {
177
		    	  boutonPremierePageEstAffiche = false;
142
				boutonPremierePageEstAffiche = false;
Line 178... Line 143...
178
		          return boutonPremierePageEstAffiche;
143
				return boutonPremierePageEstAffiche;
179
		      }})
144
			}
180
		  .when(vueMock).masquerBoutonPrecedent();
145
		}).when(vueMock).masquerBoutonPrecedent();
181
		
146
 
182
		Mockito.doAnswer(new Answer<Object>() {
147
		Mockito.doAnswer(new Answer<Object>() {
183
		      public Object answer(InvocationOnMock invocation) {
148
			public Object answer(InvocationOnMock invocation) {
184
		    	  boutonDernierePageEstAffiche = false;
149
				boutonDernierePageEstAffiche = false;
185
		          return boutonDernierePageEstAffiche;
150
				return boutonDernierePageEstAffiche;