1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.platform.wiki.creationjob.internal.steps; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.List; |
24 |
|
|
25 |
|
import org.junit.Before; |
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationException; |
29 |
|
import org.xwiki.platform.wiki.creationjob.WikiCreationRequest; |
30 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
31 |
|
import org.xwiki.wiki.user.WikiUserManager; |
32 |
|
import org.xwiki.wiki.user.WikiUserManagerException; |
33 |
|
|
34 |
|
import static org.junit.Assert.assertEquals; |
35 |
|
import static org.junit.Assert.assertNotNull; |
36 |
|
import static org.mockito.ArgumentMatchers.any; |
37 |
|
import static org.mockito.ArgumentMatchers.anyCollection; |
38 |
|
import static org.mockito.Mockito.doThrow; |
39 |
|
import static org.mockito.Mockito.verify; |
40 |
|
|
41 |
|
|
42 |
|
@version |
43 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (25) |
Complexity: 5 |
Complexity Density: 0.24 |
|
44 |
|
public class AddUsersStepTest |
45 |
|
{ |
46 |
|
@Rule |
47 |
|
public MockitoComponentMockingRule<AddUsersStep> mocker = new MockitoComponentMockingRule<>(AddUsersStep.class); |
48 |
|
|
49 |
|
private WikiUserManager wikiUserManager; |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
3 |
@Before... |
52 |
|
public void setUp() throws Exception |
53 |
|
{ |
54 |
3 |
wikiUserManager = mocker.getInstance(WikiUserManager.class); |
55 |
|
} |
56 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
57 |
1 |
@Test... |
58 |
|
public void execute() throws Exception |
59 |
|
{ |
60 |
1 |
WikiCreationRequest request = new WikiCreationRequest(); |
61 |
1 |
request.setWikiId("wikiId"); |
62 |
1 |
List<String> members = new ArrayList<>(); |
63 |
1 |
request.setMembers(members); |
64 |
|
|
65 |
|
|
66 |
1 |
mocker.getComponentUnderTest().execute(request); |
67 |
|
|
68 |
|
|
69 |
1 |
verify(wikiUserManager).addMembers(members, "wikiId"); |
70 |
|
} |
71 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (13) |
Complexity: 2 |
Complexity Density: 0.15 |
1PASS
|
|
72 |
1 |
@Test... |
73 |
|
public void executeWhenException() throws Exception |
74 |
|
{ |
75 |
1 |
WikiCreationRequest request = new WikiCreationRequest(); |
76 |
1 |
request.setWikiId("wikiId"); |
77 |
1 |
List<String> members = new ArrayList<>(); |
78 |
1 |
request.setMembers(members); |
79 |
|
|
80 |
1 |
Exception exception = new WikiUserManagerException("Execption in WikiUserManager."); |
81 |
1 |
doThrow(exception).when(wikiUserManager).addMembers(anyCollection(), any()); |
82 |
|
|
83 |
|
|
84 |
1 |
WikiCreationException caughtException = null; |
85 |
1 |
try { |
86 |
1 |
mocker.getComponentUnderTest().execute(request); |
87 |
|
} catch (WikiCreationException e) { |
88 |
1 |
caughtException = e; |
89 |
|
} |
90 |
|
|
91 |
|
|
92 |
1 |
assertNotNull(caughtException); |
93 |
1 |
assertEquals("Failed to add members to the wiki [wikiId].", caughtException.getMessage()); |
94 |
1 |
assertEquals(exception, caughtException.getCause()); |
95 |
|
|
96 |
|
} |
97 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
98 |
1 |
@Test... |
99 |
|
public void getOrder() throws Exception |
100 |
|
{ |
101 |
1 |
assertEquals(4000, mocker.getComponentUnderTest().getOrder()); |
102 |
|
} |
103 |
|
} |