1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.objects.classes; |
21 |
|
|
22 |
|
import java.util.Arrays; |
23 |
|
import java.util.List; |
24 |
|
import java.util.Map; |
25 |
|
|
26 |
|
import org.junit.Rule; |
27 |
|
import org.junit.Test; |
28 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
29 |
|
import org.xwiki.model.reference.EntityReferenceResolver; |
30 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
31 |
|
import org.xwiki.test.mockito.MockitoComponentManagerRule; |
32 |
|
|
33 |
|
import com.xpn.xwiki.XWikiContext; |
34 |
|
import com.xpn.xwiki.user.api.XWikiGroupService; |
35 |
|
import com.xpn.xwiki.web.Utils; |
36 |
|
|
37 |
|
import static org.junit.Assert.assertEquals; |
38 |
|
import static org.mockito.ArgumentMatchers.any; |
39 |
|
import static org.mockito.ArgumentMatchers.anyBoolean; |
40 |
|
import static org.mockito.ArgumentMatchers.anyInt; |
41 |
|
import static org.mockito.ArgumentMatchers.eq; |
42 |
|
import static org.mockito.Mockito.mock; |
43 |
|
import static org.mockito.Mockito.when; |
44 |
|
|
45 |
|
|
46 |
|
@link |
47 |
|
|
48 |
|
@version |
49 |
|
@since |
50 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (17) |
Complexity: 1 |
Complexity Density: 0.06 |
|
51 |
|
public class UsersClassTest |
52 |
|
{ |
53 |
|
@Rule |
54 |
|
public MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule(); |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (16) |
Complexity: 1 |
Complexity Density: 0.06 |
1PASS
|
|
56 |
1 |
@Test... |
57 |
|
public void getMap() throws Exception |
58 |
|
{ |
59 |
1 |
XWikiContext context = mock(XWikiContext.class); |
60 |
1 |
com.xpn.xwiki.XWiki xwiki = mock(com.xpn.xwiki.XWiki.class); |
61 |
1 |
when(context.getWiki()).thenReturn(xwiki); |
62 |
1 |
XWikiGroupService groupService = mock(XWikiGroupService.class); |
63 |
1 |
when(xwiki.getGroupService(any())).thenReturn(groupService); |
64 |
1 |
when(groupService.getAllMatchedUsers(any(), anyBoolean(), anyInt(), anyInt(), any(), any())) |
65 |
|
.thenReturn((List) Arrays.asList("XWiki.Admin")); |
66 |
1 |
when(xwiki.getUserName(eq("XWiki.Admin"), any(), anyBoolean(), any())).thenReturn("Administrator"); |
67 |
|
|
68 |
1 |
Utils.setComponentManager(this.componentManager); |
69 |
1 |
this.componentManager.registerMockComponent(EntityReferenceSerializer.TYPE_STRING, "local"); |
70 |
1 |
this.componentManager.registerMockComponent(EntityReferenceResolver.TYPE_STRING, "relative"); |
71 |
1 |
this.componentManager.registerMockComponent(DocumentReferenceResolver.TYPE_REFERENCE, "current"); |
72 |
|
|
73 |
1 |
UsersClass usersClass = new UsersClass(); |
74 |
1 |
Map<String, ListItem> results = usersClass.getMap(context); |
75 |
1 |
assertEquals(1, results.size()); |
76 |
1 |
assertEquals("XWiki.Admin", results.get("XWiki.Admin").getId()); |
77 |
1 |
assertEquals("Administrator", results.get("XWiki.Admin").getValue()); |
78 |
|
} |
79 |
|
} |