1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.dbcp2.datasources;
19
20 import static org.junit.jupiter.api.Assertions.assertEquals;
21 import static org.junit.jupiter.api.Assertions.assertNotEquals;
22
23 import org.junit.jupiter.api.BeforeEach;
24 import org.junit.jupiter.api.Test;
25
26
27
28
29 public class TestPoolKey {
30
31 private PoolKey poolKey;
32 private PoolKey anotherPoolKey;
33
34 @BeforeEach
35 public void setUp() {
36 poolKey = new PoolKey("ds", "user");
37 anotherPoolKey = new PoolKey(null, null);
38 }
39
40 @Test
41 public void testEquals() {
42 assertEquals(poolKey, poolKey);
43 assertNotEquals(poolKey, null);
44 assertNotEquals(poolKey, new Object());
45 assertNotEquals(new PoolKey(null, "user"), poolKey);
46 assertEquals(new PoolKey(null, "user"), new PoolKey(null, "user"));
47 assertNotEquals(new PoolKey(null, "user"), new PoolKey(null, "foo"));
48 assertNotEquals(new PoolKey("ds", null), new PoolKey("foo", null));
49 assertNotEquals(new PoolKey("ds", null), poolKey);
50 assertEquals(new PoolKey("ds", null), new PoolKey("ds", null));
51 }
52
53 @Test
54 public void testHashcode() {
55 assertEquals(poolKey.hashCode(), new PoolKey("ds", "user").hashCode());
56 assertNotEquals(poolKey.hashCode(), anotherPoolKey.hashCode());
57 }
58
59 @Test
60 public void testToString() {
61 assertEquals(poolKey.toString(), new PoolKey("ds", "user").toString());
62 assertNotEquals(poolKey.toString(), anotherPoolKey.toString());
63 }
64 }