01: // Copyright 2006 The Apache Software Foundation
02: //
03: // Licensed under the Apache License, Version 2.0 (the "License");
04: // you may not use this file except in compliance with the License.
05: // You may obtain a copy of the License at
06: //
07: // http://www.apache.org/licenses/LICENSE-2.0
08: //
09: // Unless required by applicable law or agreed to in writing, software
10: // distributed under the License is distributed on an "AS IS" BASIS,
11: // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12: // See the License for the specific language governing permissions and
13: // limitations under the License.
14:
15: package org.apache.tapestry.internal.util;
16:
17: import org.testng.Assert;
18: import org.testng.annotations.Test;
19:
20: public class MultiKeyTest extends Assert {
21: @Test
22: public void same_values_same_hash_codes() {
23: MultiKey key1 = new MultiKey(1, 3, "foo");
24: MultiKey key2 = new MultiKey(1, 3, "foo");
25: MultiKey key3 = new MultiKey(1, 3);
26: MultiKey key4 = new MultiKey(1, 3, "bar");
27: MultiKey key5 = new MultiKey(1, 3, "foo", "bar");
28:
29: assertEquals(key2.hashCode(), key1.hashCode());
30: assertFalse(key3.hashCode() == key1.hashCode());
31: assertFalse(key4.hashCode() == key1.hashCode());
32: assertFalse(key5.hashCode() == key1.hashCode());
33: }
34:
35: @Test
36: public void comparisons_against_not_multi_key() {
37: MultiKey key = new MultiKey(1, 3, "foo");
38:
39: assertFalse(key.equals(null));
40: assertFalse(key.equals("foo"));
41: }
42:
43: @Test
44: public void comparison_against_self() {
45: MultiKey key = new MultiKey(1, 3, "foo");
46:
47: assertTrue(key.equals(key));
48: }
49:
50: @Test
51: public void comparisons_against_other_keys() {
52: MultiKey key1 = new MultiKey(1, 3, "foo");
53: MultiKey key2 = new MultiKey(1, 3, "foo");
54: MultiKey key3 = new MultiKey(1, 3);
55: MultiKey key4 = new MultiKey(1, 3, "bar");
56: MultiKey key5 = new MultiKey(1, 3, "foo", "bar");
57:
58: assertEquals(key2, key1);
59: assertFalse(key3.equals(key1));
60: assertFalse(key4.equals(key1));
61: assertFalse(key5.equals(key1));
62: }
63:
64: @Test
65: public void to_string() {
66: assertEquals(new MultiKey("fred").toString(), "MultiKey[fred]");
67: assertEquals(new MultiKey("fred", "barney").toString(),
68: "MultiKey[fred, barney]");
69: }
70: }
|