From 4ecc5215bda6724115abf31c793b2b9ece3641e1 Mon Sep 17 00:00:00 2001 From: strangelookingnerd <49242855+strangelookingnerd@users.noreply.github.com> Date: Wed, 20 Nov 2024 19:49:20 +0100 Subject: [PATCH] Migrate tests to JUnit5 (#324) --- pom.xml | 8 +- .../commons/dbutils/AsyncQueryRunnerTest.java | 89 ++++---- .../dbutils/BaseResultSetHandlerTest.java | 5 +- .../apache/commons/dbutils/BaseTestCase.java | 22 +- .../dbutils/BasicRowProcessorTest.java | 19 +- .../commons/dbutils/BeanProcessorTest.java | 26 ++- .../apache/commons/dbutils/DbUtilsTest.java | 20 +- .../dbutils/GenerousBeanProcessorTest.java | 16 +- .../commons/dbutils/OutParameterTest.java | 14 +- .../commons/dbutils/ProxyFactoryTest.java | 11 + .../commons/dbutils/QueryLoaderTest.java | 11 +- .../commons/dbutils/QueryRunnerTest.java | 200 ++++++++++-------- .../dbutils/ResultSetIteratorTest.java | 9 +- .../commons/dbutils/ServiceLoaderTest.java | 8 +- .../dbutils/StatementConfigurationTest.java | 8 +- .../dbutils/handlers/ArrayHandlerTest.java | 6 + .../handlers/ArrayListHandlerTest.java | 8 + .../dbutils/handlers/BeanHandlerTest.java | 9 + .../dbutils/handlers/BeanListHandlerTest.java | 11 + .../dbutils/handlers/BeanMapHandlerTest.java | 22 +- .../handlers/ColumnListHandlerTest.java | 9 + .../dbutils/handlers/KeyedHandlerTest.java | 9 + .../dbutils/handlers/MapHandlerTest.java | 7 + .../dbutils/handlers/MapListHandlerTest.java | 8 + .../dbutils/handlers/ScalarHandlerTest.java | 9 + .../columns/AbstractTestColumnHandler.java | 6 +- .../columns/BooleanColumnHandlerTest.java | 10 +- .../columns/ByteColumnHandlerTest.java | 10 +- .../columns/DoubleColumnHandlerTest.java | 10 +- .../columns/FloatColumnHandlerTest.java | 10 +- .../columns/IntegerColumnHandlerTest.java | 12 +- .../columns/LongColumnHandlerTest.java | 10 +- .../columns/SQLXMLColumnHandlerTest.java | 10 +- .../columns/ShortColumnHandlerTest.java | 10 +- .../columns/StringColumnHandlerTest.java | 10 +- .../columns/TimestampColumnHandlerTest.java | 10 +- .../properties/DatePropertyHandlerTest.java | 12 +- .../properties/PropertyHandlerTest.java | 8 +- .../StringEnumPropertyHandlerTest.java | 10 +- .../wrappers/SqlNullCheckedResultSetTest.java | 55 ++++- .../wrappers/StringTrimmedResultSetTest.java | 9 +- 41 files changed, 501 insertions(+), 265 deletions(-) diff --git a/pom.xml b/pom.xml index 053c57c2..84a6cca5 100644 --- a/pom.xml +++ b/pom.xml @@ -44,13 +44,13 @@ - org.junit.vintage - junit-vintage-engine + org.junit.jupiter + junit-jupiter test org.mockito - mockito-core + mockito-junit-jupiter 5.14.1 test @@ -324,7 +324,7 @@ ggregory at apache.org https://www.garygregory.com The Apache Software Foundation - https://www.apache.org/ + https://www.apache.org/ PMC Member diff --git a/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java index acc317e2..558871b4 100644 --- a/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java +++ b/src/test/java/org/apache/commons/dbutils/AsyncQueryRunnerTest.java @@ -16,7 +16,8 @@ */ package org.apache.commons.dbutils; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; @@ -38,29 +39,29 @@ import javax.sql.DataSource; import org.apache.commons.dbutils.handlers.ArrayHandler; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; @SuppressWarnings("boxing") // test code -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class AsyncQueryRunnerTest { private AsyncQueryRunner runner; private ArrayHandler handler; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private DataSource dataSource; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private Connection conn; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private PreparedStatement prepStmt; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private Statement stmt; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private ParameterMetaData meta; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private ResultSet results; // helper method for calling batch when an exception is expected @@ -255,7 +256,7 @@ private void callUpdateWithException(final Object... params) throws Exception { } } - @Before + @BeforeEach public void setUp() throws Exception { when(dataSource.getConnection()).thenReturn(conn); @@ -282,10 +283,12 @@ public void testAddBatchException() throws Exception { // // Random tests // - @Test(expected = ExecutionException.class) + @Test public void testBadPrepareConnection() throws Exception { - runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1)); - runner.update("update blah set unit = test").get(); + assertThrows(ExecutionException.class, () -> { + runner = new AsyncQueryRunner(Executors.newFixedThreadPool(1)); + runner.update("update blah set unit = test").get(); + }); } @Test @@ -397,37 +400,45 @@ public void testNoParamsUpdate() throws Exception { callGoodUpdate(); } - @Test(expected = ExecutionException.class) + @Test public void testNullConnectionBatch() throws Exception { - final String[][] params = { { "unit", "unit" }, { "test", "test" } }; + assertThrows(ExecutionException.class, () -> { + final String[][] params = {{"unit", "unit"}, {"test", "test"}}; - when(dataSource.getConnection()).thenReturn(null); + when(dataSource.getConnection()).thenReturn(null); - runner.batch("select * from blah where ? = ?", params).get(); + runner.batch("select * from blah where ? = ?", params).get(); + }); } - @Test(expected = ExecutionException.class) + @Test public void testNullConnectionQuery() throws Exception { - when(dataSource.getConnection()).thenReturn(null); + assertThrows(ExecutionException.class, () -> { + when(dataSource.getConnection()).thenReturn(null); - runner.query("select * from blah where ? = ?", handler, "unit", "test").get(); + runner.query("select * from blah where ? = ?", handler, "unit", "test").get(); + }); } - @Test(expected = ExecutionException.class) + @Test public void testNullConnectionUpdate() throws Exception { - when(dataSource.getConnection()).thenReturn(null); + assertThrows(ExecutionException.class, () -> { + when(dataSource.getConnection()).thenReturn(null); - runner.update("select * from blah where ? = ?", "unit", "test").get(); + runner.update("select * from blah where ? = ?", "unit", "test").get(); + }); } - @Test(expected = ExecutionException.class) + @Test public void testNullHandlerQuery() throws Exception { - runner.query("select * from blah where ? = ?", null).get(); + assertThrows(ExecutionException.class, () -> + runner.query("select * from blah where ? = ?", null).get()); } - @Test(expected = ExecutionException.class) + @Test public void testNullParamsArgBatch() throws Exception { - runner.batch("select * from blah where ? = ?", null).get(); + assertThrows(ExecutionException.class, () -> + runner.batch("select * from blah where ? = ?", null).get()); } @Test @@ -437,21 +448,25 @@ public void testNullParamsBatch() throws Exception { callGoodBatch(params); } - @Test(expected = ExecutionException.class) + @Test public void testNullSqlBatch() throws Exception { - final String[][] params = { { "unit", "unit" }, { "test", "test" } }; + assertThrows(ExecutionException.class, () -> { + final String[][] params = {{"unit", "unit"}, {"test", "test"}}; - runner.batch(null, params).get(); + runner.batch(null, params).get(); + }); } - @Test(expected = ExecutionException.class) + @Test public void testNullSqlQuery() throws Exception { - runner.query(null, handler).get(); + assertThrows(ExecutionException.class, () -> + runner.query(null, handler).get()); } - @Test(expected = ExecutionException.class) + @Test public void testNullSqlUpdate() throws Exception { - runner.update(null).get(); + assertThrows(ExecutionException.class, () -> + runner.update(null).get()); } @Test diff --git a/src/test/java/org/apache/commons/dbutils/BaseResultSetHandlerTest.java b/src/test/java/org/apache/commons/dbutils/BaseResultSetHandlerTest.java index 0bc2b409..e36f0d3e 100644 --- a/src/test/java/org/apache/commons/dbutils/BaseResultSetHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/BaseResultSetHandlerTest.java @@ -16,13 +16,16 @@ */ package org.apache.commons.dbutils; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.sql.SQLException; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.Map; -import org.junit.Test; +import org.junit.jupiter.api.Test; public final class BaseResultSetHandlerTest extends BaseTestCase { diff --git a/src/test/java/org/apache/commons/dbutils/BaseTestCase.java b/src/test/java/org/apache/commons/dbutils/BaseTestCase.java index dbb36824..d1f903bc 100644 --- a/src/test/java/org/apache/commons/dbutils/BaseTestCase.java +++ b/src/test/java/org/apache/commons/dbutils/BaseTestCase.java @@ -16,18 +16,22 @@ */ package org.apache.commons.dbutils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; + import java.math.BigInteger; import java.sql.ResultSet; import java.sql.ResultSetMetaData; import java.sql.Timestamp; import java.util.Date; -import junit.framework.TestCase; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * BaseTestCase is the base class for all test cases as well as the "all tests" runner. */ -public class BaseTestCase extends TestCase { +public class BaseTestCase { private static final String[] columnNames = { "one", "two", "three", "notInBean", "intTest", "integerTest", "nullObjectTest", "nullPrimitiveTest", "notDate", "columnProcessorDoubleTest", null }; @@ -94,25 +98,25 @@ public void setResultSet(final ResultSet resultSet) { /** * This is called before each test method so ResultSet will be fresh each time. * - * @see junit.framework.TestCase#setUp() + * @see org.junit.jupiter.api.BeforeEach */ - @Override + @BeforeEach protected void setUp() throws Exception { - super.setUp(); - rs = createMockResultSet(); emptyResultSet = MockResultSet.create(metaData, null); } // Test which allows Eclipse to be run on full project (avoids no tests found) // check that the rows are valid for the column definition + @Test public void testCheckDataSizes() { - assertEquals("Row 1 must contain correct number of columns", columnNames.length, row1.length); - assertEquals("Row 1 must contain correct number of columns", columnNames.length, row2.length); + assertEquals(columnNames.length, row1.length, "Row 1 must contain correct number of columns"); + assertEquals(columnNames.length, row2.length, "Row 1 must contain correct number of columns"); } + @Test public void testResultSets() throws Exception { - assertFalse("emptyResultSet should be empty", emptyResultSet.next()); + assertFalse(emptyResultSet.next(), "emptyResultSet should be empty"); // fails in SqlNullCheckedResultSetTest assertTrue("rs should not be empty", rs.next()); } } diff --git a/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java b/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java index 8cddd01a..4df7f96b 100644 --- a/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java +++ b/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java @@ -16,6 +16,13 @@ */ package org.apache.commons.dbutils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.sql.SQLException; import java.text.DateFormat; import java.text.ParseException; @@ -26,6 +33,8 @@ import java.util.Locale; import java.util.Map; +import org.junit.jupiter.api.Test; + /** * Test the BasicRowProcessor class. */ @@ -38,6 +47,7 @@ public class BasicRowProcessorTest extends BaseTestCase { */ private static final DateFormat datef = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); + @Test public void testPutAllContainsKeyAndRemove() throws Exception { final Map test = new HashMap<>(3); test.put("fiRst", "thing"); @@ -54,6 +64,7 @@ public void testPutAllContainsKeyAndRemove() throws Exception { assertFalse(brpMap.containsKey("first")); } + @Test public void testToArray() throws SQLException { Object[] a; @@ -75,6 +86,7 @@ public void testToArray() throws SQLException { assertFalse(getResultSet().next()); } + @Test public void testToBean() throws SQLException, ParseException { assertTrue(getResultSet().next()); @@ -97,13 +109,14 @@ public void testToBean() throws SQLException, ParseException { assertEquals(0, row.getNullPrimitiveTest()); // test date -> string handling assertNotNull(row.getNotDate()); - assertTrue(!"not a date".equals(row.getNotDate())); + assertNotEquals("not a date", row.getNotDate()); assertTrue(row.getNotDate().endsWith("789456123")); assertFalse(getResultSet().next()); } + @Test public void testToBeanList() throws SQLException, ParseException { final List list = processor.toBeanList(getResultSet(), TestBean.class); @@ -128,10 +141,11 @@ public void testToBeanList() throws SQLException, ParseException { assertEquals(0, b.getNullPrimitiveTest()); // test date -> string handling assertNotNull(b.getNotDate()); - assertTrue(!"not a date".equals(b.getNotDate())); + assertNotEquals("not a date", b.getNotDate()); assertTrue(b.getNotDate().endsWith("789456123")); } + @Test public void testToMap() throws SQLException { assertTrue(getResultSet().next()); @@ -152,6 +166,7 @@ public void testToMap() throws SQLException { assertFalse(getResultSet().next()); } + @Test public void testToMapOrdering() throws SQLException { assertTrue(getResultSet().next()); diff --git a/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java b/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java index fb25409e..819ef858 100644 --- a/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java +++ b/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java @@ -16,7 +16,11 @@ */ package org.apache.commons.dbutils; -import static org.junit.Assert.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.beans.Introspector; import java.beans.PropertyDescriptor; @@ -28,6 +32,8 @@ import java.util.List; import java.util.Map; +import org.junit.jupiter.api.Test; + public class BeanProcessorTest extends BaseTestCase { private static final class IndexedPropertyTestClass { @@ -188,6 +194,7 @@ public void setTestField(final int idx, final Integer testField) { private static final BeanProcessor beanProc = new BeanProcessor(); + @Test public void testCheckAnnotationOnMissingReadMethod() throws Exception { final String[] colNames = { "testField" }; final ResultSetMetaData metaData = MockResultSetMetaData.create(colNames); @@ -199,7 +206,7 @@ public void testCheckAnnotationOnMissingReadMethod() throws Exception { assertTrue(rs.next()); TestNoGetter testCls = new TestNoGetter(); testCls = beanProc.populateBean(rs, testCls); - assertEquals(testCls.testField, "first"); + assertEquals("first", testCls.testField); } /** @@ -209,6 +216,7 @@ public void testCheckAnnotationOnMissingReadMethod() throws Exception { * @throws Exception * @see DBUTILS-150 */ + @Test public void testIndexedPropertyDescriptor() throws Exception { final String[] colNames = { "name", "things", "stuff" }; final ResultSetMetaData metaData = MockResultSetMetaData.create(colNames); @@ -227,6 +235,7 @@ public void testIndexedPropertyDescriptor() throws Exception { assertArrayEquals(stuff.toArray(), testCls.getStuff().toArray()); } + @Test public void testMapColumnToAnnotationField() throws Exception { final String[] columnNames = { "test", "test", "three_" }; final String[] columnLabels = { "one", "two", null }; @@ -239,6 +248,7 @@ public void testMapColumnToAnnotationField() throws Exception { } } + @Test public void testMapColumnToProperties() throws Exception { final String[] columnNames = { "test", "test", "three" }; final String[] columnLabels = { "one", "two", null }; @@ -251,6 +261,7 @@ public void testMapColumnToProperties() throws Exception { } } + @Test public void testMapColumnToPropertiesWithOverrides() throws Exception { final Map columnToPropertyOverrides = new HashMap<>(); columnToPropertyOverrides.put("five", "four"); @@ -266,37 +277,40 @@ public void testMapColumnToPropertiesWithOverrides() throws Exception { } } + @Test public void testProcessWithPopulateBean() throws SQLException { TestBean b = new TestBean(); final ResultSet rs = getResultSet(); assertTrue(rs.next()); b = beanProc.populateBean(rs, b); assertEquals(13.0, b.getColumnProcessorDoubleTest(), 0); - assertEquals(b.getThree(), TestBean.Ordinal.THREE); + assertEquals(TestBean.Ordinal.THREE, b.getThree()); assertTrue(rs.next()); b = beanProc.populateBean(rs, b); assertEquals(13.0, b.getColumnProcessorDoubleTest(), 0); - assertEquals(b.getThree(), TestBean.Ordinal.SIX); + assertEquals(TestBean.Ordinal.SIX, b.getThree()); assertFalse(rs.next()); } + @Test public void testProcessWithToBean() throws SQLException { final ResultSet rs = getResultSet(); assertTrue(rs.next()); TestBean b = beanProc.toBean(rs, TestBean.class); assertEquals(13.0, b.getColumnProcessorDoubleTest(), 0); - assertEquals(b.getThree(), TestBean.Ordinal.THREE); + assertEquals(TestBean.Ordinal.THREE, b.getThree()); assertTrue(rs.next()); b = beanProc.toBean(rs, TestBean.class); assertEquals(13.0, b.getColumnProcessorDoubleTest(), 0); - assertEquals(b.getThree(), TestBean.Ordinal.SIX); + assertEquals(TestBean.Ordinal.SIX, b.getThree()); assertFalse(rs.next()); } + @Test public void testWrongSetterParamCount() throws Exception { final String[] colNames = { "testField" }; final ResultSetMetaData metaData = MockResultSetMetaData.create(colNames); diff --git a/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java b/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java index 7f8f6384..69e82e95 100644 --- a/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java +++ b/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java @@ -16,8 +16,8 @@ */ package org.apache.commons.dbutils; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; @@ -30,22 +30,24 @@ import java.sql.Statement; import java.util.Properties; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; public class DbUtilsTest { - public static class DriverProxyTest { - private static final Driver mockedDriver = mock(Driver.class); + @Nested + public class DriverProxyTest { + private final Driver mockedDriver = mock(Driver.class); private DbUtils.DriverProxy proxy; - @Before + @BeforeEach public void setUp() { proxy = new DbUtils.DriverProxy(mockedDriver); } - @After + @AfterEach public void tearDown() { reset(mockedDriver); } diff --git a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java b/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java index 9c1bb4fe..45943f20 100644 --- a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java +++ b/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java @@ -16,20 +16,20 @@ */ package org.apache.commons.dbutils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.mockito.Mockito.when; import java.beans.PropertyDescriptor; import java.sql.ResultSetMetaData; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class GenerousBeanProcessorTest { static class TestBean { @@ -68,7 +68,7 @@ public void setTwo(final int two) { private PropertyDescriptor[] propDescriptors; - @Before + @BeforeEach public void setUp() throws Exception { propDescriptors = new PropertyDescriptor[3]; diff --git a/src/test/java/org/apache/commons/dbutils/OutParameterTest.java b/src/test/java/org/apache/commons/dbutils/OutParameterTest.java index de0b0bdc..cf00f4a5 100644 --- a/src/test/java/org/apache/commons/dbutils/OutParameterTest.java +++ b/src/test/java/org/apache/commons/dbutils/OutParameterTest.java @@ -17,7 +17,7 @@ package org.apache.commons.dbutils; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.times; @@ -27,13 +27,13 @@ import java.sql.CallableStatement; import java.sql.Types; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class OutParameterTest { private static final int INDEX = 2; private static final int VALUE = 42; @@ -43,7 +43,7 @@ public class OutParameterTest { private OutParameter parameter; - @Before + @BeforeEach public void setUp() throws Exception { parameter = new OutParameter<>(Types.INTEGER, Number.class); } diff --git a/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java b/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java index 1353a7ee..21a2e007 100644 --- a/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java +++ b/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java @@ -16,8 +16,12 @@ */ package org.apache.commons.dbutils; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import java.lang.reflect.InvocationHandler; +import org.junit.jupiter.api.Test; + /** * ProxyFactoryTest performs simple type checking on proxy objects returned from a ProxyFactory. */ @@ -25,30 +29,37 @@ public class ProxyFactoryTest extends BaseTestCase { private static final InvocationHandler stub = (proxy, method, args) -> null; + @Test public void testCreateCallableStatement() { assertNotNull(ProxyFactory.instance().createCallableStatement(stub)); } + @Test public void testCreateConnection() { assertNotNull(ProxyFactory.instance().createConnection(stub)); } + @Test public void testCreateDriver() { assertNotNull(ProxyFactory.instance().createDriver(stub)); } + @Test public void testCreatePreparedStatement() { assertNotNull(ProxyFactory.instance().createPreparedStatement(stub)); } + @Test public void testCreateResultSet() { assertNotNull(ProxyFactory.instance().createResultSet(stub)); } + @Test public void testCreateResultSetMetaData() { assertNotNull(ProxyFactory.instance().createResultSetMetaData(stub)); } + @Test public void testCreateStatement() { assertNotNull(ProxyFactory.instance().createStatement(stub)); } diff --git a/src/test/java/org/apache/commons/dbutils/QueryLoaderTest.java b/src/test/java/org/apache/commons/dbutils/QueryLoaderTest.java index 82f096f3..3986fdf9 100644 --- a/src/test/java/org/apache/commons/dbutils/QueryLoaderTest.java +++ b/src/test/java/org/apache/commons/dbutils/QueryLoaderTest.java @@ -16,9 +16,16 @@ */ package org.apache.commons.dbutils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.fail; + import java.io.IOException; import java.util.Map; +import org.junit.jupiter.api.Test; + /** * QueryLoaderTest */ @@ -26,6 +33,7 @@ public class QueryLoaderTest extends BaseTestCase { private static final String QUERIES = "/org/apache/commons/dbutils/TestQueries.properties"; + @Test public void testLoad() throws IOException { final QueryLoader loader = QueryLoader.instance(); final Map q = loader.load(QUERIES); @@ -35,9 +43,10 @@ public void testLoad() throws IOException { loader.unload(QUERIES); final Map q3 = loader.load(QUERIES); - assertTrue(q != q3); // pointer comparison should return false + assertNotSame(q, q3); // pointer comparison should return false } + @Test public void testLoadThrowsIllegalArgumentException() throws IOException { final QueryLoader queryLoader = QueryLoader.instance(); diff --git a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java index eaaa1479..59089c23 100644 --- a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java +++ b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java @@ -16,7 +16,9 @@ */ package org.apache.commons.dbutils; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; @@ -42,17 +44,16 @@ import org.apache.commons.dbutils.handlers.ArrayHandler; import org.apache.commons.dbutils.handlers.ScalarHandler; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.invocation.InvocationOnMock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.stubbing.Answer; @SuppressWarnings("boxing") // test code -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class QueryRunnerTest { // // Random tests @@ -91,28 +92,28 @@ public void setC(final String c) { private ArrayHandler handler; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private DataSource dataSource; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private Connection conn; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private PreparedStatement prepStmt; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private Statement stmt; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private CallableStatement call; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private ParameterMetaData meta; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private ResultSet results; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private ResultSetMetaData resultsMeta; // @@ -212,7 +213,7 @@ private void callGoodExecute() throws Exception { when(meta.getParameterCount()).thenReturn(2); int result = runner.execute("{call my_proc(?, ?)}", "unit", "test"); - Assert.assertEquals(3, result); + assertEquals(3, result); verify(call, times(1)).execute(); verify(call, times(1)).close(); // make sure we closed the statement @@ -222,7 +223,7 @@ private void callGoodExecute() throws Exception { when(meta.getParameterCount()).thenReturn(0); result = runner.execute("{call my_proc()}"); - Assert.assertEquals(3, result); + assertEquals(3, result); verify(call, times(2)).execute(); verify(call, times(2)).close(); // make sure we closed the statement @@ -235,8 +236,8 @@ private void callGoodExecute() throws Exception { new OutParameter<>(Types.INTEGER, Integer.class); result = runner.execute("{?= call my_proc()}", intParam); - Assert.assertEquals(42, intParam.getValue().intValue()); - Assert.assertEquals(3, result); + assertEquals(42, intParam.getValue().intValue()); + assertEquals(3, result); verify(call, times(3)).execute(); verify(call, times(3)).close(); // make sure we closed the statement @@ -248,8 +249,8 @@ private void callGoodExecute() throws Exception { intParam.setValue(null); result = runner.execute("{?= call my_proc(?, ?)}", intParam, "unit", "test"); - Assert.assertEquals(4242, intParam.getValue().intValue()); - Assert.assertEquals(3, result); + assertEquals(4242, intParam.getValue().intValue()); + assertEquals(3, result); verify(call, times(4)).execute(); verify(call, times(4)).close(); // make sure we closed the statement @@ -264,9 +265,9 @@ private void callGoodExecute() throws Exception { new OutParameter<>(Types.VARCHAR, String.class, "in"); result = runner.execute("{?= call my_proc(?, ?)}", intParam, "test", stringParam); - Assert.assertEquals(24, intParam.getValue().intValue()); - Assert.assertEquals("out", stringParam.getValue()); - Assert.assertEquals(3, result); + assertEquals(24, intParam.getValue().intValue()); + assertEquals("out", stringParam.getValue()); + assertEquals(3, result); verify(call, times(5)).execute(); verify(call, times(5)).close(); // make sure we closed the statement @@ -283,7 +284,7 @@ private void callGoodExecute(final Connection conn) throws Exception { when(meta.getParameterCount()).thenReturn(2); int result = runner.execute(conn, "{call my_proc(?, ?)}", "unit", "test"); - Assert.assertEquals(3, result); + assertEquals(3, result); verify(call, times(1)).execute(); verify(call, times(1)).close(); // make sure we closed the statement @@ -293,7 +294,7 @@ private void callGoodExecute(final Connection conn) throws Exception { when(meta.getParameterCount()).thenReturn(0); result = runner.execute(conn, "{call my_proc()}"); - Assert.assertEquals(3, result); + assertEquals(3, result); verify(call, times(2)).execute(); verify(call, times(2)).close(); // make sure we closed the statement @@ -306,8 +307,8 @@ private void callGoodExecute(final Connection conn) throws Exception { new OutParameter<>(Types.INTEGER, Integer.class); result = runner.execute(conn, "{?= call my_proc()}", intParam); - Assert.assertEquals(42, intParam.getValue().intValue()); - Assert.assertEquals(3, result); + assertEquals(42, intParam.getValue().intValue()); + assertEquals(3, result); verify(call, times(3)).execute(); verify(call, times(3)).close(); // make sure we closed the statement @@ -319,8 +320,8 @@ private void callGoodExecute(final Connection conn) throws Exception { intParam.setValue(null); result = runner.execute(conn, "{?= call my_proc(?, ?)}", intParam, "unit", "test"); - Assert.assertEquals(4242, intParam.getValue().intValue()); - Assert.assertEquals(3, result); + assertEquals(4242, intParam.getValue().intValue()); + assertEquals(3, result); verify(call, times(4)).execute(); verify(call, times(4)).close(); // make sure we closed the statement @@ -335,9 +336,9 @@ private void callGoodExecute(final Connection conn) throws Exception { new OutParameter<>(Types.VARCHAR, String.class, "in"); result = runner.execute(conn, "{?= call my_proc(?, ?)}", intParam, "test", stringParam); - Assert.assertEquals(24, intParam.getValue().intValue()); - Assert.assertEquals("out", stringParam.getValue()); - Assert.assertEquals(3, result); + assertEquals(24, intParam.getValue().intValue()); + assertEquals("out", stringParam.getValue()); + assertEquals(3, result); verify(call, times(5)).execute(); verify(call, times(5)).close(); // make sure we closed the statement @@ -371,7 +372,7 @@ private void callGoodExecuteWithResultSet() throws Exception { new OutParameter<>(Types.INTEGER, Integer.class); runner.execute("{?= call my_proc()}", handler, intParam); - Assert.assertEquals(42, intParam.getValue().intValue()); + assertEquals(42, intParam.getValue().intValue()); verify(call, times(3)).execute(); verify(results, times(3)).close(); @@ -384,7 +385,7 @@ private void callGoodExecuteWithResultSet() throws Exception { intParam.setValue(null); runner.execute("{?= call my_proc(?, ?)}", handler, intParam, "unit", "test"); - Assert.assertEquals(4242, intParam.getValue().intValue()); + assertEquals(4242, intParam.getValue().intValue()); verify(call, times(4)).execute(); verify(results, times(4)).close(); @@ -400,8 +401,8 @@ private void callGoodExecuteWithResultSet() throws Exception { new OutParameter<>(Types.VARCHAR, String.class, "in"); runner.execute("{?= call my_proc(?, ?)}", handler, intParam, "test", stringParam); - Assert.assertEquals(24, intParam.getValue().intValue()); - Assert.assertEquals("out", stringParam.getValue()); + assertEquals(24, intParam.getValue().intValue()); + assertEquals("out", stringParam.getValue()); verify(call, times(5)).execute(); verify(results, times(5)).close(); @@ -436,7 +437,7 @@ private void callGoodExecuteWithResultSet(final Connection conn) throws Exceptio new OutParameter<>(Types.INTEGER, Integer.class); runner.execute(conn, "{?= call my_proc()}", handler, intParam); - Assert.assertEquals(42, intParam.getValue().intValue()); + assertEquals(42, intParam.getValue().intValue()); verify(call, times(3)).execute(); verify(results, times(3)).close(); @@ -449,7 +450,7 @@ private void callGoodExecuteWithResultSet(final Connection conn) throws Exceptio intParam.setValue(null); runner.execute(conn, "{?= call my_proc(?, ?)}", handler, intParam, "unit", "test"); - Assert.assertEquals(4242, intParam.getValue().intValue()); + assertEquals(4242, intParam.getValue().intValue()); verify(call, times(4)).execute(); verify(results, times(4)).close(); @@ -465,8 +466,8 @@ private void callGoodExecuteWithResultSet(final Connection conn) throws Exceptio new OutParameter<>(Types.VARCHAR, String.class, "in"); runner.execute(conn, "{?= call my_proc(?, ?)}", handler, intParam, "test", stringParam); - Assert.assertEquals(24, intParam.getValue().intValue()); - Assert.assertEquals("out", stringParam.getValue()); + assertEquals(24, intParam.getValue().intValue()); + assertEquals("out", stringParam.getValue()); verify(call, times(5)).execute(); verify(results, times(5)).close(); @@ -618,7 +619,7 @@ private void callUpdateWithException(final Object... params) throws Exception { } } - @Before + @BeforeEach public void setUp() throws Exception { when(dataSource.getConnection()).thenReturn(conn); @@ -649,10 +650,12 @@ public void testAddBatchExceptionOnAdd() throws Exception { callBatchWithException("select * from blah where ? = ?", params); } - @Test(expected = SQLException.class) + @Test public void testBadPrepareConnection() throws Exception { - runner = new QueryRunner(); - runner.update("update blah set unit = test"); + assertThrows(SQLException.class, () -> { + runner = new QueryRunner(); + runner.update("update blah set unit = test"); + }); } @Test @@ -694,7 +697,7 @@ public Boolean answer(final InvocationOnMock invocation) { when(meta.getParameterCount()).thenReturn(0); final List objects = runner.execute("{call my_proc()}", handler); - Assert.assertEquals(3, objects.size()); + assertEquals(3, objects.size()); verify(call, times(1)).execute(); verify(results, times(3)).close(); verify(call, times(1)).close(); // make sure we closed the statement @@ -714,10 +717,12 @@ public void testFillStatementWithBean() throws Exception { runner.fillStatementWithBean(prepStmt, bean, "a", "b", "c"); } - @Test(expected = NullPointerException.class) + @Test public void testFillStatementWithBeanNullNames() throws Exception { - final MyBean bean = new MyBean(); - runner.fillStatementWithBean(prepStmt, bean, "a", "b", null); + assertThrows(NullPointerException.class, () -> { + final MyBean bean = new MyBean(); + runner.fillStatementWithBean(prepStmt, bean, "a", "b", null); + }); } @Test @@ -766,7 +771,7 @@ public void testGoodBatchInsert() throws Exception { verify(prepStmt, times(1)).close(); // make sure we closed the statement verify(conn, times(1)).close(); // make sure we closed the connection - Assert.assertEquals(2, generatedKeys.size()); + assertEquals(2, generatedKeys.size()); } @Test @@ -827,7 +832,7 @@ public void testGoodInsert() throws Exception { verify(prepStmt, times(1)).close(); // make sure we closed the statement verify(conn, times(1)).close(); // make sure we closed the connection - Assert.assertEquals(1L, generatedKey.longValue()); + assertEquals(1L, generatedKey.longValue()); } @Test @@ -884,67 +889,82 @@ public void testNoParamsUpdate() throws Exception { callGoodUpdate(); } - @Test(expected = SQLException.class) + @Test public void testNullConnectionBatch() throws Exception { - final String[][] params = { { "unit", "unit" }, { "test", "test" } }; + assertThrows(SQLException.class, () -> { + final String[][] params = {{"unit", "unit"}, {"test", "test"}}; - when(dataSource.getConnection()).thenReturn(null); + when(dataSource.getConnection()).thenReturn(null); - runner.batch("select * from blah where ? = ?", params); + runner.batch("select * from blah where ? = ?", params); + }); } - @Test(expected = SQLException.class) + @Test public void testNullConnectionExecute() throws Exception { - when(dataSource.getConnection()).thenReturn(null); + assertThrows(SQLException.class, () -> { + when(dataSource.getConnection()).thenReturn(null); - runner.execute("{call my_proc(?, ?)}", "unit", "test"); + runner.execute("{call my_proc(?, ?)}", "unit", "test"); + }); } - @Test(expected = SQLException.class) + @Test public void testNullConnectionExecuteWithResultSet() throws Exception { - when(dataSource.getConnection()).thenReturn(null); + assertThrows(SQLException.class, () -> { + when(dataSource.getConnection()).thenReturn(null); - runner.execute("{call my_proc(?, ?)}", handler, "unit", "test"); + runner.execute("{call my_proc(?, ?)}", handler, "unit", "test"); + }); } - @Test(expected = SQLException.class) + @Test public void testNullConnectionQuery() throws Exception { - when(dataSource.getConnection()).thenReturn(null); + assertThrows(SQLException.class, () -> { + when(dataSource.getConnection()).thenReturn(null); - runner.query("select * from blah where ? = ?", handler, "unit", "test"); + runner.query("select * from blah where ? = ?", handler, "unit", "test"); + }); } - @Test(expected = SQLException.class) + @Test public void testNullConnectionUpdate() throws Exception { - when(dataSource.getConnection()).thenReturn(null); + assertThrows(SQLException.class, () -> { + when(dataSource.getConnection()).thenReturn(null); - runner.update("select * from blah where ? = ?", "unit", "test"); + runner.update("select * from blah where ? = ?", "unit", "test"); + }); } - @Test(expected = SQLException.class) + @Test public void testNullHandlerExecute() throws Exception { - when(meta.getParameterCount()).thenReturn(2); + assertThrows(SQLException.class, () -> { + when(meta.getParameterCount()).thenReturn(2); - runner.execute("{call my_proc(?, ?)}"); + runner.execute("{call my_proc(?, ?)}"); + }); } - @Test(expected = SQLException.class) + @Test public void testNullHandlerExecuteWithResultSet() throws Exception { - runner.execute("{call my_proc(?, ?)}", (ResultSetHandler) null); + assertThrows(SQLException.class, () -> + runner.execute("{call my_proc(?, ?)}", (ResultSetHandler) null)); } - @Test(expected = SQLException.class) + @Test public void testNullHandlerQuery() throws Exception { - runner.query("select * from blah where ? = ?", null); + assertThrows(SQLException.class, () -> + runner.query("select * from blah where ? = ?", null)); } // // Execute with ResultSetHandler // - @Test(expected = SQLException.class) + @Test public void testNullParamsArgBatch() throws Exception { - runner.batch("select * from blah where ? = ?", null); + assertThrows(SQLException.class, () -> + runner.batch("select * from blah where ? = ?", null)); } @Test @@ -954,31 +974,37 @@ public void testNullParamsBatch() throws Exception { callGoodBatch(params); } - @Test(expected = SQLException.class) + @Test public void testNullSqlBatch() throws Exception { - final String[][] params = { { "unit", "unit" }, { "test", "test" } }; + assertThrows(SQLException.class, () -> { + final String[][] params = {{"unit", "unit"}, {"test", "test"}}; - runner.batch(null, params); + runner.batch(null, params); + }); } - @Test(expected = SQLException.class) + @Test public void testNullSqlExecute() throws Exception { - runner.execute(null); + assertThrows(SQLException.class, () -> + runner.execute(null)); } - @Test(expected = SQLException.class) + @Test public void testNullSqlExecuteWithResultSet() throws Exception { - runner.execute(null, handler); + assertThrows(SQLException.class, () -> + runner.execute(null, handler)); } - @Test(expected = SQLException.class) + @Test public void testNullSqlQuery() throws Exception { - runner.query(null, handler); + assertThrows(SQLException.class, () -> + runner.query(null, handler)); } - @Test(expected = SQLException.class) + @Test public void testNullSqlUpdate() throws Exception { - runner.update(null); + assertThrows(SQLException.class, () -> + runner.update(null)); } @Test diff --git a/src/test/java/org/apache/commons/dbutils/ResultSetIteratorTest.java b/src/test/java/org/apache/commons/dbutils/ResultSetIteratorTest.java index 425017ea..d2de5de5 100644 --- a/src/test/java/org/apache/commons/dbutils/ResultSetIteratorTest.java +++ b/src/test/java/org/apache/commons/dbutils/ResultSetIteratorTest.java @@ -16,13 +16,17 @@ */ package org.apache.commons.dbutils; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import java.sql.ResultSet; import java.sql.SQLException; import java.util.Iterator; -import org.junit.Test; +import org.junit.jupiter.api.Test; /** * ResultSetIteratorTest @@ -38,6 +42,7 @@ public void testCreatesResultSetIteratorTakingThreeArgumentsAndCallsRemove() { } + @Test public void testNext() { final Iterator iter = new ResultSetIterator(getResultSet()); @@ -58,7 +63,7 @@ public void testNext() { assertEquals("SIX", row[2]); assertFalse(iter.hasNext()); - assertTrue(iter.next().length == 0); + assertEquals(0, iter.next().length); } @Test diff --git a/src/test/java/org/apache/commons/dbutils/ServiceLoaderTest.java b/src/test/java/org/apache/commons/dbutils/ServiceLoaderTest.java index c73e01d4..f790e537 100644 --- a/src/test/java/org/apache/commons/dbutils/ServiceLoaderTest.java +++ b/src/test/java/org/apache/commons/dbutils/ServiceLoaderTest.java @@ -16,20 +16,20 @@ */ package org.apache.commons.dbutils; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ServiceLoader; import org.apache.commons.dbutils.handlers.columns.TestColumnHandler; import org.apache.commons.dbutils.handlers.properties.TestPropertyHandler; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class ServiceLoaderTest { private ServiceLoader columns; private ServiceLoader properties; - @Before + @BeforeEach public void setUp() { columns = ServiceLoader.load(ColumnHandler.class); properties = ServiceLoader.load(PropertyHandler.class); diff --git a/src/test/java/org/apache/commons/dbutils/StatementConfigurationTest.java b/src/test/java/org/apache/commons/dbutils/StatementConfigurationTest.java index 7f796766..17cf59e6 100644 --- a/src/test/java/org/apache/commons/dbutils/StatementConfigurationTest.java +++ b/src/test/java/org/apache/commons/dbutils/StatementConfigurationTest.java @@ -16,13 +16,13 @@ */ package org.apache.commons.dbutils; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.time.Duration; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class StatementConfigurationTest { /** diff --git a/src/test/java/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java index 0995cf76..108230fa 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java @@ -16,16 +16,21 @@ */ package org.apache.commons.dbutils.handlers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; + import java.sql.SQLException; import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ResultSetHandler; +import org.junit.jupiter.api.Test; /** * ArrayHandlerTest */ public class ArrayHandlerTest extends BaseTestCase { + @Test public void testEmptyResultSetHandle() throws SQLException { final ResultSetHandler h = new ArrayHandler(); final Object[] results = h.handle(getEmptyResultSet()); @@ -33,6 +38,7 @@ public void testEmptyResultSetHandle() throws SQLException { assertEquals(0, results.length); } + @Test public void testHandle() throws SQLException { final ResultSetHandler h = new ArrayHandler(); final Object[] results = h.handle(getResultSet()); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java index 95df585d..75efdd56 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java @@ -16,18 +16,25 @@ */ package org.apache.commons.dbutils.handlers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.sql.SQLException; import java.util.Iterator; import java.util.List; import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ResultSetHandler; +import org.junit.jupiter.api.Test; /** * ArrayListHandlerTest */ public class ArrayListHandlerTest extends BaseTestCase { + @Test public void testEmptyResultSetHandle() throws SQLException { final ResultSetHandler> h = new ArrayListHandler(); final List results = h.handle(getEmptyResultSet()); @@ -36,6 +43,7 @@ public void testEmptyResultSetHandle() throws SQLException { assertTrue(results.isEmpty()); } + @Test public void testHandle() throws SQLException { final ResultSetHandler> h = new ArrayListHandler(); final List results = h.handle(getResultSet()); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java index 63ab887f..e56fe64a 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java @@ -16,11 +16,16 @@ */ package org.apache.commons.dbutils.handlers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.sql.SQLException; import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ResultSetHandler; import org.apache.commons.dbutils.TestBean; +import org.junit.jupiter.api.Test; /** * BeanHandlerTest @@ -40,6 +45,7 @@ public interface SubTestBeanInterface { String getTwo(); } + @Test public void testEmptyResultSetHandle() throws SQLException { final ResultSetHandler h = new BeanHandler<>(TestBean.class); final TestBean results = h.handle(getEmptyResultSet()); @@ -47,6 +53,7 @@ public void testEmptyResultSetHandle() throws SQLException { assertNull(results); } + @Test public void testHandle() throws SQLException { final ResultSetHandler h = new BeanHandler<>(TestBean.class); final TestBean results = h.handle(getResultSet()); @@ -58,6 +65,7 @@ public void testHandle() throws SQLException { assertEquals("not set", results.getDoNotSet()); } + @Test public void testHandleToInterface() throws SQLException { final ResultSetHandler h = new BeanHandler<>(SubTestBean.class); final SubTestBeanInterface results = h.handle(getResultSet()); @@ -69,6 +77,7 @@ public void testHandleToInterface() throws SQLException { assertEquals("not set", results.getDoNotSet()); } + @Test public void testHandleToSuperClass() throws SQLException { final ResultSetHandler h = new BeanHandler<>(SubTestBean.class); final TestBean results = h.handle(getResultSet()); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java index 5b96cbad..85cb0b73 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java @@ -16,6 +16,12 @@ */ package org.apache.commons.dbutils.handlers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.sql.SQLException; import java.util.Iterator; import java.util.List; @@ -23,6 +29,7 @@ import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ResultSetHandler; import org.apache.commons.dbutils.TestBean; +import org.junit.jupiter.api.Test; /** * BeanListHandlerTest @@ -42,6 +49,7 @@ public interface SubTestBeanInterface { String getTwo(); } + @Test public void testEmptyResultSetHandle() throws SQLException { final ResultSetHandler> h = new BeanListHandler<>(TestBean.class); final List results = h.handle(getEmptyResultSet()); @@ -50,6 +58,7 @@ public void testEmptyResultSetHandle() throws SQLException { assertTrue(results.isEmpty()); } + @Test public void testHandle() throws SQLException { final ResultSetHandler> h = new BeanListHandler<>(TestBean.class); final List results = h.handle(getResultSet()); @@ -77,6 +86,7 @@ public void testHandle() throws SQLException { assertFalse(iter.hasNext()); } + @Test public void testHandleToInterface() throws SQLException { final ResultSetHandler> h = new BeanListHandler<>(SubTestBean.class); final List results = h.handle(getResultSet()); @@ -107,6 +117,7 @@ public void testHandleToInterface() throws SQLException { assertFalse(iter.hasNext()); } + @Test public void testHandleToSuperClass() throws SQLException { final ResultSetHandler> h = new BeanListHandler<>(SubTestBean.class); final List results = h.handle(getResultSet()); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java index 04d2e4ba..aaa9d526 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java @@ -16,8 +16,8 @@ */ package org.apache.commons.dbutils.handlers; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.when; import java.sql.ResultSet; @@ -26,22 +26,22 @@ import org.apache.commons.dbutils.RowProcessor; import org.apache.commons.dbutils.TestBean; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BeanMapHandlerTest { private BeanMapHandler bmh; private Map res; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private ResultSet rs; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private ResultSetMetaData rsmd; - @Mock + @Mock(strictness = Mock.Strictness.LENIENT) private RowProcessor rp; private void handle() throws Exception { @@ -49,7 +49,7 @@ private void handle() throws Exception { assertNotNull(res.get(Long.valueOf(23L))); } - @Before + @BeforeEach public void setUp() throws Exception { when(Boolean.valueOf(rs.next())).thenReturn(Boolean.TRUE, Boolean.FALSE); when(rs.getObject(1)).thenReturn(Long.valueOf(23L)); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/ColumnListHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/ColumnListHandlerTest.java index dfbf99ef..b0a4b391 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/ColumnListHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/ColumnListHandlerTest.java @@ -16,17 +16,23 @@ */ package org.apache.commons.dbutils.handlers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.sql.SQLException; import java.util.List; import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ResultSetHandler; +import org.junit.jupiter.api.Test; /** * ColumnListHandlerTest */ public class ColumnListHandlerTest extends BaseTestCase { + @Test public void testColumnIndexHandle() throws SQLException { final ResultSetHandler> h = new ColumnListHandler<>(2); final List results = h.handle(getResultSet()); @@ -38,6 +44,7 @@ public void testColumnIndexHandle() throws SQLException { assertEquals("5", results.get(1)); } + @Test public void testColumnNameHandle() throws SQLException { final ResultSetHandler> h = new ColumnListHandler<>("intTest"); final List results = h.handle(getResultSet()); @@ -49,6 +56,7 @@ public void testColumnNameHandle() throws SQLException { assertEquals(Integer.valueOf(3), results.get(1)); } + @Test public void testEmptyResultSetHandle() throws SQLException { final ResultSetHandler> h = new ColumnListHandler<>(); final List results = h.handle(getEmptyResultSet()); @@ -57,6 +65,7 @@ public void testEmptyResultSetHandle() throws SQLException { assertTrue(results.isEmpty()); } + @Test public void testHandle() throws SQLException { final ResultSetHandler> h = new ColumnListHandler<>(); final List results = h.handle(getResultSet()); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/KeyedHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/KeyedHandlerTest.java index a91f434b..d179fbe2 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/KeyedHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/KeyedHandlerTest.java @@ -16,6 +16,9 @@ */ package org.apache.commons.dbutils.handlers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import java.sql.SQLException; @@ -25,9 +28,11 @@ import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ResultSetHandler; import org.apache.commons.dbutils.RowProcessor; +import org.junit.jupiter.api.Test; public class KeyedHandlerTest extends BaseTestCase { + @Test public void testColumnIndexHandle() throws SQLException { final ResultSetHandler>> h = new KeyedHandler<>(2); final Map> results = h.handle(getResultSet()); @@ -49,6 +54,7 @@ public void testColumnIndexHandle() throws SQLException { assertEquals("SIX", row.get("Three")); } + @Test public void testColumnNameHandle() throws SQLException { final ResultSetHandler>> h = new KeyedHandler<>("intTest"); final Map> results = h.handle(getResultSet()); @@ -70,6 +76,7 @@ public void testColumnNameHandle() throws SQLException { assertEquals("SIX", row.get("Three")); } + @Test public void testEmptyResultSetHandle() throws SQLException { final ResultSetHandler>> h = new KeyedHandler<>(); final Map> results = h.handle(getEmptyResultSet()); @@ -77,6 +84,7 @@ public void testEmptyResultSetHandle() throws SQLException { assertTrue(results.isEmpty()); } + @Test public void testHandle() throws SQLException { final ResultSetHandler>> h = new KeyedHandler<>(); @@ -99,6 +107,7 @@ public void testHandle() throws SQLException { assertEquals("THREE", row.get("Three")); } + @Test public void testInjectedRowProcess() throws Exception { final RowProcessor mockProc = mock(RowProcessor.class); final ResultSetHandler>> h = new KeyedHandler<>(mockProc); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/MapHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/MapHandlerTest.java index d6b2c5b1..74a9ecd8 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/MapHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/MapHandlerTest.java @@ -16,17 +16,23 @@ */ package org.apache.commons.dbutils.handlers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.sql.SQLException; import java.util.Map; import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ResultSetHandler; +import org.junit.jupiter.api.Test; /** * MapHandlerTest */ public class MapHandlerTest extends BaseTestCase { + @Test public void testEmptyResultSetHandle() throws SQLException { final ResultSetHandler> h = new MapHandler(); final Map results = h.handle(getEmptyResultSet()); @@ -34,6 +40,7 @@ public void testEmptyResultSetHandle() throws SQLException { assertNull(results); } + @Test public void testHandle() throws SQLException { final ResultSetHandler> h = new MapHandler(); final Map results = h.handle(getResultSet()); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/MapListHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/MapListHandlerTest.java index 88fd11ac..1a6050a5 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/MapListHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/MapListHandlerTest.java @@ -16,6 +16,11 @@ */ package org.apache.commons.dbutils.handlers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; + import java.sql.SQLException; import java.util.Iterator; import java.util.List; @@ -23,12 +28,14 @@ import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ResultSetHandler; +import org.junit.jupiter.api.Test; /** * MapListHandlerTest */ public class MapListHandlerTest extends BaseTestCase { + @Test public void testEmptyResultSetHandle() throws SQLException { final ResultSetHandler>> h = new MapListHandler(); final List> results = h.handle(getEmptyResultSet()); @@ -37,6 +44,7 @@ public void testEmptyResultSetHandle() throws SQLException { assertTrue(results.isEmpty()); } + @Test public void testHandle() throws SQLException { final ResultSetHandler>> h = new MapListHandler(); final List> results = h.handle(getResultSet()); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/ScalarHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/ScalarHandlerTest.java index 5ecbd444..c9b0537d 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/ScalarHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/ScalarHandlerTest.java @@ -16,13 +16,19 @@ */ package org.apache.commons.dbutils.handlers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + import java.sql.SQLException; import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ResultSetHandler; +import org.junit.jupiter.api.Test; public class ScalarHandlerTest extends BaseTestCase { + @Test public void testColumnIndexHandle() throws SQLException { final ResultSetHandler h = new ScalarHandler<>(2); final Object results = h.handle(getResultSet()); @@ -30,6 +36,7 @@ public void testColumnIndexHandle() throws SQLException { assertEquals("2", results); } + @Test public void testColumnNameHandle() throws SQLException { final ResultSetHandler h = new ScalarHandler<>("intTest"); final Object results = h.handle(getResultSet()); @@ -37,12 +44,14 @@ public void testColumnNameHandle() throws SQLException { assertEquals(Integer.valueOf(1), results); } + @Test public void testEmptyResultSetHandle() throws SQLException { final ResultSetHandler h = new ScalarHandler<>(); final Object results = h.handle(getEmptyResultSet()); assertNull(results); } + @Test public void testHandle() throws SQLException { final ResultSetHandler h = new ScalarHandler<>(); final Object results = h.handle(getResultSet()); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/AbstractTestColumnHandler.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/AbstractTestColumnHandler.java index 8a266ead..f62441a7 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/AbstractTestColumnHandler.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/AbstractTestColumnHandler.java @@ -16,13 +16,13 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.ResultSet; import org.apache.commons.dbutils.ColumnHandler; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mock; public abstract class AbstractTestColumnHandler { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/BooleanColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/BooleanColumnHandlerTest.java index 58981f58..54382f83 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/BooleanColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/BooleanColumnHandlerTest.java @@ -16,16 +16,16 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; import java.sql.ResultSet; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class BooleanColumnHandlerTest extends AbstractTestColumnHandler { public BooleanColumnHandlerTest() { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/ByteColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/ByteColumnHandlerTest.java index 78f40cb5..0f706f2a 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/ByteColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/ByteColumnHandlerTest.java @@ -16,16 +16,16 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; import java.sql.ResultSet; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ByteColumnHandlerTest extends AbstractTestColumnHandler { public ByteColumnHandlerTest() { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/DoubleColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/DoubleColumnHandlerTest.java index f3c959f9..fdab6c2a 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/DoubleColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/DoubleColumnHandlerTest.java @@ -16,16 +16,16 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; import java.sql.ResultSet; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class DoubleColumnHandlerTest extends AbstractTestColumnHandler { public DoubleColumnHandlerTest() { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/FloatColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/FloatColumnHandlerTest.java index c86373ff..1acfca77 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/FloatColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/FloatColumnHandlerTest.java @@ -16,16 +16,16 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; import java.sql.ResultSet; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class FloatColumnHandlerTest extends AbstractTestColumnHandler { public FloatColumnHandlerTest() { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/IntegerColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/IntegerColumnHandlerTest.java index 48ce6ecf..29b8dbc3 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/IntegerColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/IntegerColumnHandlerTest.java @@ -16,15 +16,15 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.mockito.Mockito.when; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class IntegerColumnHandlerTest extends AbstractTestColumnHandler { public IntegerColumnHandlerTest() { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/LongColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/LongColumnHandlerTest.java index bb69a50a..4a3b0690 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/LongColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/LongColumnHandlerTest.java @@ -16,14 +16,14 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class LongColumnHandlerTest extends AbstractTestColumnHandler { public LongColumnHandlerTest() { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/SQLXMLColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/SQLXMLColumnHandlerTest.java index 6f72cad9..0b4effc2 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/SQLXMLColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/SQLXMLColumnHandlerTest.java @@ -16,17 +16,17 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; import java.sql.SQLXML; -import org.junit.Test; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class SQLXMLColumnHandlerTest extends AbstractTestColumnHandler { @Mock diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/ShortColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/ShortColumnHandlerTest.java index 5a4462bf..f3fc4f31 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/ShortColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/ShortColumnHandlerTest.java @@ -16,14 +16,14 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class ShortColumnHandlerTest extends AbstractTestColumnHandler { public ShortColumnHandlerTest() { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/StringColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/StringColumnHandlerTest.java index bf26f170..b11e2923 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/StringColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/StringColumnHandlerTest.java @@ -16,14 +16,14 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class StringColumnHandlerTest extends AbstractTestColumnHandler { public StringColumnHandlerTest() { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/columns/TimestampColumnHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/columns/TimestampColumnHandlerTest.java index 9655b59a..83947821 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/columns/TimestampColumnHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/columns/TimestampColumnHandlerTest.java @@ -16,17 +16,17 @@ */ package org.apache.commons.dbutils.handlers.columns; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; import java.sql.Timestamp; import java.util.Date; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.junit.MockitoJUnitRunner; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.junit.jupiter.MockitoExtension; -@RunWith(MockitoJUnitRunner.class) +@ExtendWith(MockitoExtension.class) public class TimestampColumnHandlerTest extends AbstractTestColumnHandler { public TimestampColumnHandlerTest() { diff --git a/src/test/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandlerTest.java index 2f50d55e..592021a7 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/properties/DatePropertyHandlerTest.java @@ -16,22 +16,22 @@ */ package org.apache.commons.dbutils.handlers.properties; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.sql.Time; import java.sql.Timestamp; import java.util.Date; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class DatePropertyHandlerTest { private DatePropertyHandler handler; private Date testValue; - @Before + @BeforeEach public void setUp() { this.handler = new DatePropertyHandler(); this.testValue = new Date(); diff --git a/src/test/java/org/apache/commons/dbutils/handlers/properties/PropertyHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/properties/PropertyHandlerTest.java index 8361ae96..9329a0de 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/properties/PropertyHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/properties/PropertyHandlerTest.java @@ -16,18 +16,18 @@ */ package org.apache.commons.dbutils.handlers.properties; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ServiceLoader; import org.apache.commons.dbutils.PropertyHandler; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class PropertyHandlerTest { private ServiceLoader loader; - @Before + @BeforeEach public void setUp() { loader = ServiceLoader.load(PropertyHandler.class); } diff --git a/src/test/java/org/apache/commons/dbutils/handlers/properties/StringEnumPropertyHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/properties/StringEnumPropertyHandlerTest.java index 80773438..bc9bc63b 100644 --- a/src/test/java/org/apache/commons/dbutils/handlers/properties/StringEnumPropertyHandlerTest.java +++ b/src/test/java/org/apache/commons/dbutils/handlers/properties/StringEnumPropertyHandlerTest.java @@ -16,16 +16,16 @@ */ package org.apache.commons.dbutils.handlers.properties; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; public class StringEnumPropertyHandlerTest { private StringEnumPropertyHandler handler; - @Before + @BeforeEach public void setUp() { this.handler = new StringEnumPropertyHandler(); } diff --git a/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java b/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java index be9ea0d7..a39c9c28 100644 --- a/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java +++ b/src/test/java/org/apache/commons/dbutils/wrappers/SqlNullCheckedResultSetTest.java @@ -16,6 +16,11 @@ */ package org.apache.commons.dbutils.wrappers; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -44,6 +49,8 @@ import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.ProxyFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; final class SqlNullCheckedResultSetMockBlob implements Blob { @@ -221,12 +228,12 @@ private static void assertArrayEquals(final byte[] expected, final byte[] actual return; } if (expected.length != actual.length) { - failNotEquals(null, Arrays.toString(expected), Arrays.toString(actual)); + assertEquals(Arrays.toString(expected), Arrays.toString(actual)); } for (int i = 0; i < expected.length; i++) { final byte expectedItem = expected[i]; final byte actualItem = actual[i]; - assertEquals("Array not equal at index " + i, expectedItem, actualItem); + assertEquals(expectedItem, actualItem, "Array not equal at index " + i); } } private SqlNullCheckedResultSet rs2; @@ -234,7 +241,7 @@ private static void assertArrayEquals(final byte[] expected, final byte[] actual /** * Sets up instance variables required by this test case. */ - @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); @@ -247,6 +254,7 @@ public void setUp() throws Exception { /** * Tests the getAsciiStream implementation. */ + @Test public void testGetAsciiStream() throws SQLException { assertNull(rs.getAsciiStream(1)); @@ -266,6 +274,7 @@ public void testGetAsciiStream() throws SQLException { /** * Tests the getBigDecimal implementation. */ + @Test public void testGetBigDecimal() throws SQLException { assertNull(rs.getBigDecimal(1)); @@ -285,6 +294,7 @@ public void testGetBigDecimal() throws SQLException { /** * Tests the getBinaryStream implementation. */ + @Test public void testGetBinaryStream() throws SQLException { assertNull(rs.getBinaryStream(1)); @@ -304,6 +314,7 @@ public void testGetBinaryStream() throws SQLException { /** * Tests the getBlob implementation. */ + @Test public void testGetBlob() throws SQLException { assertNull(rs.getBlob(1)); @@ -323,6 +334,7 @@ public void testGetBlob() throws SQLException { /** * Tests the getBoolean implementation. */ + @Test public void testGetBoolean() throws SQLException { assertFalse(rs.getBoolean(1)); @@ -339,6 +351,7 @@ public void testGetBoolean() throws SQLException { /** * Tests the getByte implementation. */ + @Test public void testGetByte() throws SQLException { assertEquals((byte) 0, rs.getByte(1)); @@ -356,6 +369,7 @@ public void testGetByte() throws SQLException { /** * Tests the getByte implementation. */ + @Test public void testGetBytes() throws SQLException { assertNull(rs.getBytes(1)); @@ -378,6 +392,7 @@ public void testGetBytes() throws SQLException { /** * Tests the getCharacterStream implementation. */ + @Test public void testGetCharacterStream() throws SQLException { assertNull(rs.getCharacterStream(1)); @@ -397,6 +412,7 @@ public void testGetCharacterStream() throws SQLException { /** * Tests the getClob implementation. */ + @Test public void testGetClob() throws SQLException { assertNull(rs.getClob(1)); @@ -416,6 +432,7 @@ public void testGetClob() throws SQLException { /** * Tests the getDate implementation. */ + @Test public void testGetDate() throws SQLException { assertNull(rs.getDate(1)); @@ -443,6 +460,7 @@ public void testGetDate() throws SQLException { /** * Tests the getDouble implementation. */ + @Test public void testGetDouble() throws SQLException { assertEquals(0.0, rs.getDouble(1), 0.0); @@ -460,6 +478,7 @@ public void testGetDouble() throws SQLException { /** * Tests the getFloat implementation. */ + @Test public void testGetFloat() throws SQLException { assertEquals(0, rs.getFloat(1), 0.0); assertTrue(rs.wasNull()); @@ -475,6 +494,7 @@ public void testGetFloat() throws SQLException { /** * Tests the getInt implementation. */ + @Test public void testGetInt() throws SQLException { assertEquals(0, rs.getInt(1)); assertTrue(rs.wasNull()); @@ -490,6 +510,7 @@ public void testGetInt() throws SQLException { /** * Tests the getLong implementation. */ + @Test public void testGetLong() throws SQLException { assertEquals(0, rs.getLong(1)); assertTrue(rs.wasNull()); @@ -505,6 +526,7 @@ public void testGetLong() throws SQLException { /** * Tests the getObject implementation. */ + @Test public void testGetObject() throws SQLException { assertNull(rs.getObject(1)); @@ -532,6 +554,7 @@ public void testGetObject() throws SQLException { /** * Tests the getRef implementation. */ + @Test public void testGetRef() throws SQLException { assertNull(rs.getRef(1)); @@ -551,6 +574,7 @@ public void testGetRef() throws SQLException { /** * Tests the getShort implementation. */ + @Test public void testGetShort() throws SQLException { assertEquals((short) 0, rs.getShort(1)); @@ -567,6 +591,7 @@ public void testGetShort() throws SQLException { /** * Tests the getString implementation. */ + @Test public void testGetString() throws SQLException { assertNull(rs.getString(1)); assertTrue(rs.wasNull()); @@ -582,6 +607,7 @@ public void testGetString() throws SQLException { /** * Tests the getTime implementation. */ + @Test public void testGetTime() throws SQLException { assertNull(rs.getTime(1)); @@ -609,6 +635,7 @@ public void testGetTime() throws SQLException { /** * Tests the getTimestamp implementation. */ + @Test public void testGetTimestamp() throws SQLException { assertNull(rs.getTimestamp(1)); @@ -635,6 +662,7 @@ public void testGetTimestamp() throws SQLException { /** * Tests the setNullAsciiStream implementation. */ + @Test public void testSetNullAsciiStream() throws SQLException { assertNull(rs2.getNullAsciiStream()); @@ -651,6 +679,7 @@ public void testSetNullAsciiStream() throws SQLException { /** * Tests the setNullBigDecimal implementation. */ + @Test public void testSetNullBigDecimal() throws SQLException { assertNull(rs2.getNullBigDecimal()); @@ -667,6 +696,7 @@ public void testSetNullBigDecimal() throws SQLException { /** * Tests the setNullBinaryStream implementation. */ + @Test public void testSetNullBinaryStream() throws SQLException { assertNull(rs2.getNullBinaryStream()); @@ -683,6 +713,7 @@ public void testSetNullBinaryStream() throws SQLException { /** * Tests the setNullBlob implementation. */ + @Test public void testSetNullBlob() throws SQLException { assertNull(rs2.getNullBlob()); @@ -699,6 +730,7 @@ public void testSetNullBlob() throws SQLException { /** * Tests the setNullBoolean implementation. */ + @Test public void testSetNullBoolean() throws SQLException { assertFalse(rs2.getNullBoolean()); @@ -712,6 +744,7 @@ public void testSetNullBoolean() throws SQLException { /** * Tests the setNullByte implementation. */ + @Test public void testSetNullByte() throws SQLException { assertEquals((byte) 0, rs2.getNullByte()); @@ -726,6 +759,7 @@ public void testSetNullByte() throws SQLException { /** * Tests the setNullByte implementation. */ + @Test public void testSetNullBytes() throws SQLException { // test the default, unset value assertNull(rs2.getNullBytes()); @@ -750,6 +784,7 @@ public void testSetNullBytes() throws SQLException { /** * Tests the setNullCharacterStream implementation. */ + @Test public void testSetNullCharacterStream() throws SQLException { assertNull(rs2.getNullCharacterStream()); @@ -766,6 +801,7 @@ public void testSetNullCharacterStream() throws SQLException { /** * Tests the setNullClob implementation. */ + @Test public void testSetNullClob() throws SQLException { assertNull(rs2.getNullClob()); @@ -782,6 +818,7 @@ public void testSetNullClob() throws SQLException { /** * Tests the setNullDate implementation. */ + @Test public void testSetNullDate() throws SQLException { // test the default, unset value assertNull(rs2.getNullDate()); @@ -807,6 +844,7 @@ public void testSetNullDate() throws SQLException { /** * Tests the setNullDouble implementation. */ + @Test public void testSetNullDouble() throws SQLException { assertEquals(0.0, rs2.getNullDouble(), 0.0); // Set what gets returned to something other than the default @@ -819,6 +857,7 @@ public void testSetNullDouble() throws SQLException { /** * Tests the setNullFloat implementation. */ + @Test public void testSetNullFloat() throws SQLException { assertEquals((float) 0.0, rs2.getNullFloat(), 0.0); // Set what gets returned to something other than the default @@ -831,6 +870,7 @@ public void testSetNullFloat() throws SQLException { /** * Tests the setNullInt implementation. */ + @Test public void testSetNullInt() throws SQLException { assertEquals(0, rs2.getNullInt()); assertEquals(0, rs.getInt(1)); @@ -847,6 +887,7 @@ public void testSetNullInt() throws SQLException { /** * Tests the setNullLong implementation. */ + @Test public void testSetNullLong() throws SQLException { assertEquals(0, rs2.getNullLong()); // Set what gets returned to something other than the default @@ -859,6 +900,7 @@ public void testSetNullLong() throws SQLException { /** * Tests the setNullObject implementation. */ + @Test public void testSetNullObject() throws SQLException { assertNull(rs2.getNullObject()); // Set what gets returned to something other than the default @@ -877,6 +919,7 @@ public void testSetNullObject() throws SQLException { /** * Tests the setNullRef implementation. */ + @Test public void testSetNullRef() throws SQLException { assertNull(rs2.getNullRef()); // Set what gets returned to something other than the default @@ -891,6 +934,7 @@ public void testSetNullRef() throws SQLException { /** * Tests the setNullShort implementation. */ + @Test public void testSetNullShort() throws SQLException { assertEquals((short) 0, rs2.getNullShort()); @@ -905,6 +949,7 @@ public void testSetNullShort() throws SQLException { /** * Tests the setNullString implementation. */ + @Test public void testSetNullString() throws SQLException { assertNull(rs2.getNullString()); // Set what gets returned to something other than the default @@ -917,6 +962,7 @@ public void testSetNullString() throws SQLException { /** * Tests the setNullTime implementation. */ + @Test public void testSetNullTime() throws SQLException { // test the default, unset value assertNull(rs2.getNullTime()); @@ -941,6 +987,7 @@ public void testSetNullTime() throws SQLException { /** * Tests the setNullTimestamp implementation. */ + @Test public void testSetNullTimestamp() throws SQLException { // test the default, unset value assertNull(rs2.getNullTimestamp()); @@ -965,6 +1012,7 @@ public void testSetNullTimestamp() throws SQLException { /** * Tests the getURL and setNullURL implementations. */ + @Test public void testURL() throws SQLException, MalformedURLException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { assertNull(rs.getURL(1)); assertTrue(rs.wasNull()); @@ -977,6 +1025,7 @@ public void testURL() throws SQLException, MalformedURLException, IllegalAccessE assertEquals(u, rs.getURL("column")); } + @Test public void testWrapResultSet() throws SQLException { final ResultSet wrappedRs = mock(ResultSet.class); final ResultSet rs = SqlNullCheckedResultSet.wrap(wrappedRs); diff --git a/src/test/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSetTest.java b/src/test/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSetTest.java index 09c98336..8ba740c3 100644 --- a/src/test/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSetTest.java +++ b/src/test/java/org/apache/commons/dbutils/wrappers/StringTrimmedResultSetTest.java @@ -16,29 +16,35 @@ */ package org.apache.commons.dbutils.wrappers; +import static org.junit.jupiter.api.Assertions.assertEquals; + import java.sql.ResultSet; import java.sql.SQLException; import org.apache.commons.dbutils.BaseTestCase; import org.apache.commons.dbutils.MockResultSet; import org.apache.commons.dbutils.ProxyFactory; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; /** * StringTrimmedResultSetTest */ public class StringTrimmedResultSetTest extends BaseTestCase { - @Override + @BeforeEach public void setUp() throws Exception { super.setUp(); setResultSet(StringTrimmedResultSet.wrap(getResultSet())); } + @Test public void testGetObject() throws SQLException { getResultSet().next(); assertEquals("notInBean", getResultSet().getObject(4)); } + @Test public void testGetString() throws SQLException { getResultSet().next(); assertEquals("notInBean", getResultSet().getString(4)); @@ -49,6 +55,7 @@ public void testGetString() throws SQLException { * * @throws SQLException if a database access error occurs */ + @Test public void testMultipleWrappers() throws Exception { // Create a ResultSet with data final Object[][] rows = { { null } };