1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.objects.classes

File UsersClassTest.java

 

Code metrics

0
16
1
1
79
46
1
0.06
16
1
1

Classes

Class Line # Actions
UsersClassTest 51 16 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Unit tests for {@link com.xpn.xwiki.objects.classes.UsersClass}.
47    *
48    * @version $Id: 244fb11eeeb2c676c9d0a16a99ef2611dc73771b $
49    * @since 5.1M2
50    */
 
51    public class UsersClassTest
52    {
53    @Rule
54    public MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule();
55   
 
56  1 toggle @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    }