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 {
PublisherVersion addNewPublisher(PublisherVersion publisherVersion);
void addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion);
PublisherVersion addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion);
void validatePublisherVersion(PublisherVersion publisherVersion);
......
......@@ -58,7 +58,7 @@ public class PublisherServiceSpring implements PublisherService {
return publisherVersion;
}
public void addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion) {
public PublisherVersion addVersionToPublisher(Publisher publisher, PublisherVersion publisherVersion) {
logger.trace("debut addVersionToPublisher, publisherVersion = {}", publisherVersion);
Set<PublisherVersion> publisherVersionSet = publisher.getVersions();
publisherVersionSet.add(publisherVersion);
......@@ -69,6 +69,7 @@ public class PublisherServiceSpring implements PublisherService {
this.savePublisherVersion(publisherVersion);
this.savePublisher(publisher);
logger.trace("fin addVersionToPublisher, publisherVersion = {}", publisherVersion);
return publisherVersion;
}
public void validatePublisherVersion(PublisherVersion publisherVersion) {
......
......@@ -159,7 +159,7 @@ public class PublisherVersionView implements Serializable {
PublisherVersion publisherVersion = getNewPublisherVersion();
logger.trace("milieu update, avant enregistrement, publisherVersion = {}", publisherVersion);
publisherService.addVersionToPublisher(publisher, publisherVersion);
publisherVersion = publisherService.addVersionToPublisher(publisher, publisherVersion);
publisherVersionId = publisherVersion.getPublisherVersionId();
......
......@@ -196,6 +196,77 @@ public class PublisherVersionViewTest {
}
}
@Nested
@DisplayName("Update method")
class updateTests {
@BeforeEach
public void given(@Mock Publisher publisherMock) {
publisherVersionView.setNewPublisher(false);
publisherVersionView.setPublisherName("1");
publisherVersionView.setPublisherStreetAddress("2");
publisherVersionView.setPublisherPostalCode("3");
publisherVersionView.setPublisherPostOfficeBoxNumber("4");
publisherVersionView.setPublisherAddressRegion("5");
publisherVersionView.setPublisherAddressLocality("6");
publisherVersionView.setPublisherAddressCountry(new Country());
publisherVersionView.setPublisherTelephone("7");
publisherVersionView.setPublisherEmail("8");
publisherVersionView.setPublisherURL("9");
publisherVersionView.setPublisherActive(true);
publisherVersionView.setPublisherHistory("10");
publisherVersionView.setPublisher(publisherMock);
}
@Nested
@DisplayName("given some input fields")
class given {
@Captor
ArgumentCaptor<PublisherVersion> publisherVersionArgumentCaptor;
@Captor
ArgumentCaptor<Publisher> publisherArgumentCaptor;
@BeforeEach
public void test(@Mock PublisherService publisherService, @Mock Publisher publisherMock, @Mock PublisherVersion publisherVersionMock) {
// mock de l'appel dans Immutables values
when(publisherService.getPublisherVersion(anyInt())).thenReturn(new PublisherVersion());
when(publisherService.addVersionToPublisher(any(Publisher.class), any(PublisherVersion.class))).thenReturn(publisherVersionMock);
when(publisherVersionMock.getPublisher()).thenReturn(publisherMock);
when(publisherVersionMock.getPublisherVersionId()).thenReturn(13);
publisherVersionView.update();
}
@DisplayName("doit ajouter une nouvelle version à un éditeur")
@Test
public void shouldAddNewVersion(@Mock PublisherService publisherService) {
Mockito.verify(publisherService).addVersionToPublisher(publisherArgumentCaptor.capture(), publisherVersionArgumentCaptor.capture());
PublisherVersion publisherVersion = publisherVersionArgumentCaptor.getValue();
assertThat(publisherVersion.getPublisherName()).isEqualTo("1");
}
@DisplayName("should put state in non edit mode")
@Test
public void shouldNonEdit() {
assertThat(publisherVersionView.isEditMode()).isFalse();
}
@DisplayName("should put state in non new publisher with new ids")
@Test
public void shouldNonNewPublisher(@Mock Publisher publisherMock) {
assertThat(publisherVersionView.isNewPublisher()).isFalse();
assertThat(publisherVersionView.getPublisher()).isEqualTo(publisherMock);
assertThat(publisherVersionView.getPublisherVersionId()).isEqualTo(13);
}
}
}
@Nested
@DisplayName("Add method")
......@@ -217,6 +288,7 @@ public class PublisherVersionViewTest {
publisherVersionView.setPublisherURL("I");
publisherVersionView.setPublisherActive(true);
publisherVersionView.setPublisherHistory("J");
// WHY, JR ?
publisherVersionView.setPublisher(publisherMock);
}
......