com.atlassian.jira.user
Class MockUser

java.lang.Object
  extended by com.atlassian.jira.user.MockUser
All Implemented Interfaces:
com.atlassian.crowd.embedded.api.Attributes, com.atlassian.crowd.embedded.api.User, com.atlassian.crowd.embedded.api.UserWithAttributes, Serializable, Comparable<com.atlassian.crowd.embedded.api.User>, Principal

public class MockUser
extends Object
implements com.atlassian.crowd.embedded.api.UserWithAttributes, Serializable

A convenient mock for User that supplies reasonable behaviour for unit tests. Note that creating a MockUser does not automatically ensure that it can be resolved by the UserManager or UserKeyService, so unit tests may need to provide mocks for one or both of those services as well.

Since:
v4.3
See Also:
Serialized Form

Constructor Summary
MockUser(String username)
          Convenience constructor that is equivalent to MockUser(username, "", null, null).
MockUser(String username, String fullName, String email)
          Convenience constructor that is equivalent to MockUser(username, fullName, email, null).
MockUser(String username, String fullName, String email, Map<String,Set<String>> values)
          Creates a new mock user with the specified information.
 
Method Summary
 int compareTo(com.atlassian.crowd.embedded.api.User other)
           
 boolean equals(Object o)
           
 long getDirectoryId()
           
 String getDisplayName()
           
 String getEmailAddress()
           
 Set<String> getKeys()
           
 String getName()
           
 String getValue(String key)
           
 Set<String> getValues(String key)
           
 int hashCode()
           
 boolean isActive()
          A MockUser is always active by default.
 boolean isEmpty()
           
 void setActive(boolean active)
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

MockUser

public MockUser(String username)
Convenience constructor that is equivalent to MockUser(username, "", null, null).


MockUser

public MockUser(String username,
                String fullName,
                String email)
Convenience constructor that is equivalent to MockUser(username, fullName, email, null).


MockUser

public MockUser(String username,
                String fullName,
                String email,
                Map<String,Set<String>> values)
Creates a new mock user with the specified information.

Parameters:
username - the value to be returned for getName()
fullName - the value to be returned for getDisplayName()
email - the value to be returned for getEmailAddress()
values - a map to provide user attributes, such as are returned by getKeys() and getValues(String). May be null, in which case an empty map is used.
Method Detail

isActive

public boolean isActive()
A MockUser is always active by default.

Specified by:
isActive in interface com.atlassian.crowd.embedded.api.User

setActive

public void setActive(boolean active)

getEmailAddress

public String getEmailAddress()
Specified by:
getEmailAddress in interface com.atlassian.crowd.embedded.api.User

getDisplayName

public String getDisplayName()
Specified by:
getDisplayName in interface com.atlassian.crowd.embedded.api.User

getDirectoryId

public long getDirectoryId()
Specified by:
getDirectoryId in interface com.atlassian.crowd.embedded.api.User

getName

public String getName()
Specified by:
getName in interface Principal

toString

public String toString()
Specified by:
toString in interface Principal
Overrides:
toString in class Object

getValues

public Set<String> getValues(String key)
Specified by:
getValues in interface com.atlassian.crowd.embedded.api.Attributes

getValue

public String getValue(String key)
Specified by:
getValue in interface com.atlassian.crowd.embedded.api.Attributes

getKeys

public Set<String> getKeys()
Specified by:
getKeys in interface com.atlassian.crowd.embedded.api.Attributes

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface com.atlassian.crowd.embedded.api.Attributes

equals

public boolean equals(Object o)
Specified by:
equals in interface com.atlassian.crowd.embedded.api.User
Specified by:
equals in interface Principal
Overrides:
equals in class Object

hashCode

public int hashCode()
Specified by:
hashCode in interface com.atlassian.crowd.embedded.api.User
Specified by:
hashCode in interface Principal
Overrides:
hashCode in class Object

compareTo

public int compareTo(com.atlassian.crowd.embedded.api.User other)
Specified by:
compareTo in interface com.atlassian.crowd.embedded.api.User
Specified by:
compareTo in interface Comparable<com.atlassian.crowd.embedded.api.User>


Copyright © 2002-2014 Atlassian. All Rights Reserved.