1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.mina.session;
20
21 import static org.hamcrest.CoreMatchers.is;
22 import static org.junit.Assert.assertThat;
23
24 import java.util.Date;
25
26 import org.junit.Rule;
27 import org.junit.Test;
28 import org.junit.rules.ExpectedException;
29
30
31
32
33
34
35 public class AttributeKeyTest {
36
37 @Rule
38 public final ExpectedException exception = ExpectedException.none();
39
40
41
42
43
44
45
46 @Test
47 public void constructorWithoutKeyType() throws Exception {
48 exception.expect(IllegalArgumentException.class);
49 exception.expectMessage("Parameter >attributeType< must not be null!");
50 new AttributeKey<Number>(null, "key");
51 }
52
53
54
55
56
57
58
59 @Test
60 public void constructorWithoutKeyName() throws Exception {
61 exception.expect(IllegalArgumentException.class);
62 exception.expectMessage("Parameter >attributeName< must not be null!");
63 new AttributeKey<Number>(Number.class, null);
64 }
65
66
67
68
69
70
71 @Test
72 public void getName() throws Exception {
73 String name = new AttributeKey<Number>(Number.class, "keyName").getName();
74 assertThat(name, is("keyName"));
75 }
76
77
78
79
80
81
82 @Test
83 public void getType() throws Exception {
84 Class<?> type = new AttributeKey<Number>(Number.class, "keyName").getType();
85 assertThat(type, is((Object) Number.class));
86 }
87
88
89
90
91
92 @Test
93 public void equalsSymmetric() throws Exception {
94 AttributeKey<Number> key1 = new AttributeKey<Number>(Number.class, "keyName");
95 AttributeKey<Number> key2 = new AttributeKey<Number>(Number.class, "keyName");
96
97 assertThat(key1.equals(key2), is(true));
98 assertThat(key2.equals(key1), is(true));
99 }
100
101
102
103
104
105 @Test
106 public void equalsWithDifferentTypes() throws Exception {
107 AttributeKey<Number> key1 = new AttributeKey<Number>(Number.class, "keyName");
108 AttributeKey<Date> key2 = new AttributeKey<Date>(Date.class, "keyName");
109
110 assertThat(key1.equals(key2), is(false));
111 assertThat(key2.equals(key1), is(false));
112 }
113
114
115
116
117
118 @Test
119 public void equalsWithDifferentName() throws Exception {
120 AttributeKey<Number> key1 = new AttributeKey<Number>(Number.class, "key1");
121 AttributeKey<Number> key2 = new AttributeKey<Number>(Number.class, "key2");
122
123 assertThat(key1.equals(key2), is(false));
124 assertThat(key2.equals(key1), is(false));
125 }
126
127
128
129
130
131 @Test
132 public void hashCodeValue() throws Exception {
133 AttributeKey<Number> key1 = new AttributeKey<Number>(Number.class, "keyName");
134 AttributeKey<Number> key2 = new AttributeKey<Number>(Number.class, "keyName");
135
136 assertThat(key1.hashCode(), is(key2.hashCode()));
137 }
138 }