Jean-Francois Leveque

Modification de addVersionToPublisher sur le modèle de addNewPublisher, par imitation.

Création de tests par imitation.
...@@ -14,7 +14,7 @@ public interface PublisherService { ...@@ -14,7 +14,7 @@ public interface PublisherService {
14 14
15 PublisherVersion addNewPublisher(PublisherVersion publisherVersion); 15 PublisherVersion addNewPublisher(PublisherVersion publisherVersion);
16 16
17 - void addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion); 17 + PublisherVersion addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion);
18 18
19 void validatePublisherVersion(PublisherVersion publisherVersion); 19 void validatePublisherVersion(PublisherVersion publisherVersion);
20 20
......
...@@ -58,7 +58,7 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -58,7 +58,7 @@ public class PublisherServiceSpring implements PublisherService {
58 return publisherVersion; 58 return publisherVersion;
59 } 59 }
60 60
61 - public void addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion) { 61 + public PublisherVersion addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion) {
62 logger.trace("debut addVersionToPublisher, publisherVersion = {}", publisherVersion); 62 logger.trace("debut addVersionToPublisher, publisherVersion = {}", publisherVersion);
63 Set<PublisherVersion> publisherVersionSet = publisher.getVersions(); 63 Set<PublisherVersion> publisherVersionSet = publisher.getVersions();
64 publisherVersionSet.add(publisherVersion); 64 publisherVersionSet.add(publisherVersion);
...@@ -69,6 +69,7 @@ public class PublisherServiceSpring implements PublisherService { ...@@ -69,6 +69,7 @@ public class PublisherServiceSpring implements PublisherService {
69 this.savePublisherVersion(publisherVersion); 69 this.savePublisherVersion(publisherVersion);
70 this.savePublisher(publisher); 70 this.savePublisher(publisher);
71 logger.trace("fin addVersionToPublisher, publisherVersion = {}", publisherVersion); 71 logger.trace("fin addVersionToPublisher, publisherVersion = {}", publisherVersion);
72 + return publisherVersion;
72 } 73 }
73 74
74 public void validatePublisherVersion(PublisherVersion publisherVersion) { 75 public void validatePublisherVersion(PublisherVersion publisherVersion) {
......
...@@ -159,7 +159,7 @@ public class PublisherVersionView implements Serializable { ...@@ -159,7 +159,7 @@ public class PublisherVersionView implements Serializable {
159 PublisherVersion publisherVersion = getNewPublisherVersion(); 159 PublisherVersion publisherVersion = getNewPublisherVersion();
160 160
161 logger.trace("milieu update, avant enregistrement, publisherVersion = {}", publisherVersion); 161 logger.trace("milieu update, avant enregistrement, publisherVersion = {}", publisherVersion);
162 - publisherService.addVersionToPublisher(publisher, publisherVersion); 162 + publisherVersion = publisherService.addVersionToPublisher(publisher, publisherVersion);
163 163
164 publisherVersionId = publisherVersion.getPublisherVersionId(); 164 publisherVersionId = publisherVersion.getPublisherVersionId();
165 165
......
...@@ -196,6 +196,77 @@ public class PublisherVersionViewTest { ...@@ -196,6 +196,77 @@ public class PublisherVersionViewTest {
196 } 196 }
197 } 197 }
198 198
199 + @Nested
200 + @DisplayName("Update method")
201 + class updateTests {
202 +
203 + @BeforeEach
204 + public void given(@Mock Publisher publisherMock) {
205 + publisherVersionView.setNewPublisher(false);
206 +
207 + publisherVersionView.setPublisherName("1");
208 + publisherVersionView.setPublisherStreetAddress("2");
209 + publisherVersionView.setPublisherPostalCode("3");
210 + publisherVersionView.setPublisherPostOfficeBoxNumber("4");
211 + publisherVersionView.setPublisherAddressRegion("5");
212 + publisherVersionView.setPublisherAddressLocality("6");
213 + publisherVersionView.setPublisherAddressCountry(new Country());
214 + publisherVersionView.setPublisherTelephone("7");
215 + publisherVersionView.setPublisherEmail("8");
216 + publisherVersionView.setPublisherURL("9");
217 + publisherVersionView.setPublisherActive(true);
218 + publisherVersionView.setPublisherHistory("10");
219 + publisherVersionView.setPublisher(publisherMock);
220 + }
221 +
222 + @Nested
223 + @DisplayName("given some input fields")
224 + class given {
225 +
226 + @Captor
227 + ArgumentCaptor<PublisherVersion> publisherVersionArgumentCaptor;
228 +
229 + @Captor
230 + ArgumentCaptor<Publisher> publisherArgumentCaptor;
231 +
232 + @BeforeEach
233 + public void test(@Mock PublisherService publisherService, @Mock Publisher publisherMock, @Mock PublisherVersion publisherVersionMock) {
234 + // mock de l'appel dans Immutables values
235 + when(publisherService.getPublisherVersion(anyInt())).thenReturn(new PublisherVersion());
236 +
237 + when(publisherService.addVersionToPublisher(any(Publisher.class), any(PublisherVersion.class))).thenReturn(publisherVersionMock);
238 + when(publisherVersionMock.getPublisher()).thenReturn(publisherMock);
239 + when(publisherVersionMock.getPublisherVersionId()).thenReturn(13);
240 +
241 + publisherVersionView.update();
242 + }
243 +
244 + @DisplayName("doit ajouter une nouvelle version à un éditeur")
245 + @Test
246 + public void shouldAddNewVersion(@Mock PublisherService publisherService) {
247 + Mockito.verify(publisherService).addVersionToPublisher(publisherArgumentCaptor.capture(), publisherVersionArgumentCaptor.capture());
248 + PublisherVersion publisherVersion = publisherVersionArgumentCaptor.getValue();
249 + assertThat(publisherVersion.getPublisherName()).isEqualTo("1");
250 + }
251 +
252 + @DisplayName("should put state in non edit mode")
253 + @Test
254 + public void shouldNonEdit() {
255 + assertThat(publisherVersionView.isEditMode()).isFalse();
256 + }
257 +
258 + @DisplayName("should put state in non new publisher with new ids")
259 + @Test
260 + public void shouldNonNewPublisher(@Mock Publisher publisherMock) {
261 +
262 + assertThat(publisherVersionView.isNewPublisher()).isFalse();
263 + assertThat(publisherVersionView.getPublisher()).isEqualTo(publisherMock);
264 + assertThat(publisherVersionView.getPublisherVersionId()).isEqualTo(13);
265 + }
266 +
267 + }
268 +
269 + }
199 270
200 @Nested 271 @Nested
201 @DisplayName("Add method") 272 @DisplayName("Add method")
...@@ -217,6 +288,7 @@ public class PublisherVersionViewTest { ...@@ -217,6 +288,7 @@ public class PublisherVersionViewTest {
217 publisherVersionView.setPublisherURL("I"); 288 publisherVersionView.setPublisherURL("I");
218 publisherVersionView.setPublisherActive(true); 289 publisherVersionView.setPublisherActive(true);
219 publisherVersionView.setPublisherHistory("J"); 290 publisherVersionView.setPublisherHistory("J");
291 + // WHY, JR ?
220 publisherVersionView.setPublisher(publisherMock); 292 publisherVersionView.setPublisher(publisherMock);
221 } 293 }
222 294
......