View Javadoc
1   /*
2    * Licensed under the GPL License. You may not use this file except in compliance with the License.
3    * You may obtain a copy of the License at
4    *
5    *   https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
6    *
7    * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
8    * WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
9    * PURPOSE.
10   */
11  package psiprobe.beans.accessors;
12  
13  import com.zaxxer.hikari.HikariDataSource;
14  
15  import java.sql.SQLException;
16  
17  import org.junit.jupiter.api.Assertions;
18  import org.junit.jupiter.api.BeforeEach;
19  import org.junit.jupiter.api.Test;
20  import org.junit.jupiter.api.extension.ExtendWith;
21  import org.mockito.Mock;
22  import org.mockito.Mockito;
23  import org.mockito.junit.jupiter.MockitoExtension;
24  import org.vibur.dbcp.ViburDBCPDataSource;
25  import org.vibur.objectpool.PoolService;
26  
27  /**
28   * The Class ViburCpDatasourceAccessorTest.
29   */
30  @ExtendWith(MockitoExtension.class)
31  class ViburCpDatasourceAccessorTest {
32  
33    /** The accessor. */
34    ViburCpDatasourceAccessor accessor;
35  
36    /** The source. */
37    @Mock
38    ViburDBCPDataSource source;
39  
40    /** The bad source. */
41    HikariDataSource badSource;
42  
43    /**
44     * Before.
45     */
46    @BeforeEach
47    void before() {
48      accessor = new ViburCpDatasourceAccessor();
49      badSource = new HikariDataSource();
50    }
51  
52    /**
53     * Can map test.
54     */
55    @Test
56    void canMapTest() {
57      Assertions.assertTrue(accessor.canMap(source));
58    }
59  
60    /**
61     * Cannot map test.
62     */
63    @Test
64    void cannotMapTest() {
65      Assertions.assertFalse(accessor.canMap(badSource));
66    }
67  
68    /**
69     * Gets the info test.
70     *
71     * @throws SQLException the sql exception
72     */
73    @SuppressWarnings("unchecked")
74    @Test
75    void getInfoTest() throws SQLException {
76      var poolService = Mockito.mock(PoolService.class);
77      Mockito.when(source.getPool()).thenReturn(poolService);
78      Mockito.when(poolService.taken()).thenReturn(1);
79      Mockito.when(poolService.remainingCreated()).thenReturn(1);
80  
81      Assertions.assertNotNull(accessor.getInfo(source));
82    }
83  
84  }