Showing
1 changed file
with
95 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.jupiter.api.BeforeEach; | ||
6 | +import org.junit.jupiter.api.DisplayName; | ||
7 | +import org.junit.jupiter.api.Nested; | ||
8 | +import org.junit.jupiter.api.extension.ExtendWith; | ||
9 | +import org.junit.platform.runner.JUnitPlatform; | ||
10 | +import org.junit.runner.RunWith; | ||
11 | +import org.legrog.entities.Publisher; | ||
12 | +import org.legrog.entities.PublisherAction; | ||
13 | +import org.legrog.test.MockitoExtension; | ||
14 | +import org.mockito.Mock; | ||
15 | +import org.mockito.Mockito; | ||
16 | + | ||
17 | +import javax.inject.Inject; | ||
18 | + | ||
19 | +import java.util.ArrayList; | ||
20 | +import java.util.List; | ||
21 | + | ||
22 | +import static org.assertj.core.api.Assertions.assertThat; | ||
23 | + | ||
24 | +/** | ||
25 | + * Classe testant ListPublisherActionsView. | ||
26 | + */ | ||
27 | +@RunWith(JUnitPlatform.class) | ||
28 | +@ExtendWith(MockitoExtension.class) | ||
29 | +@DisplayName("Visualisation d'actions sur éditeur") | ||
30 | +public class ListPublisherActionsViewTest { | ||
31 | + ListPublisherActionsView listPublisherActionsView; | ||
32 | + | ||
33 | + @Nested | ||
34 | + @DisplayName("setView method") | ||
35 | + public class testSetView { | ||
36 | + boolean filtered; | ||
37 | + | ||
38 | + @BeforeEach | ||
39 | + public void setUp(@Mock PublisherService publisherServiceMock){ | ||
40 | + filtered = false; | ||
41 | + listPublisherActionsView = new ListPublisherActionsView(publisherServiceMock) { | ||
42 | + @Override | ||
43 | + public void filterOnID() { | ||
44 | + filtered = true; | ||
45 | + } | ||
46 | + }; | ||
47 | + } | ||
48 | + | ||
49 | + @Test | ||
50 | + @DisplayName("should show all") | ||
51 | + public void showAll(@Mock PublisherService publisherServiceMock) { | ||
52 | + listPublisherActionsView.setPublisherId(null); | ||
53 | + listPublisherActionsView.setViewAll(false); | ||
54 | + listPublisherActionsView.setView(); | ||
55 | + Mockito.verify(publisherServiceMock).getAllPublisherActions(); | ||
56 | + assertThat(listPublisherActionsView.isViewAll()).isTrue(); | ||
57 | + assertThat(filtered).isFalse(); | ||
58 | + } | ||
59 | + | ||
60 | + @Test | ||
61 | + @DisplayName("should show filtered") | ||
62 | + public void showFiltered(@Mock PublisherService publisherServiceMock) { | ||
63 | + listPublisherActionsView.setPublisherId(1); | ||
64 | + listPublisherActionsView.setViewAll(true); | ||
65 | + listPublisherActionsView.setView(); | ||
66 | + Mockito.verify(publisherServiceMock).getAllPublisherActions(); | ||
67 | + assertThat(listPublisherActionsView.isViewAll()).isFalse(); | ||
68 | + assertThat(filtered).isTrue(); | ||
69 | + } | ||
70 | + } | ||
71 | + | ||
72 | + @Test | ||
73 | + @DisplayName("filterId should filter") | ||
74 | + public void testFilter(@Mock PublisherService publisherServiceMock) { | ||
75 | + List<PublisherAction> publisherActions = new ArrayList<PublisherAction>(); | ||
76 | + | ||
77 | + Publisher publisher = new Publisher(); | ||
78 | + Publisher publisher1 = new Publisher(); | ||
79 | + PublisherAction publisherAction = new PublisherAction(); | ||
80 | + PublisherAction publisherAction1 = new PublisherAction(); | ||
81 | + | ||
82 | + publisher.setPublisherId(0); | ||
83 | + publisher1.setPublisherId(1); | ||
84 | + publisherAction.setPublisher(publisher); | ||
85 | + publisherAction1.setPublisher(publisher1); | ||
86 | + publisherActions.add(publisherAction); | ||
87 | + publisherActions.add(publisherAction1); | ||
88 | + | ||
89 | + listPublisherActionsView = new ListPublisherActionsView(); | ||
90 | + listPublisherActionsView.setPublisherActions(publisherActions); | ||
91 | + listPublisherActionsView.setPublisherId(1); | ||
92 | + listPublisherActionsView.filterOnID(); | ||
93 | + assertThat(listPublisherActionsView.getPublisherActions()).containsExactly(publisherAction1); | ||
94 | + } | ||
95 | +} |
-
Please register or login to post a comment