Jean-Francois Leveque

Étape de couverture de PublisherVersionView.

1 package org.legrog.web.publisher; 1 package org.legrog.web.publisher;
2 2
3 -import org.junit.Before; 3 +import org.junit.jupiter.api.Nested;
4 -import org.junit.Test; 4 +import org.junit.jupiter.api.Test;
5 import org.junit.jupiter.api.BeforeEach; 5 import org.junit.jupiter.api.BeforeEach;
6 import org.junit.jupiter.api.DisplayName; 6 import org.junit.jupiter.api.DisplayName;
7 +import org.junit.jupiter.api.extension.ExtendWith;
8 +import org.junit.platform.runner.JUnitPlatform;
7 import org.junit.runner.RunWith; 9 import org.junit.runner.RunWith;
8 import org.legrog.entities.Country; 10 import org.legrog.entities.Country;
9 import org.legrog.entities.Publisher; 11 import org.legrog.entities.Publisher;
10 import org.legrog.entities.PublisherVersion; 12 import org.legrog.entities.PublisherVersion;
13 +import org.legrog.test.MockitoExtension;
11 import org.legrog.web.xyz.SharedService; 14 import org.legrog.web.xyz.SharedService;
12 import org.mockito.Answers; 15 import org.mockito.Answers;
13 import org.mockito.Mock; 16 import org.mockito.Mock;
...@@ -15,13 +18,16 @@ import org.mockito.runners.MockitoJUnitRunner; ...@@ -15,13 +18,16 @@ import org.mockito.runners.MockitoJUnitRunner;
15 import org.slf4j.Logger; 18 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory; 19 import org.slf4j.LoggerFactory;
17 20
21 +import java.util.List;
22 +
18 import static org.assertj.core.api.Assertions.assertThat; 23 import static org.assertj.core.api.Assertions.assertThat;
19 import static org.mockito.Mockito.when; 24 import static org.mockito.Mockito.when;
20 25
21 /** 26 /**
22 * Classe testant PublisherVersionView. 27 * Classe testant PublisherVersionView.
23 */ 28 */
24 -@RunWith(MockitoJUnitRunner.class) 29 +@RunWith(JUnitPlatform.class)
30 +@ExtendWith(MockitoExtension.class)
25 @DisplayName("Création et visualisation de version d'éditeur") 31 @DisplayName("Création et visualisation de version d'éditeur")
26 public class PublisherVersionViewTest { 32 public class PublisherVersionViewTest {
27 Logger logger = LoggerFactory.getLogger(getClass()); 33 Logger logger = LoggerFactory.getLogger(getClass());
...@@ -30,8 +36,10 @@ public class PublisherVersionViewTest { ...@@ -30,8 +36,10 @@ public class PublisherVersionViewTest {
30 36
31 private PublisherVersion publisherVersion; 37 private PublisherVersion publisherVersion;
32 38
33 - @Before 39 + // TODO tester add et update, mais je ne sais pas comment je suis censé faire
34 - public void setUp(@Mock PublisherService publisherService, @Mock SharedService sharedService) { 40 +
41 + @BeforeEach
42 + public void setUp(@Mock PublisherService publisherService, @Mock SharedService sharedService) throws Exception{
35 publisherVersionView = new PublisherVersionView(publisherService, sharedService); 43 publisherVersionView = new PublisherVersionView(publisherService, sharedService);
36 publisherVersionView.setEditMode(false); 44 publisherVersionView.setEditMode(false);
37 publisherVersionView.setNewPublisher(false); 45 publisherVersionView.setNewPublisher(false);
...@@ -51,11 +59,16 @@ public class PublisherVersionViewTest { ...@@ -51,11 +59,16 @@ public class PublisherVersionViewTest {
51 publisherVersion.setPublisherHistory("J"); 59 publisherVersion.setPublisherHistory("J");
52 publisherVersion.setPublisher(new Publisher()); 60 publisherVersion.setPublisher(new Publisher());
53 61
54 -// todo uncomment when need to use it (new mockito refuses unnecessary stubbing) 62 + when(publisherService.getPublisherVersion(1)).thenReturn(publisherVersion);
55 -// when(publisherService.getPublisherVersion(0)).thenReturn(publisherVersion);
56 63
57 } 64 }
58 65
66 + @Test
67 + @DisplayName("depends on Shared Service and User Service")
68 + public void testDependencies() {
69 + assertThat(publisherVersionView).isNotNull();
70 + }
71 +
59 @DisplayName("Passage en mode édition") 72 @DisplayName("Passage en mode édition")
60 @Test 73 @Test
61 public void testEdit() { 74 public void testEdit() {
...@@ -98,18 +111,46 @@ public class PublisherVersionViewTest { ...@@ -98,18 +111,46 @@ public class PublisherVersionViewTest {
98 assertThat(publisherVersionView.isEditMode()).isTrue(); 111 assertThat(publisherVersionView.isEditMode()).isTrue();
99 } 112 }
100 113
101 - // J'ai l'impression qu'on pourrait utiliser de l'imbrication ici
102 - /*
103 @DisplayName("Annulation de saisie de nouvelle version de saisie d'un éditeur existant") 114 @DisplayName("Annulation de saisie de nouvelle version de saisie d'un éditeur existant")
104 @Test 115 @Test
105 public void testCancelNewVersionOfPublisher() { 116 public void testCancelNewVersionOfPublisher() {
117 + publisherVersionView.setNewPublisher(false);
118 + publisherVersionView.setPublisherVersionId(1);
119 +
120 + publisherVersionView.setPublisherName("1");
121 + publisherVersionView.setPublisherStreetAddress("2");
122 + publisherVersionView.setPublisherPostalCode("3");
123 + publisherVersionView.setPublisherPostOfficeBoxNumber("4");
124 + publisherVersionView.setPublisherAddressRegion("5");
125 + publisherVersionView.setPublisherAddressLocality("6");
126 + publisherVersionView.setPublisherAddressCountry(new Country());
127 + publisherVersionView.setPublisherTelephone("7");
128 + publisherVersionView.setPublisherEmail("8");
129 + publisherVersionView.setPublisherURL("9");
130 + publisherVersionView.setPublisherActive(false);
131 + publisherVersionView.setPublisherHistory("10");
132 +
133 + publisherVersionView.cancel();
134 +
135 + assertThat(publisherVersionView.getPublisherName()).isEqualTo("A");
136 + assertThat(publisherVersionView.getPublisherStreetAddress()).isEqualTo("B");
137 + assertThat(publisherVersionView.getPublisherPostalCode()).isEqualTo("C");
138 + assertThat(publisherVersionView.getPublisherPostOfficeBoxNumber()).isEqualTo("D");
139 + assertThat(publisherVersionView.getPublisherAddressRegion()).isEqualTo("E");
140 + assertThat(publisherVersionView.getPublisherAddressLocality()).isEqualTo("F");
141 + assertThat(publisherVersionView.getPublisherTelephone()).isEqualTo("G");
142 + assertThat(publisherVersionView.getPublisherEmail()).isEqualTo("H");
143 + assertThat(publisherVersionView.getPublisherURL()).isEqualTo("I");
144 + assertThat(publisherVersionView.getPublisherHistory()).isEqualTo("J");
145 + assertThat(publisherVersionView.isEditMode()).isFalse();
146 +
147 + }
106 148
107 - }*/
108 -/*
109 @Test 149 @Test
110 @DisplayName("Test de la fonction de chargement des valeurs initiales pour leur affichage") 150 @DisplayName("Test de la fonction de chargement des valeurs initiales pour leur affichage")
111 public void testLoadData() { 151 public void testLoadData() {
112 - publisherVersionView.setPublisherVersionId(0); 152 + publisherVersionView.setNewPublisher(true);
153 + publisherVersionView.setPublisherVersionId(1);
113 publisherVersionView.loadData(); 154 publisherVersionView.loadData();
114 assertThat(publisherVersionView.getPublisherName()).isEqualTo("A"); 155 assertThat(publisherVersionView.getPublisherName()).isEqualTo("A");
115 assertThat(publisherVersionView.getPublisherStreetAddress()).isEqualTo("B"); 156 assertThat(publisherVersionView.getPublisherStreetAddress()).isEqualTo("B");
...@@ -124,5 +165,33 @@ public class PublisherVersionViewTest { ...@@ -124,5 +165,33 @@ public class PublisherVersionViewTest {
124 assertThat(publisherVersionView.getPublisherHistory()).isEqualTo("J"); 165 assertThat(publisherVersionView.getPublisherHistory()).isEqualTo("J");
125 assertThat(publisherVersionView.isNewPublisher()).isFalse(); 166 assertThat(publisherVersionView.isNewPublisher()).isFalse();
126 } 167 }
127 -*/ 168 +
169 + @Test
170 + @DisplayName("Test initialisation formulaire pour nouvel éditeur")
171 + public void testLoadDataEmpty() {
172 + publisherVersionView.setNewPublisher(false);
173 + publisherVersionView.setPublisherVersionId(0);
174 + publisherVersionView.loadData();
175 + assertThat(publisherVersionView.isNewPublisher()).isTrue();
176 + assertThat(publisherVersionView.isEditMode()).isTrue();
177 + }
178 +
179 + @Nested
180 + @DisplayName("post construct method")
181 + class init {
182 +
183 + private List<Country> countries;
184 +
185 + @BeforeEach
186 + public void setUp(@Mock SharedService sharedService) {
187 + when(sharedService.getAllCountries()).thenReturn(countries);
188 + }
189 +
190 + @Test
191 + @DisplayName("should set lists of available masks, user roles, and user properties from shared service")
192 + public void testList(@Mock SharedService sharedService) {
193 + publisherVersionView.init();
194 + assertThat(publisherVersionView.getAvailableCountries()).isEqualTo(countries);
195 + }
196 + }
128 } 197 }
...\ No newline at end of file ...\ No newline at end of file
......