1
+ package org .rulez .demokracia .pdengine ;
2
+
3
+ import static org .junit .Assert .assertEquals ;
4
+ import static org .junit .Assert .assertNotEquals ;
5
+
6
+ import org .junit .Test ;
7
+ import org .rulez .demokracia .pdengine .annotations .TestedBehaviour ;
8
+ import org .rulez .demokracia .pdengine .annotations .TestedFeature ;
9
+ import org .rulez .demokracia .pdengine .annotations .TestedOperation ;
10
+ import org .rulez .demokracia .pdengine .dataobjects .Pair ;
11
+ import org .rulez .demokracia .pdengine .dataobjects .VoteEntity ;
12
+
13
+ @ TestedFeature ("Supporting functionality" )
14
+ @ TestedOperation ("BaseEntity" )
15
+ @ TestedBehaviour ("None of the entities count id into the equals and hashCode." )
16
+ public class BaseEntityHashEqualsTest {
17
+
18
+
19
+ @ Test
20
+ public void entities_with_equal_fields_are_equal () {
21
+ Pair pair1 = new Pair (12 , 42 );
22
+ Pair pair2 = new Pair (12 , 42 );
23
+ assertNotEquals (pair1 .id , pair2 .id );
24
+ assertEquals (pair1 , pair2 );
25
+ }
26
+
27
+ @ Test
28
+ public void entities_with_different_fields_are_not_equal () {
29
+ Pair pair1 = new Pair (12 , 42 );
30
+ Pair pair2 = new Pair (12 , 69 );
31
+ assertNotEquals (pair1 , pair2 );
32
+ }
33
+
34
+ @ Test
35
+ public void equal_entities_have_the_same_hash_code () {
36
+ Pair pair1 = new Pair (12 , 42 );
37
+ Pair pair2 = new Pair (12 , 42 );
38
+ assertEquals (pair1 .hashCode (), pair2 .hashCode ());
39
+ }
40
+
41
+ @ Test
42
+ public void hashCode_should_return_different_hash_on_different_entities () {
43
+ Pair pair = new Pair (10 , 10 );
44
+ VoteEntity vote = new VoteEntity ();
45
+ assertNotEquals (pair .hashCode (), vote .hashCode ());
46
+ }
47
+ }
0 commit comments