Menu

[r3159]: / trunk / ch.sahits.codegen.java.jugr / src / UserBeanOriginalTest.java  Maximize  Restore  History

Download this file

83 lines (72 with data), 2.9 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
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());
}
}
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.