Move close methods out of sql datasource utils class
As noticed by @Gnat008 - We need two different implementations for MySQL and SQLite because SQLite uses an older version where #isClosed is not implemented
This commit is contained in:
@@ -4,18 +4,12 @@ import fr.xephi.authme.TestHelper;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.SQLException;
|
||||
import java.sql.Statement;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
||||
|
||||
/**
|
||||
* Test for {@link SqlDataSourceUtils}.
|
||||
@@ -46,90 +40,4 @@ public class SqlDataSourceUtilsTest {
|
||||
// then
|
||||
verify(logger).warning(argThat(containsString(msg)));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCloseStatement() throws SQLException {
|
||||
// given
|
||||
Statement st = mock(Statement.class);
|
||||
|
||||
// when
|
||||
SqlDataSourceUtils.close(st);
|
||||
|
||||
// then
|
||||
verify(st).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleExceptionFromStatement() throws SQLException {
|
||||
// given
|
||||
Statement st = mock(Statement.class);
|
||||
doThrow(SQLException.class).when(st).close();
|
||||
|
||||
// when
|
||||
SqlDataSourceUtils.close(st);
|
||||
|
||||
// then
|
||||
verify(logger).warning(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCloseResultSet() throws SQLException {
|
||||
// given
|
||||
ResultSet rs = mock(ResultSet.class);
|
||||
|
||||
// when
|
||||
SqlDataSourceUtils.close(rs);
|
||||
|
||||
// then
|
||||
verify(rs).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleExceptionFromResultSet() throws SQLException {
|
||||
// given
|
||||
ResultSet rs = mock(ResultSet.class);
|
||||
doThrow(SQLException.class).when(rs).close();
|
||||
|
||||
// when
|
||||
SqlDataSourceUtils.close(rs);
|
||||
|
||||
// then
|
||||
verify(logger).warning(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCloseConnection() throws SQLException {
|
||||
// given
|
||||
Connection con = mock(Connection.class);
|
||||
|
||||
// when
|
||||
SqlDataSourceUtils.close(con);
|
||||
|
||||
// then
|
||||
verify(con).close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleExceptionFromConnection() throws SQLException {
|
||||
// given
|
||||
Connection con = mock(Connection.class);
|
||||
doThrow(SQLException.class).when(con).close();
|
||||
|
||||
// when
|
||||
SqlDataSourceUtils.close(con);
|
||||
|
||||
// then
|
||||
verify(logger).warning(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullArgument() {
|
||||
// given / when
|
||||
SqlDataSourceUtils.close((Statement) null);
|
||||
SqlDataSourceUtils.close((ResultSet) null);
|
||||
SqlDataSourceUtils.close((Connection) null);
|
||||
|
||||
// then - nothing happens
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user