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

File UserTest.java

 

Code metrics

0
22
2
1
76
41
2
0.09
11
2
1

Classes

Class Line # Actions
UserTest 38 22 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

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.api;
21   
22    import org.jmock.Mock;
23    import org.xwiki.model.reference.DocumentReference;
24   
25    import com.xpn.xwiki.XWiki;
26    import com.xpn.xwiki.XWikiContext;
27    import com.xpn.xwiki.doc.XWikiDocument;
28    import com.xpn.xwiki.objects.BaseObject;
29    import com.xpn.xwiki.objects.classes.BaseClass;
30    import com.xpn.xwiki.test.AbstractBridgedXWikiComponentTestCase;
31    import com.xpn.xwiki.user.api.XWikiUser;
32   
33    /**
34    * Unit tests for {@link com.xpn.xwiki.api.User}.
35    *
36    * @version $Id: 1bdaf95c229c4ccac7beae21fb5dfa1e65b1fd92 $
37    */
 
38    public class UserTest extends AbstractBridgedXWikiComponentTestCase
39    {
40    /**
41    * Checks that XWIKI-2040 remains fixed.
42    */
 
43  1 toggle public void testIsUserInGroupDoesNotThrowNPE()
44    {
45  1 User u = new User(null, null);
46  1 assertFalse(u.isUserInGroup("XWiki.InexistentGroupName"));
47   
48  1 XWikiUser xu = new XWikiUser(null);
49  1 u = new User(xu, null);
50  1 assertFalse(u.isUserInGroup("XWiki.InexistentGroupName"));
51   
52  1 XWikiContext c = new XWikiContext();
53  1 u = new User(xu, c);
54  1 assertFalse(u.isUserInGroup("XWiki.InexistentGroupName"));
55    }
56   
 
57  1 toggle public void testGetEmail() throws Exception
58    {
59  1 Mock mockXWiki = mock(XWiki.class);
60  1 getContext().setWiki((XWiki) mockXWiki.proxy());
61  1 XWikiDocument doc = new XWikiDocument(new DocumentReference("xwiki", "XWiki", "Admin"));
62  1 BaseClass userClass = new BaseClass();
63  1 userClass.addTextField("email", "email address", 20);
64  1 mockXWiki.stubs().method("getXClass").will(returnValue(userClass));
65  1 BaseObject userObj = doc.newXObject(new DocumentReference("xwiki", "XWiki", "XWikiUsers"), getContext());
66  1 userObj.setStringValue("email", "admin@mail.com");
67  1 mockXWiki.stubs().method("getDocument").will(returnValue(doc));
68   
69  1 User u = new User(null, null);
70  1 assertNull(u.getEmail());
71   
72  1 XWikiUser xu = new XWikiUser("XWiki.Admin");
73  1 u = new User(xu, getContext());
74  1 assertEquals("admin@mail.com", u.getEmail());
75    }
76    }