25
25
* Tests for {@link SimpleKeyGenerator} and {@link SimpleKey}.
26
26
*
27
27
* @author Phillip Webb
28
+ * @author Stephane Nicoll
28
29
*/
29
30
public class SimpleKeyGeneratorTests {
30
31
31
32
private SimpleKeyGenerator generator = new SimpleKeyGenerator ();
32
33
33
34
@ Test
34
- public void noValues () throws Exception {
35
- Object k1 = generator . generate ( null , null , new Object [] {});
36
- Object k2 = generator . generate ( null , null , new Object [] {});
37
- Object k3 = generator . generate ( null , null , new Object [] { "different" });
35
+ public void noValues () {
36
+ Object k1 = generateKey ( new Object [] {});
37
+ Object k2 = generateKey ( new Object [] {});
38
+ Object k3 = generateKey ( new Object [] { "different" });
38
39
assertThat (k1 .hashCode (), equalTo (k2 .hashCode ()));
39
40
assertThat (k1 .hashCode (), not (equalTo (k3 .hashCode ())));
40
41
assertThat (k1 , equalTo (k2 ));
41
42
assertThat (k1 , not (equalTo (k3 )));
42
43
}
43
44
44
45
@ Test
45
- public void singleValue () throws Exception {
46
- Object k1 = generator . generate ( null , null , new Object [] { "a" });
47
- Object k2 = generator . generate ( null , null , new Object [] { "a" });
48
- Object k3 = generator . generate ( null , null , new Object [] { "different" });
46
+ public void singleValue (){
47
+ Object k1 = generateKey ( new Object [] { "a" });
48
+ Object k2 = generateKey ( new Object [] { "a" });
49
+ Object k3 = generateKey ( new Object [] { "different" });
49
50
assertThat (k1 .hashCode (), equalTo (k2 .hashCode ()));
50
51
assertThat (k1 .hashCode (), not (equalTo (k3 .hashCode ())));
51
52
assertThat (k1 , equalTo (k2 ));
@@ -54,21 +55,21 @@ public void singleValue() throws Exception {
54
55
}
55
56
56
57
@ Test
57
- public void multipleValues () throws Exception {
58
- Object k1 = generator . generate ( null , null , new Object [] { "a" , 1 , "b" });
59
- Object k2 = generator . generate ( null , null , new Object [] { "a" , 1 , "b" });
60
- Object k3 = generator . generate ( null , null , new Object [] { "b" , 1 , "a" });
58
+ public void multipleValues () {
59
+ Object k1 = generateKey ( new Object [] { "a" , 1 , "b" });
60
+ Object k2 = generateKey ( new Object [] { "a" , 1 , "b" });
61
+ Object k3 = generateKey ( new Object [] { "b" , 1 , "a" });
61
62
assertThat (k1 .hashCode (), equalTo (k2 .hashCode ()));
62
63
assertThat (k1 .hashCode (), not (equalTo (k3 .hashCode ())));
63
64
assertThat (k1 , equalTo (k2 ));
64
65
assertThat (k1 , not (equalTo (k3 )));
65
66
}
66
67
67
68
@ Test
68
- public void singleNullValue () throws Exception {
69
- Object k1 = generator . generate ( null , null , new Object [] { null });
70
- Object k2 = generator . generate ( null , null , new Object [] { null });
71
- Object k3 = generator . generate ( null , null , new Object [] { "different" });
69
+ public void singleNullValue () {
70
+ Object k1 = generateKey ( new Object [] { null });
71
+ Object k2 = generateKey ( new Object [] { null });
72
+ Object k3 = generateKey ( new Object [] { "different" });
72
73
assertThat (k1 .hashCode (), equalTo (k2 .hashCode ()));
73
74
assertThat (k1 .hashCode (), not (equalTo (k3 .hashCode ())));
74
75
assertThat (k1 , equalTo (k2 ));
@@ -77,13 +78,28 @@ public void singleNullValue() throws Exception {
77
78
}
78
79
79
80
@ Test
80
- public void multiplNullValues () throws Exception {
81
- Object k1 = generator . generate ( null , null , new Object [] { "a" , null , "b" , null });
82
- Object k2 = generator . generate ( null , null , new Object [] { "a" , null , "b" , null });
83
- Object k3 = generator . generate ( null , null , new Object [] { "a" , null , "b" });
81
+ public void multipleNullValues () {
82
+ Object k1 = generateKey ( new Object [] { "a" , null , "b" , null });
83
+ Object k2 = generateKey ( new Object [] { "a" , null , "b" , null });
84
+ Object k3 = generateKey ( new Object [] { "a" , null , "b" });
84
85
assertThat (k1 .hashCode (), equalTo (k2 .hashCode ()));
85
86
assertThat (k1 .hashCode (), not (equalTo (k3 .hashCode ())));
86
87
assertThat (k1 , equalTo (k2 ));
87
88
assertThat (k1 , not (equalTo (k3 )));
88
89
}
90
+
91
+ @ Test
92
+ public void arrays () {
93
+ Object k1 = generateKey (new Object [] { new String []{"a" , "b" }, "c" });
94
+ Object k2 = generateKey (new Object [] { new String []{"a" , "b" }, "c" });
95
+ Object k3 = generateKey (new Object [] { new String []{"b" , "a" }, "c" });
96
+ assertThat (k1 .hashCode (), equalTo (k2 .hashCode ()));
97
+ assertThat (k1 .hashCode (), not (equalTo (k3 .hashCode ())));
98
+ assertThat (k1 , equalTo (k2 ));
99
+ assertThat (k1 , not (equalTo (k3 )));
100
+ }
101
+
102
+ private Object generateKey (Object [] arguments ) {
103
+ return generator .generate (null , null , arguments );
104
+ }
89
105
}
0 commit comments