Jean-Francois Leveque

sonarQube : Test de vouverture de l'Exception inattendue.

...@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory; ...@@ -20,6 +20,7 @@ import org.slf4j.LoggerFactory;
20 import java.util.List; 20 import java.util.List;
21 21
22 import static org.assertj.core.api.Assertions.assertThat; 22 import static org.assertj.core.api.Assertions.assertThat;
23 +import static org.junit.jupiter.api.Assertions.assertThrows;
23 import static org.mockito.ArgumentMatchers.any; 24 import static org.mockito.ArgumentMatchers.any;
24 import static org.mockito.ArgumentMatchers.anyInt; 25 import static org.mockito.ArgumentMatchers.anyInt;
25 import static org.mockito.Mockito.when; 26 import static org.mockito.Mockito.when;
...@@ -37,7 +38,8 @@ public class PublisherVersionViewTest { ...@@ -37,7 +38,8 @@ public class PublisherVersionViewTest {
37 38
38 private PublisherVersion publisherVersion; 39 private PublisherVersion publisherVersion;
39 40
40 - // TODO tester add et update, mais je ne sais pas comment je suis censé faire 41 + @Mock
42 + PublisherVersion publisherVersionMock;
41 43
42 @BeforeEach 44 @BeforeEach
43 public void setUp(@Mock PublisherService publisherService, @Mock SharedService sharedService) throws Exception { 45 public void setUp(@Mock PublisherService publisherService, @Mock SharedService sharedService) throws Exception {
...@@ -179,6 +181,23 @@ public class PublisherVersionViewTest { ...@@ -179,6 +181,23 @@ public class PublisherVersionViewTest {
179 } 181 }
180 182
181 @Nested 183 @Nested
184 + @DisplayName("getImmutableValues method")
185 + class getImmutableValuesTests{
186 + @BeforeEach
187 + @DisplayName("given a way to get a null")
188 + public void given(@Mock PublisherService publisherService) {
189 + when(publisherService.addNewPublisher(any())).thenReturn(publisherVersionMock);
190 + when(publisherVersionMock.getPublisherVersionId()).thenReturn(2);
191 + when(publisherService.getPublisherVersion(2)).thenReturn(null);
192 + }
193 + @Test
194 + @DisplayName("throws an IllegalStateException")
195 + public void testUnexcpetedNull() {
196 + assertThrows(IllegalStateException.class, () -> publisherVersionView.add());
197 + }
198 + }
199 +
200 + @Nested
182 @DisplayName("save method") 201 @DisplayName("save method")
183 class saveTests{ 202 class saveTests{
184 PublisherVersionView publisherVersionViewForSave; 203 PublisherVersionView publisherVersionViewForSave;
......