SuperX-Kernmodul
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

93 lines
2.9 KiB

package de.memtext.baseobjects;
import static org.junit.Assert.*;
import org.junit.Test;
import de.memtext.rights.Rights;
/**
* Class to test {@link de.memtext.baseobjects.User}
* @author hiber
*/
public class UserTest {
private User user;
private final Integer USER_ID = Integer.valueOf(4711);
private final String NAME = "NAME";
private final String PASSWORD = "123Abc@!€";
private final Rights RIGHTS = new Rights(true, true);
/*
* Constructors
*/
@Test
public void testEmptyConstructor() {
this.user = new User();
String name = this.user.getName();
String password = this.user.getPasswd();
assertTrue("Name initialized with empty String", name.isEmpty());
assertTrue("Password initialized with empty String", password.isEmpty());
}
@Test
public void testConstructorWithUsername() {
this.user = new User(this.NAME);
assertEquals("Name has set correctly", this.NAME, this.user.getName());
}
@Test
public void testConstructorWithUsernameAndPassword() {
this.user = new User(this.NAME, this.PASSWORD);
assertEquals("Name has set correctly", this.NAME, this.user.getName());
assertEquals("Name has set correctly", this.PASSWORD, this.user.getPasswd());
}
@Test
public void testConstructorWithUsernameAndId() {
this.user = new User(this.NAME, this.USER_ID);
assertEquals("Name has set correctly", this.NAME, this.user.getName());
assertEquals("UserId has set correctly", this.NAME, this.user.getName());
}
@SuppressWarnings("deprecation")
@Test(expected = IllegalArgumentException.class)
public void testConstructorWithUsernameAndIdThrowsException() {
this.user = new User(this.NAME, Integer.valueOf(null));
assertEquals("Name has set correctly", this.NAME, this.user.getName());
assertNull("Userid has set to null", this.user.getId());
}
/*
* Getter and setter
*/
@Test
public void testSetAndGetName() {
this.user = new User();
this.user.setName(this.NAME);
assertEquals("Name has set correctly", this.NAME, this.user.getName());
}
@Test
public void testSetAndGetPassword() {
this.user = new User();
this.user.setPasswd(this.PASSWORD);
assertEquals("Name has set correctly", this.PASSWORD, this.user.getPasswd());
}
@Test
public void testSetAndGetAdmin() {
this.user = new User();
this.user.setAdmin(true);
assertTrue("User is admin", this.user.isAdmin());
this.user.setAdmin(false);
assertFalse("User isn't admin", this.user.isAdmin());
}
@Test
public void testSetAndGetRights() {
this.user = new User();
this.user.setRights(this.RIGHTS);
assertEquals("Rights have set correctly", this.RIGHTS, this.user.getRights());
}
}