Test de la méthode derrière le bouton save et simplification code de test.
Showing
1 changed file
with
43 additions
and
14 deletions
... | @@ -83,19 +83,6 @@ public class PublisherVersionViewTest { | ... | @@ -83,19 +83,6 @@ public class PublisherVersionViewTest { |
83 | public void testCancelNewPublisher() { | 83 | public void testCancelNewPublisher() { |
84 | publisherVersionView.setNewPublisher(true); | 84 | publisherVersionView.setNewPublisher(true); |
85 | 85 | ||
86 | - publisherVersionView.setPublisherName("A"); | ||
87 | - publisherVersionView.setPublisherStreetAddress("B"); | ||
88 | - publisherVersionView.setPublisherPostalCode("C"); | ||
89 | - publisherVersionView.setPublisherPostOfficeBoxNumber("D"); | ||
90 | - publisherVersionView.setPublisherAddressRegion("E"); | ||
91 | - publisherVersionView.setPublisherAddressLocality("F"); | ||
92 | - publisherVersionView.setPublisherAddressCountry(new Country()); | ||
93 | - publisherVersionView.setPublisherTelephone("G"); | ||
94 | - publisherVersionView.setPublisherEmail("H"); | ||
95 | - publisherVersionView.setPublisherURL("I"); | ||
96 | - publisherVersionView.setPublisherActive(true); | ||
97 | - publisherVersionView.setPublisherHistory("J"); | ||
98 | - | ||
99 | publisherVersionView.cancel(); | 86 | publisherVersionView.cancel(); |
100 | 87 | ||
101 | assertThat(publisherVersionView.getPublisherName()).isNull(); | 88 | assertThat(publisherVersionView.getPublisherName()).isNull(); |
... | @@ -178,6 +165,49 @@ public class PublisherVersionViewTest { | ... | @@ -178,6 +165,49 @@ public class PublisherVersionViewTest { |
178 | } | 165 | } |
179 | 166 | ||
180 | @Nested | 167 | @Nested |
168 | + @DisplayName("save method") | ||
169 | + class saveTests{ | ||
170 | + PublisherVersionView publisherVersionViewForSave; | ||
171 | + public boolean addCalled = false; | ||
172 | + public boolean updateCalled = false; | ||
173 | + | ||
174 | + @BeforeEach | ||
175 | + @DisplayName("Given some test reimplementation") | ||
176 | + public void given() { | ||
177 | + publisherVersionViewForSave = new PublisherVersionView() { | ||
178 | + | ||
179 | + @Override | ||
180 | + public void add() { | ||
181 | + addCalled = true; | ||
182 | + } | ||
183 | + | ||
184 | + @Override | ||
185 | + public void update() { | ||
186 | + updateCalled = true; | ||
187 | + } | ||
188 | + | ||
189 | + }; | ||
190 | + } | ||
191 | + | ||
192 | + @Test | ||
193 | + @DisplayName("Test should call add on new publisher") | ||
194 | + public void testSaveAdd() { | ||
195 | + publisherVersionViewForSave.setNewPublisher(true); | ||
196 | + publisherVersionViewForSave.save(); | ||
197 | + assertThat(addCalled).isTrue(); | ||
198 | + } | ||
199 | + | ||
200 | + @Test | ||
201 | + @DisplayName("Test should call update on old publisher") | ||
202 | + public void testSaveUpdate() { | ||
203 | + publisherVersionViewForSave.setNewPublisher(false); | ||
204 | + publisherVersionViewForSave.save(); | ||
205 | + assertThat(updateCalled).isTrue(); | ||
206 | + } | ||
207 | + | ||
208 | + } | ||
209 | + | ||
210 | + @Nested | ||
181 | @DisplayName("post construct method") | 211 | @DisplayName("post construct method") |
182 | class init { | 212 | class init { |
183 | 213 | ||
... | @@ -288,7 +318,6 @@ public class PublisherVersionViewTest { | ... | @@ -288,7 +318,6 @@ public class PublisherVersionViewTest { |
288 | publisherVersionView.setPublisherURL("I"); | 318 | publisherVersionView.setPublisherURL("I"); |
289 | publisherVersionView.setPublisherActive(true); | 319 | publisherVersionView.setPublisherActive(true); |
290 | publisherVersionView.setPublisherHistory("J"); | 320 | publisherVersionView.setPublisherHistory("J"); |
291 | - // WHY, JR ? | ||
292 | publisherVersionView.setPublisher(publisherMock); | 321 | publisherVersionView.setPublisher(publisherMock); |
293 | } | 322 | } |
294 | 323 | ... | ... |
-
Please register or login to post a comment