Couverture satisfaisante de ListPublisherVersionsView par tests
Showing
1 changed file
with
100 additions
and
0 deletions
1 | +package org.legrog.web.publisher; | ||
2 | + | ||
3 | +import org.junit.Before; | ||
4 | +import org.junit.Test; | ||
5 | +import org.junit.runner.RunWith; | ||
6 | +import org.junit.jupiter.api.DisplayName; | ||
7 | +import org.legrog.entities.Publisher; | ||
8 | +import org.legrog.entities.PublisherVersion; | ||
9 | +import org.mockito.Answers; | ||
10 | +import org.mockito.Mock; | ||
11 | +import org.mockito.Mockito; | ||
12 | +import org.mockito.runners.MockitoJUnitRunner; | ||
13 | +import org.slf4j.Logger; | ||
14 | +import org.slf4j.LoggerFactory; | ||
15 | + | ||
16 | +import java.util.ArrayList; | ||
17 | +import java.util.List; | ||
18 | + | ||
19 | +import static org.assertj.core.api.Assertions.assertThat; | ||
20 | +import static org.mockito.Mockito.*; | ||
21 | + | ||
22 | +/** | ||
23 | + * Classe testant ListPublisherVersionsView. | ||
24 | + */ | ||
25 | +@RunWith(MockitoJUnitRunner.class) | ||
26 | +@DisplayName("Listes de versions d'éditeurs") | ||
27 | +public class ListPublisherVersionsViewTest { | ||
28 | + Logger logger = LoggerFactory.getLogger(getClass()); | ||
29 | + | ||
30 | + private ListPublisherVersionsView listPublisherVersionsView; | ||
31 | + private List<PublisherVersion> publisherVersions; | ||
32 | + private PublisherVersion publisherVersion; | ||
33 | + private PublisherVersion publisherVersion1; | ||
34 | + private PublisherVersion publisherVersion2; | ||
35 | + | ||
36 | + @Mock(answer = Answers.RETURNS_DEEP_STUBS) | ||
37 | + private PublisherService publisherService; | ||
38 | + | ||
39 | + @Before | ||
40 | + public void setUp() { | ||
41 | + listPublisherVersionsView = new ListPublisherVersionsView(); | ||
42 | + | ||
43 | + // Données | ||
44 | + publisherVersion = new PublisherVersion(); | ||
45 | + publisherVersion1 = new PublisherVersion(); | ||
46 | + publisherVersion2 = new PublisherVersion(); | ||
47 | + publisherVersion.setPublisherVersionId(0); | ||
48 | + publisherVersion1.setPublisherVersionId(1); | ||
49 | + publisherVersion2.setPublisherVersionId(2); | ||
50 | + Publisher publisher = new Publisher(); | ||
51 | + Publisher publisher1 = new Publisher(); | ||
52 | + publisher.setPublisherId(0); | ||
53 | + publisher1.setPublisherId(1); | ||
54 | + logger.trace("publisher {}", publisher); | ||
55 | + logger.trace("publisher1 {}", publisher1); | ||
56 | + publisherVersion.setPublisher(publisher); | ||
57 | + publisherVersion1.setPublisher(publisher1); | ||
58 | + publisherVersion2.setPublisher(publisher); | ||
59 | + publisher.setValidatedVersion(publisherVersion); | ||
60 | + logger.trace("publisherVersion {}", publisherVersion); | ||
61 | + logger.trace("publisherVersion1 {}", publisherVersion1); | ||
62 | + publisherVersions = new ArrayList<PublisherVersion>(); | ||
63 | + publisherVersions.add(publisherVersion); | ||
64 | + publisherVersions.add(publisherVersion1); | ||
65 | + | ||
66 | + // Mock | ||
67 | + when(publisherService.getAllPublisherVersions()).thenReturn(publisherVersions); | ||
68 | + listPublisherVersionsView.setPublisherService(publisherService); | ||
69 | + logger.trace("listPublisherVersionsView : {}", listPublisherVersionsView); | ||
70 | + logger.trace("listPublisherVersionsView, publisherVersions : {}", publisherVersions); | ||
71 | + } | ||
72 | + | ||
73 | + @Test | ||
74 | + @DisplayName("Liste complète") | ||
75 | + public void testSetViewAll() { | ||
76 | + listPublisherVersionsView.setPublisherId(null); | ||
77 | + listPublisherVersionsView.setView(); | ||
78 | + Mockito.verify(publisherService).getAllPublisherVersions(); | ||
79 | + assertThat(listPublisherVersionsView.isViewAll()).isTrue(); | ||
80 | + assertThat(listPublisherVersionsView.getPublisherVersions()).isEqualTo(this.publisherVersions); | ||
81 | + } | ||
82 | + | ||
83 | + @Test | ||
84 | + @DisplayName("Liste pour un éditeur") | ||
85 | + public void testSetViewNotAllAlsoTestingFilterOnId() { | ||
86 | + listPublisherVersionsView.setPublisherId(new Integer(1)); | ||
87 | + listPublisherVersionsView.setView(); | ||
88 | + Mockito.verify(publisherService).getAllPublisherVersions(); | ||
89 | + assertThat(listPublisherVersionsView.isViewAll()).isFalse(); | ||
90 | + assertThat(listPublisherVersionsView.getPublisherVersions()).containsExactly(this.publisherVersion1); | ||
91 | + } | ||
92 | + | ||
93 | + @Test | ||
94 | + @DisplayName("Test de l'appel de validation") | ||
95 | + public void testValidate() { | ||
96 | + listPublisherVersionsView.setPublisherId(new Integer(0)); | ||
97 | + listPublisherVersionsView.validate(publisherVersion2); | ||
98 | + Mockito.verify(publisherService).validatePublisherVersion(publisherVersion2); | ||
99 | + } | ||
100 | +} | ||
... | \ No newline at end of file | ... | \ No newline at end of file |
-
Please register or login to post a comment