1
2
3
4
5
6
7
8
9
10
11 package psiprobe.beans.accessors;
12
13 import com.zaxxer.hikari.HikariDataSource;
14 import com.zaxxer.hikari.HikariPoolMXBean;
15
16 import java.sql.SQLException;
17
18 import org.junit.jupiter.api.Assertions;
19 import org.junit.jupiter.api.BeforeEach;
20 import org.junit.jupiter.api.Test;
21 import org.junit.jupiter.api.extension.ExtendWith;
22 import org.mockito.Mock;
23 import org.mockito.Mockito;
24 import org.mockito.junit.jupiter.MockitoExtension;
25 import org.vibur.dbcp.ViburDBCPDataSource;
26
27
28
29
30 @ExtendWith(MockitoExtension.class)
31 class HikariCpDatasourceAccessorTest {
32
33
34 HikariCpDatasourceAccessor accessor;
35
36
37 @Mock
38 HikariDataSource source;
39
40
41 ViburDBCPDataSource badSource;
42
43
44
45
46 @BeforeEach
47 void before() {
48 accessor = new HikariCpDatasourceAccessor();
49 badSource = new ViburDBCPDataSource();
50 }
51
52
53
54
55 @Test
56 void canMapTest() {
57 Assertions.assertTrue(accessor.canMap(source));
58 }
59
60
61
62
63 @Test
64 void cannotMapTest() {
65 Assertions.assertFalse(accessor.canMap(badSource));
66 }
67
68
69
70
71
72
73 @Test
74 void getInfoTest() throws SQLException {
75 var poolMxBean = Mockito.mock(HikariPoolMXBean.class);
76 Mockito.when(source.getHikariPoolMXBean()).thenReturn(poolMxBean);
77 Mockito.when(poolMxBean.getActiveConnections()).thenReturn(1);
78 Mockito.when(poolMxBean.getTotalConnections()).thenReturn(2);
79
80 Assertions.assertNotNull(accessor.getInfo(source));
81 }
82
83 }