import java.util.Random;
import java.util.UUID;
import junit.framework.TestCase;
public class UserBeanOriginalTest extends TestCase {
private UserBeanOriginal x;
private UserBeanOriginal xx;
private UserBeanOriginal y;
private UserBeanOriginal z;
private UserBeanOriginal zx;
private Random rnd = new Random(UserBeanOriginalTest.class.hashCode()+System.nanoTime());
protected void setUp() throws Exception {
x = new UserBeanOriginal();
x.setId(rnd.nextInt());
x.setEmail(UUID.randomUUID().toString());
x.setPassword(UUID.randomUUID().toString());
x.setUsername(UUID.randomUUID().toString());
xx = new UserBeanOriginal();
xx.setId(x.getId());
xx.setEmail(x.getEmail());
xx.setPassword(x.getPassword());
xx.setUsername(x.getUsername());
y = new UserBeanOriginal();
y.setId(rnd.nextInt());
y.setEmail(UUID.randomUUID().toString());
y.setPassword(UUID.randomUUID().toString());
y.setUsername(UUID.randomUUID().toString());
z = new UserBeanOriginal();
z.setId(rnd.nextInt());
z.setEmail(UUID.randomUUID().toString());
z.setPassword(UUID.randomUUID().toString());
z.setUsername(UUID.randomUUID().toString());
zx = new UserBeanOriginal();
zx.setId(x.getId());
zx.setEmail(x.getEmail());
zx.setPassword(x.getPassword());
zx.setUsername(x.getUsername());
}
public void testEqualsObject() {
assertEquals("The equals method fails on the reflexifity test: x.equals(x)==false",x, x);
assertEquals("The equals method fails on objects with the same status: xx.equals(x)==false",xx, x);
assertEquals("The equals method fails on objects with the same status: zx.equals(xx)==false",zx, xx);
assertEquals("The equals method fails on the symetry test: xx.equals(x)== x.equals(xx) is false",xx.equals(x), x.equals(xx));
assertEquals("The equals method fails on the transitivity test: (xx==x && zx==xx) but zx.equals(x)==false",zx, x);
assertEquals("The equals method fails on the transitivity test: (x==zx && zx==y)==false but x.equals(y)==true",x.equals(zx) && zx.equals(y), x.equals(y));
assertNotNull(x);
assertFalse("The equals test fails on the null comparrison: x!=null == true", x.equals(null));
}
public void testHashCode() {
final int firstXHash = x.hashCode();
for (int i=0;i<100;i++){
assertEquals("The hash value of x changed without x changing its status",firstXHash, x.hashCode());
}
assertEquals(x, xx);
for (int i=0;i<100;i++){
if (x.equals(xx)){
assertEquals("The hashCode of equal objects differs.",x.hashCode(), xx.hashCode());
}
}
assertEquals(x, zx);
for (int i=0;i<100;i++){
if (x.equals(zx)){
assertEquals("The hashCode of equal objects differs.",x.hashCode(), zx.hashCode());
}
}
assertEquals(xx, zx);
for (int i=0;i<100;i++){
if (zx.equals(xx)){
assertEquals("The hashCode of equal objects differs.",zx.hashCode(), xx.hashCode());
}
}
}
}