2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2019 Ericsson
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.appc.dao.util.helper;
24 import org.junit.Test;
25 import org.mockito.Mockito;
26 import java.sql.Connection;
27 import java.sql.ResultSet;
28 import java.sql.SQLException;
29 import java.sql.Statement;
31 public class DBHelperTest {
34 public void testClose() throws SQLException {
35 ResultSet resultSet = Mockito.mock(ResultSet.class);
36 Statement statement = Mockito.mock(Statement.class);
37 Connection connection = Mockito.mock(Connection.class);
38 DBHelper.close(resultSet, statement, connection);
39 Mockito.verify(connection).close();
43 public void testCloseResultSet() throws SQLException {
44 ResultSet resultSet = Mockito.mock(ResultSet.class);
45 Mockito.doThrow(new SQLException()).when(resultSet).close();
46 DBHelper.closeResultSet(resultSet);
47 Mockito.verify(resultSet, Mockito.times(1)).close();
51 public void testCloseResultSetNull() throws SQLException {
52 ResultSet resultSet = Mockito.mock(ResultSet.class);
53 Mockito.doThrow(new SQLException()).when(resultSet).close();
54 DBHelper.closeResultSet(null);
55 Mockito.verify(resultSet, Mockito.times(0)).close();
59 public void testCloseStatement() throws SQLException {
60 Statement statement = Mockito.mock(Statement.class);
61 Mockito.doThrow(new SQLException()).when(statement).close();
62 DBHelper.closeStatement(statement);
63 Mockito.verify(statement, Mockito.times(1)).close();
67 public void testCloseStatementNull() throws SQLException {
68 Statement statement = Mockito.mock(Statement.class);
69 Mockito.doThrow(new SQLException()).when(statement).close();
70 DBHelper.closeStatement(null);
71 Mockito.verify(statement, Mockito.times(0)).close();
75 public void testCloseConnection() throws SQLException {
76 Connection connection = Mockito.mock(Connection.class);
77 Mockito.doThrow(new SQLException()).when(connection).close();
78 DBHelper.closeConnection(connection);
79 Mockito.verify(connection, Mockito.times(1)).close();
83 public void testCloseConnectionNull() throws SQLException {
84 Connection connection = Mockito.mock(Connection.class);
85 Mockito.doThrow(new SQLException()).when(connection).close();
86 DBHelper.closeConnection(null);
87 Mockito.verify(connection, Mockito.times(0)).close();