package com.xpn.xwiki.api;

import org.jmock.cglib.MockObjectTestCase;

import com.xpn.xwiki.XWikiContext;
import com.xpn.xwiki.user.api.XWikiUser;

/**
 * Unit tests for {@link com.xpn.xwiki.api.User}.
 * 
 * @version $Id: $
 */
public class UserTest extends MockObjectTestCase
{
    /**
     * Checks that XWIKI-2040 remains fixed.
     */
    public void testIsUserInGroupDoesNotThrowNPE()
    {
        User u = new User(null, null);
        assertFalse(u.isUserInGroup("XWiki.InexistentGroupName"));

        XWikiUser xu = new XWikiUser(null);
        u = new User(xu, null);
        assertFalse(u.isUserInGroup("XWiki.InexistentGroupName"));

        XWikiContext c = new XWikiContext();
        u = new User(xu, c);
        assertFalse(u.isUserInGroup("XWiki.InexistentGroupName"));
    }
}

@@ -21,16 +21,39 @@
 i.api;%0A%0A
+import org.jmock.Mock;%0A
 import o
@@ -118,190 +118,1376 @@
 Wiki
-Context;%0Aimport com.xpn.xwiki.user.api.XWikiUser;%0A%0A/**%0A * Unit tests for %7B@link com.xpn.xwiki.api.User%7D.%0A * %0A * @version $Id: $%0A */%0Apublic class UserTest extends MockObjectTestCase%0A%7B
+;%0Aimport com.xpn.xwiki.XWikiConfig;%0Aimport com.xpn.xwiki.XWikiContext;%0Aimport com.xpn.xwiki.XWikiException;%0Aimport com.xpn.xwiki.doc.XWikiDocument;%0Aimport com.xpn.xwiki.objects.BaseObject;%0Aimport com.xpn.xwiki.objects.classes.BaseClass;%0Aimport com.xpn.xwiki.store.XWikiHibernateVersioningStore;%0Aimport com.xpn.xwiki.user.api.XWikiUser;%0A%0A/**%0A * Unit tests for %7B@link com.xpn.xwiki.api.User%7D.%0A * %0A * @version $Id: $%0A */%0Apublic class UserTest extends MockObjectTestCase%0A%7B%0A    private Mock mockXWiki;%0A%0A    private XWikiContext context;%0A%0A    protected void setUp() throws XWikiException%0A    %7B%0A        this.context = new XWikiContext();%0A        this.mockXWiki =%0A            mock(com.xpn.xwiki.XWiki.class, new java.lang.Class%5B%5D %7B%0A            com.xpn.xwiki.XWikiConfig.class, XWikiContext.class%7D, new java.lang.Object%5B%5D %7B%0A            new XWikiConfig(), context%7D);%0A        context.setWiki((XWiki) mockXWiki.proxy());%0A        XWikiDocument doc = new XWikiDocument(%22XWiki%22, %22Admin%22);%0A        BaseClass userClass = new BaseClass();%0A        userClass.addTextField(%22email%22, %22email address%22, 20);%0A        mockXWiki.stubs().method(%22getClass%22).will(returnValue(userClass));%0A        BaseObject userObj = doc.newObject(%22XWiki.XWikiUsers%22, context);%0A        userObj.setStringValue(%22email%22, %22admin@mail.com%22);%0A        mockXWiki.stubs().method(%22getDocument%22).will(returnValue(doc));%0A    %7D%0A
 %0A   
@@ -1998,11 +1998,271 @@
 );%0A    %7D
+%0A%0A    public void testGetEmail()%0A    %7B%0A        User u = new User(null, null);%0A        assertNull(u.getEmail());%0A%0A        XWikiUser xu = new XWikiUser(%22XWiki.Admin%22);%0A        u = new User(xu, context);%0A        assertEquals(%22admin@mail.com%22, u.getEmail());%0A    %7D
 %0A%7D%0A

Add a method to retrieve the e-mail address of a user Added unit tests.