http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java b/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java deleted file mode 100644 index 75ac9dd..0000000 --- a/src/test/java/org/apache/commons/dbutils/BasicRowProcessorTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import java.sql.SQLException; -import java.text.DateFormat; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.List; -import java.util.Locale; -import java.util.Map; - -/** - * Test the BasicRowProcessor class. - */ -public class BasicRowProcessorTest extends BaseTestCase { - - private static final RowProcessor processor = new BasicRowProcessor(); - - /** - * Format that matches Date.toString(). - * Sun Mar 14 15:19:15 MST 2004 - */ - private static final DateFormat datef = - new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy", Locale.US); - - public void testToArray() throws SQLException { - - Object[] a = null; - assertTrue(this.rs.next()); - a = processor.toArray(this.rs); - assertEquals(COLS, a.length); - assertEquals("1", a[0]); - assertEquals("2", a[1]); - assertEquals("3", a[2]); - - assertTrue(this.rs.next()); - a = processor.toArray(this.rs); - assertEquals(COLS, a.length); - - assertEquals("4", a[0]); - assertEquals("5", a[1]); - assertEquals("6", a[2]); - - assertFalse(this.rs.next()); - } - - public void testToBean() throws SQLException, ParseException { - - TestBean row = null; - assertTrue(this.rs.next()); - row = processor.toBean(this.rs, TestBean.class); - assertEquals("1", row.getOne()); - assertEquals("2", row.getTwo()); - assertEquals("3", row.getThree()); - assertEquals("not set", row.getDoNotSet()); - - assertTrue(this.rs.next()); - row = processor.toBean(this.rs, TestBean.class); - - assertEquals("4", row.getOne()); - assertEquals("5", row.getTwo()); - assertEquals("6", row.getThree()); - assertEquals("not set", row.getDoNotSet()); - assertEquals(3, row.getIntTest()); - assertEquals(Integer.valueOf(4), row.getIntegerTest()); - assertEquals(null, row.getNullObjectTest()); - assertEquals(0, row.getNullPrimitiveTest()); - // test date -> string handling - assertNotNull(row.getNotDate()); - assertTrue(!"not a date".equals(row.getNotDate())); - datef.parse(row.getNotDate()); - - assertFalse(this.rs.next()); - - } - - public void testToBeanList() throws SQLException, ParseException { - - List<TestBean> list = processor.toBeanList(this.rs, TestBean.class); - assertNotNull(list); - assertEquals(ROWS, list.size()); - - TestBean b = list.get(0); - assertEquals("1", b.getOne()); - assertEquals("2", b.getTwo()); - assertEquals("3", b.getThree()); - assertEquals("not set", b.getDoNotSet()); - - b = list.get(1); - assertEquals("4", b.getOne()); - assertEquals("5", b.getTwo()); - assertEquals("6", b.getThree()); - assertEquals("not set", b.getDoNotSet()); - assertEquals(3, b.getIntTest()); - assertEquals(Integer.valueOf(4), b.getIntegerTest()); - assertEquals(null, b.getNullObjectTest()); - assertEquals(0, b.getNullPrimitiveTest()); - // test date -> string handling - assertNotNull(b.getNotDate()); - assertTrue(!"not a date".equals(b.getNotDate())); - datef.parse(b.getNotDate()); - } - - public void testToMap() throws SQLException { - - assertTrue(this.rs.next()); - Map<String, Object> m = processor.toMap(this.rs); - assertEquals(COLS, m.keySet().size()); - assertEquals("1", m.get("one")); - assertEquals("2", m.get("TWO")); - assertEquals("3", m.get("Three")); - - assertTrue(this.rs.next()); - m = processor.toMap(this.rs); - assertEquals(COLS, m.keySet().size()); - - assertEquals("4", m.get("One")); // case shouldn't matter - assertEquals("5", m.get("two")); - assertEquals("6", m.get("THREE")); - - assertFalse(this.rs.next()); - } - -}
http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/BatchExecutorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/BatchExecutorTest.java b/src/test/java/org/apache/commons/dbutils/BatchExecutorTest.java deleted file mode 100644 index 3d2d7be..0000000 --- a/src/test/java/org/apache/commons/dbutils/BatchExecutorTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import static org.junit.Assert.*; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - - -public class BatchExecutorTest { - - private BatchExecutor executor; - - @Mock private Connection conn; - @Mock private PreparedStatement stmt; - - @Before - public void setup() throws SQLException { - MockitoAnnotations.initMocks(this); - - when(conn.prepareStatement(any(String.class))).thenReturn(stmt); - when(stmt.executeBatch()).thenReturn(new int[] { 2, 3, 4 }); - } - - protected void createExecutor(String sql) throws Exception { - executor = new BatchExecutor(conn, sql, true); - } - - @Test - public void testGoodSQL() throws Exception { - createExecutor("insert into blah"); - - executor.addBatch(); - int[] ret = executor.execute(); - - assertEquals(3, ret.length); - assertEquals(2, ret[0]); - assertEquals(3, ret[1]); - assertEquals(4, ret[2]); - verify(conn, times(1)).close(); - verify(stmt, times(1)).close(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java b/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java deleted file mode 100644 index c60ffad..0000000 --- a/src/test/java/org/apache/commons/dbutils/BeanProcessorTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import java.beans.Introspector; -import java.beans.PropertyDescriptor; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.util.HashMap; -import java.util.Map; - -public class BeanProcessorTest extends BaseTestCase { - - private static final BeanProcessor beanProc = new BeanProcessor(); - - public void testProcess() throws SQLException { - TestBean b = null; - assertTrue(this.rs.next()); - b = beanProc.toBean(this.rs, TestBean.class); - assertEquals(13.0, b.getColumnProcessorDoubleTest(), 0); - - assertTrue(this.rs.next()); - b = beanProc.toBean(this.rs, TestBean.class); - assertEquals(13.0, b.getColumnProcessorDoubleTest(), 0); - - assertFalse(this.rs.next()); - } - - public static class MapColumnToPropertiesBean { - private String one; - - private String two; - - private String three; - - private String four; - - public String getOne() { - return one; - } - - public void setOne(String one) { - this.one = one; - } - - public String getTwo() { - return two; - } - - public void setTwo(String two) { - this.two = two; - } - - public String getThree() { - return three; - } - - public void setThree(String three) { - this.three = three; - } - - public String getFour() { - return four; - } - - public void setFour(String four) { - this.four = four; - } - } - - public void testMapColumnToProperties() throws Exception { - String[] columnNames = { "test", "test", "three" }; - String[] columnLabels = { "one", "two", null }; - ResultSetMetaData rsmd = ProxyFactory.instance().createResultSetMetaData( - new MockResultSetMetaData(columnNames, columnLabels)); - PropertyDescriptor[] props = Introspector.getBeanInfo(MapColumnToPropertiesBean.class).getPropertyDescriptors(); - - int[] columns = beanProc.mapColumnsToProperties(rsmd, props); - for (int i = 1; i < columns.length; i++) { - assertTrue(columns[i] != BeanProcessor.PROPERTY_NOT_FOUND); - } - } - - public void testMapColumnToPropertiesWithOverrides() throws Exception { - Map<String, String> columnToPropertyOverrides = new HashMap<String, String>(); - columnToPropertyOverrides.put("five", "four"); - BeanProcessor beanProc = new BeanProcessor(columnToPropertyOverrides); - String[] columnNames = { "test", "test", "three", "five" }; - String[] columnLabels = { "one", "two", null, null }; - ResultSetMetaData rsmd = ProxyFactory.instance().createResultSetMetaData( - new MockResultSetMetaData(columnNames, columnLabels)); - PropertyDescriptor[] props = Introspector.getBeanInfo(MapColumnToPropertiesBean.class).getPropertyDescriptors(); - - int[] columns = beanProc.mapColumnsToProperties(rsmd, props); - for (int i = 1; i < columns.length; i++) { - assertTrue(columns[i] != BeanProcessor.PROPERTY_NOT_FOUND); - } - } -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java b/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java deleted file mode 100644 index 3d2a16e..0000000 --- a/src/test/java/org/apache/commons/dbutils/DbUtilsTest.java +++ /dev/null @@ -1,272 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import static org.junit.Assert.fail; -import static org.mockito.Mockito.doThrow; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; - -import java.sql.Connection; -import java.sql.ResultSet; -import java.sql.SQLException; -import java.sql.Statement; - -import org.junit.Test; - -public class DbUtilsTest { - - @Test - public void closeNullConnection() throws Exception { - DbUtils.close((Connection) null); - } - - @Test - public void closeConnection() throws Exception { - Connection mockCon = mock(Connection.class); - DbUtils.close(mockCon); - verify(mockCon).close(); - } - - @Test - public void closeNullResultSet() throws Exception { - DbUtils.close((ResultSet) null); - } - - @Test - public void closeResultSet() throws Exception { - ResultSet mockResultSet = mock(ResultSet.class); - DbUtils.close(mockResultSet); - verify(mockResultSet).close(); - } - - @Test - public void closeNullStatement() throws Exception { - DbUtils.close((Statement) null); - } - - @Test - public void closeStatement() throws Exception { - Statement mockStatement = mock(Statement.class); - DbUtils.close(mockStatement); - verify(mockStatement).close(); - } - - @Test - public void closeQuietlyNullConnection() throws Exception { - DbUtils.closeQuietly((Connection) null); - } - - @Test - public void closeQuietlyConnection() throws Exception { - Connection mockConnection = mock(Connection.class); - DbUtils.closeQuietly(mockConnection); - verify(mockConnection).close(); - } - - @Test - public void closeQuietlyConnectionThrowingException() throws Exception { - Connection mockConnection = mock(Connection.class); - doThrow(SQLException.class).when(mockConnection).close(); - DbUtils.closeQuietly(mockConnection); - } - - @Test - public void closeQuietlyNullResultSet() throws Exception { - DbUtils.closeQuietly((ResultSet) null); - } - - @Test - public void closeQuietlyResultSet() throws Exception { - ResultSet mockResultSet = mock(ResultSet.class); - DbUtils.closeQuietly(mockResultSet); - verify(mockResultSet).close(); - } - - @Test - public void closeQuietlyResultSetThrowingException() throws Exception { - ResultSet mockResultSet = mock(ResultSet.class); - doThrow(SQLException.class).when(mockResultSet).close(); - DbUtils.closeQuietly(mockResultSet); - } - - @Test - public void closeQuietlyNullStatement() throws Exception { - DbUtils.closeQuietly((Statement) null); - } - - @Test - public void closeQuietlyStatement() throws Exception { - Statement mockStatement = mock(Statement.class); - DbUtils.closeQuietly(mockStatement); - verify(mockStatement).close(); - } - - @Test - public void closeQuietlyStatementThrowingException() throws Exception { - Statement mockStatement = mock(Statement.class); - doThrow(SQLException.class).when(mockStatement).close(); - DbUtils.closeQuietly(mockStatement); - } - - @Test - public void closeQuietlyConnectionResultSetStatement() throws Exception { - Connection mockConnection = mock(Connection.class); - ResultSet mockResultSet = mock(ResultSet.class); - Statement mockStatement = mock(Statement.class); - DbUtils.closeQuietly(mockConnection, mockStatement, mockResultSet); - verify(mockConnection).close(); - verify(mockResultSet).close(); - verify(mockStatement).close(); - } - - @Test - public void closeQuietlyConnectionThrowingExceptionResultSetStatement() throws Exception { - Connection mockConnection = mock(Connection.class); - doThrow(SQLException.class).when(mockConnection).close(); - ResultSet mockResultSet = mock(ResultSet.class); - Statement mockStatement = mock(Statement.class); - DbUtils.closeQuietly(mockConnection, mockStatement, mockResultSet); - verify(mockConnection).close(); - verify(mockResultSet).close(); - verify(mockStatement).close(); - } - - @Test - public void closeQuietlyConnectionResultSetThrowingExceptionStatement() throws Exception { - Connection mockConnection = mock(Connection.class); - ResultSet mockResultSet = mock(ResultSet.class); - doThrow(SQLException.class).when(mockResultSet).close(); - Statement mockStatement = mock(Statement.class); - DbUtils.closeQuietly(mockConnection, mockStatement, mockResultSet); - verify(mockConnection).close(); - verify(mockResultSet).close(); - verify(mockStatement).close(); - } - - @Test - public void closeQuietlyConnectionResultSetStatementThrowingException() throws Exception { - Connection mockConnection = mock(Connection.class); - ResultSet mockResultSet = mock(ResultSet.class); - Statement mockStatement = mock(Statement.class); - doThrow(SQLException.class).when(mockStatement).close(); - DbUtils.closeQuietly(mockConnection, mockStatement, mockResultSet); - verify(mockConnection).close(); - verify(mockResultSet).close(); - verify(mockStatement).close(); - } - - @Test - public void commitAndClose() throws Exception { - Connection mockConnection = mock(Connection.class); - DbUtils.commitAndClose(mockConnection); - verify(mockConnection).commit(); - verify(mockConnection).close(); - } - - @Test - public void commitAndCloseWithException() throws Exception { - Connection mockConnection = mock(Connection.class); - doThrow(SQLException.class).when(mockConnection).commit(); - try { - DbUtils.commitAndClose(mockConnection); - fail("DbUtils.commitAndClose() swallowed SQLEception!"); - } catch (SQLException e) { - // we expect this exception - } - verify(mockConnection).close(); - } - - @Test - public void commitAndCloseQuietly() throws Exception { - Connection mockConnection = mock(Connection.class); - DbUtils.commitAndClose(mockConnection); - verify(mockConnection).commit(); - verify(mockConnection).close(); - } - - @Test - public void commitAndCloseQuietlyWithException() throws Exception { - Connection mockConnection = mock(Connection.class); - doThrow(SQLException.class).when(mockConnection).close(); - DbUtils.commitAndCloseQuietly(mockConnection); - verify(mockConnection).commit(); - verify(mockConnection).close(); - } - - @Test - public void rollbackNull() throws Exception { - DbUtils.rollback(null); - } - - @Test - public void rollback() throws Exception { - Connection mockConnection = mock(Connection.class); - DbUtils.rollback(mockConnection); - verify(mockConnection).rollback(); - } - - @Test - public void rollbackAndCloseNull() throws Exception { - DbUtils.rollbackAndClose(null); - } - - @Test - public void rollbackAndClose() throws Exception { - Connection mockConnection = mock(Connection.class); - DbUtils.rollbackAndClose(mockConnection); - verify(mockConnection).rollback(); - verify(mockConnection).close(); - } - - @Test - public void rollbackAndCloseWithException() throws Exception { - Connection mockConnection = mock(Connection.class); - doThrow(SQLException.class).when(mockConnection).rollback(); - try { - DbUtils.rollbackAndClose(mockConnection); - fail("DbUtils.rollbackAndClose() swallowed SQLException!"); - } catch (SQLException e) { - // we expect this exeption - } - verify(mockConnection).rollback(); - verify(mockConnection).close(); - } - - @Test - public void rollbackAndCloseQuietlyNull() throws Exception { - DbUtils.rollbackAndCloseQuietly(null); - } - - @Test - public void rollbackAndCloseQuietly() throws Exception { - Connection mockConnection = mock(Connection.class); - DbUtils.rollbackAndCloseQuietly(mockConnection); - verify(mockConnection).rollback(); - verify(mockConnection).close(); - } - - @Test - public void rollbackAndCloseQuietlyWithException() throws Exception { - Connection mockConnection = mock(Connection.class); - doThrow(SQLException.class).when(mockConnection).rollback(); - DbUtils.rollbackAndCloseQuietly(mockConnection); - verify(mockConnection).rollback(); - verify(mockConnection).close(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java b/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java deleted file mode 100644 index 4d88fd7..0000000 --- a/src/test/java/org/apache/commons/dbutils/GenerousBeanProcessorTest.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.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.mockito.Mock; -import org.mockito.MockitoAnnotations; - - -public class GenerousBeanProcessorTest { - - GenerousBeanProcessor processor = new GenerousBeanProcessor(); - @Mock ResultSetMetaData metaData; - PropertyDescriptor[] propDescriptors; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - - propDescriptors = new PropertyDescriptor[3]; - - propDescriptors[0] = new PropertyDescriptor("one", TestBean.class); - propDescriptors[1] = new PropertyDescriptor("two", TestBean.class); - propDescriptors[2] = new PropertyDescriptor("three", TestBean.class); - } - - @Test - public void testMapColumnsToPropertiesWithOutUnderscores() throws Exception { - when(metaData.getColumnCount()).thenReturn(3); - - when(metaData.getColumnLabel(1)).thenReturn("three"); - when(metaData.getColumnLabel(2)).thenReturn("one"); - when(metaData.getColumnLabel(3)).thenReturn("two"); - - int[] ret = processor.mapColumnsToProperties(metaData, propDescriptors); - - assertNotNull(ret); - assertEquals(4, ret.length); - assertEquals(-1, ret[0]); - assertEquals(2, ret[1]); - assertEquals(0, ret[2]); - assertEquals(1, ret[3]); - } - - @Test - public void testMapColumnsToPropertiesWithUnderscores() throws Exception { - when(metaData.getColumnCount()).thenReturn(3); - - when(metaData.getColumnLabel(1)).thenReturn("t_h_r_e_e"); - when(metaData.getColumnLabel(2)).thenReturn("o_n_e"); - when(metaData.getColumnLabel(3)).thenReturn("t_w_o"); - - int[] ret = processor.mapColumnsToProperties(metaData, propDescriptors); - - assertNotNull(ret); - assertEquals(4, ret.length); - assertEquals(-1, ret[0]); - assertEquals(2, ret[1]); - assertEquals(0, ret[2]); - assertEquals(1, ret[3]); - } - - static class TestBean { - private String one; - private int two; - private long three; - - public String getOne() { - return one; - } - - public void setOne(String one) { - this.one = one; - } - - public int getTwo() { - return two; - } - - public void setTwo(int two) { - this.two = two; - } - - public long getThree() { - return three; - } - - public void setThree(long three) { - this.three = three; - } - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/InsertExecutorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/InsertExecutorTest.java b/src/test/java/org/apache/commons/dbutils/InsertExecutorTest.java deleted file mode 100644 index f96c546..0000000 --- a/src/test/java/org/apache/commons/dbutils/InsertExecutorTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - - -public class InsertExecutorTest { - - private InsertExecutor executor; - - @Mock private ResultSetHandler<Object> handler; - @Mock private Connection conn; - @Mock private PreparedStatement stmt; - @Mock private ResultSet resultSet; - - @Before - public void setup() throws SQLException { - MockitoAnnotations.initMocks(this); - - when(conn.prepareStatement(any(String.class))).thenReturn(stmt); - when(stmt.getGeneratedKeys()).thenReturn(resultSet); - when(handler.handle(any(ResultSet.class))).thenReturn(new Object()); - } - - protected void createExecutor(String sql) throws Exception { - executor = new InsertExecutor(conn, sql, true); - } - - @Test - public void testGoodSQL() throws Exception { - createExecutor("insert into blah"); - - Object ret = executor.execute(handler); - - assertNotNull(ret); - verify(handler, times(1)).handle(resultSet); - verify(conn, times(1)).close(); - verify(stmt, times(1)).close(); - } - - @Test(expected=SQLException.class) - public void testUnmappedParams() throws Exception { - createExecutor("insert into blah (:something)"); - - Object ret = executor.execute(handler); - - assertNotNull(ret); - verify(handler, times(1)).handle(resultSet); - verify(conn, times(1)).close(); - verify(stmt, times(1)).close(); - } - - @Test(expected=SQLException.class) - public void testNullHandler() throws Exception { - createExecutor("insert into blah"); - - Object ret = executor.execute(null); - - assertNotNull(ret); - verify(handler, times(1)).handle(resultSet); - verify(conn, times(1)).close(); - verify(stmt, times(1)).close(); - } -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/MockResultSet.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/MockResultSet.java b/src/test/java/org/apache/commons/dbutils/MockResultSet.java deleted file mode 100644 index 39b8547..0000000 --- a/src/test/java/org/apache/commons/dbutils/MockResultSet.java +++ /dev/null @@ -1,363 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.sql.SQLException; -import java.util.Arrays; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; - -/** - * MockResultSet dynamically implements the ResultSet interface. - */ -public class MockResultSet implements InvocationHandler { - - /** - * Create a <code>MockResultSet</code> proxy object. This is equivalent to: - * <pre> - * ProxyFactory.instance().createResultSet(new MockResultSet(metaData, rows)); - * </pre> - * - * @param metaData - * @param rows A null value indicates an empty <code>ResultSet</code>. - */ - public static ResultSet create(ResultSetMetaData metaData, - Object[][] rows) { - return ProxyFactory.instance().createResultSet( - new MockResultSet(metaData, rows)); - } - - private Object[] currentRow = null; - - private Iterator<Object[]> iter = null; - - private ResultSetMetaData metaData = null; - - private Boolean wasNull = Boolean.FALSE; - - /** - * MockResultSet constructor. - * @param metaData - * @param rows A null value indicates an empty <code>ResultSet</code>. - */ - public MockResultSet(ResultSetMetaData metaData, Object[][] rows) { - super(); - this.metaData = metaData; - if (rows == null) { - List<Object[]> empty = Collections.emptyList(); - this.iter = empty.iterator(); - } else { - this.iter = Arrays.asList(rows).iterator(); - } - } - - /** - * The get* methods can have an int column index or a String column name as - * the parameter. This method handles both cases and returns the column - * index that the client is trying to get at. - * @param args - * @return A column index. - * @throws SQLException if a database access error occurs - */ - private int columnIndex(Object[] args) throws SQLException { - - if (args[0] instanceof Integer) { - return ((Integer) args[0]).intValue(); - - } else if (args[0] instanceof String) { - return this.columnNameToIndex((String) args[0]); - - } else { - throw new SQLException(args[0] + " must be Integer or String"); - } - } - - /** - * Returns the column index for the given column name. - * @return A 1 based index - * @throws SQLException if the column name is invalid - */ - private int columnNameToIndex(String columnName) throws SQLException { - for (int i = 0; i < this.currentRow.length; i++) { - int c = i + 1; - if (this.metaData.getColumnName(c).equalsIgnoreCase(columnName)) { - return c; - } - } - - throw new SQLException(columnName + " is not a valid column name."); - } - - /** - * Gets the boolean value at the given column index. - * @param columnIndex A 1 based index. - * @throws SQLException if a database access error occurs - */ - protected Object getBoolean(int columnIndex) throws SQLException { - Object obj = this.currentRow[columnIndex - 1]; - this.setWasNull(obj); - - try { - return (obj == null) - ? Boolean.FALSE - : Boolean.valueOf(obj.toString()); - - } catch (NumberFormatException e) { - throw new SQLException(e.getMessage()); - } - } - - /** - * Gets the byte value at the given column index. - * @param columnIndex A 1 based index. - * @throws SQLException if a database access error occurs - */ - protected Object getByte(int columnIndex) throws SQLException { - Object obj = this.currentRow[columnIndex - 1]; - this.setWasNull(obj); - - try { - return (obj == null) - ? Byte.valueOf((byte) 0) - : Byte.valueOf(obj.toString()); - - } catch (NumberFormatException e) { - throw new SQLException(e.getMessage()); - } - } - - /** - * Gets the double value at the given column index. - * @param columnIndex A 1 based index. - * @throws SQLException if a database access error occurs - */ - protected Object getDouble(int columnIndex) throws SQLException { - Object obj = this.currentRow[columnIndex - 1]; - this.setWasNull(obj); - - try { - return (obj == null) - ? new Double(0) - : Double.valueOf(obj.toString()); - - } catch (NumberFormatException e) { - throw new SQLException(e.getMessage()); - } - } - - /** - * Gets the float value at the given column index. - * @param columnIndex A 1 based index. - * @throws SQLException if a database access error occurs - */ - protected Object getFloat(int columnIndex) throws SQLException { - Object obj = this.currentRow[columnIndex - 1]; - this.setWasNull(obj); - - try { - return (obj == null) ? new Float(0) : Float.valueOf(obj.toString()); - - } catch (NumberFormatException e) { - throw new SQLException(e.getMessage()); - } - } - - /** - * Gets the int value at the given column index. - * @param columnIndex A 1 based index. - * @throws SQLException if a database access error occurs - */ - protected Object getInt(int columnIndex) throws SQLException { - Object obj = this.currentRow[columnIndex - 1]; - this.setWasNull(obj); - - try { - return (obj == null) - ? Integer.valueOf(0) - : Integer.valueOf(obj.toString()); - - } catch (NumberFormatException e) { - throw new SQLException(e.getMessage()); - } - } - - /** - * Gets the long value at the given column index. - * @param columnIndex A 1 based index. - * @throws SQLException if a database access error occurs - */ - protected Object getLong(int columnIndex) throws SQLException { - Object obj = this.currentRow[columnIndex - 1]; - this.setWasNull(obj); - - try { - return (obj == null) ? Long.valueOf(0) : Long.valueOf(obj.toString()); - - } catch (NumberFormatException e) { - throw new SQLException(e.getMessage()); - } - } - - /** - * @throws SQLException - */ - protected ResultSetMetaData getMetaData() throws SQLException { - return this.metaData; - } - - /** - * Gets the object at the given column index. - * @param columnIndex A 1 based index. - * @throws SQLException if a database access error occurs - */ - protected Object getObject(int columnIndex) throws SQLException { - Object obj = this.currentRow[columnIndex - 1]; - this.setWasNull(obj); - return obj; - } - - /** - * Gets the short value at the given column index. - * @param columnIndex A 1 based index. - * @throws SQLException if a database access error occurs - */ - protected Object getShort(int columnIndex) throws SQLException { - Object obj = this.currentRow[columnIndex - 1]; - this.setWasNull(obj); - - try { - return (obj == null) - ? Short.valueOf((short) 0) - : Short.valueOf(obj.toString()); - - } catch (NumberFormatException e) { - throw new SQLException(e.getMessage()); - } - } - - /** - * Gets the String at the given column index. - * @param columnIndex A 1 based index. - * @throws SQLException if a database access error occurs - */ - protected String getString(int columnIndex) throws SQLException { - Object obj = this.getObject(columnIndex); - this.setWasNull(obj); - return (obj == null) ? null : obj.toString(); - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - - String methodName = method.getName(); - - if (methodName.equals("getMetaData")) { - return this.getMetaData(); - - } else if (methodName.equals("next")) { - return this.next(); - - } else if (methodName.equals("previous")) { - - } else if (methodName.equals("close")) { - - } else if (methodName.equals("getBoolean")) { - return this.getBoolean(columnIndex(args)); - - } else if (methodName.equals("getByte")) { - return this.getByte(columnIndex(args)); - - } else if (methodName.equals("getDouble")) { - return this.getDouble(columnIndex(args)); - - } else if (methodName.equals("getFloat")) { - return this.getFloat(columnIndex(args)); - - } else if (methodName.equals("getInt")) { - return this.getInt(columnIndex(args)); - - } else if (methodName.equals("getLong")) { - return this.getLong(columnIndex(args)); - - } else if (methodName.equals("getObject")) { - return this.getObject(columnIndex(args)); - - } else if (methodName.equals("getShort")) { - return this.getShort(columnIndex(args)); - - } else if (methodName.equals("getString")) { - return this.getString(columnIndex(args)); - - } else if (methodName.equals("wasNull")) { - return this.wasNull(); - - } else if (methodName.equals("isLast")) { - return this.isLast(); - - } else if (methodName.equals("hashCode")) { - return Integer.valueOf(System.identityHashCode(proxy)); - - } else if (methodName.equals("toString")) { - return "MockResultSet " + System.identityHashCode(proxy); - - } else if (methodName.equals("equals")) { - return Boolean.valueOf(proxy == args[0]); - } - - throw new UnsupportedOperationException("Unsupported method: " + methodName); - } - - /** - * @throws SQLException - */ - protected Boolean isLast() throws SQLException { - return this.iter.hasNext() ? Boolean.FALSE : Boolean.TRUE; - } - - /** - * @throws SQLException - */ - protected Boolean next() throws SQLException { - if (!this.iter.hasNext()) { - return Boolean.FALSE; - } else { - this.currentRow = iter.next(); - return Boolean.TRUE; - } - } - - /** - * Assigns this.wasNull a Boolean value based on the object passed in. - * @param isNull - */ - private void setWasNull(Object isNull) { - this.wasNull = (isNull == null) ? Boolean.TRUE : Boolean.FALSE; - } - - /** - * @throws SQLException - */ - protected Boolean wasNull() throws SQLException { - return this.wasNull; - } -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java b/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java deleted file mode 100644 index 2e02807..0000000 --- a/src/test/java/org/apache/commons/dbutils/MockResultSetMetaData.java +++ /dev/null @@ -1,95 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; -import java.sql.ResultSetMetaData; - -/** - * MockResultSetMetaData dynamically implements the ResultSetMetaData - * interface. - */ -public class MockResultSetMetaData implements InvocationHandler { - - private String[] columnNames = null; - private String[] columnLabels = null; - - /** - * Create a <code>MockResultSetMetaData</code> proxy object. This is - * equivalent to: - * <pre> - * ProxyFactory.instance().createResultSetMetaData(new MockResultSetMetaData(columnNames)); - * </pre> - * - * @param columnNames - * @return the proxy object - */ - public static ResultSetMetaData create(String[] columnNames) { - return ProxyFactory.instance().createResultSetMetaData( - new MockResultSetMetaData(columnNames)); - } - - public MockResultSetMetaData(String[] columnNames) { - super(); - this.columnNames = columnNames; - this.columnLabels = new String[columnNames.length]; - - } - - public MockResultSetMetaData(String[] columnNames, String[] columnLabels) { - super(); - this.columnNames = columnNames; - this.columnLabels = columnLabels; - - } - - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - - String methodName = method.getName(); - - if (methodName.equals("getColumnCount")) { - return Integer.valueOf(this.columnNames.length); - - } else if ( - methodName.equals("getColumnName")) { - - int col = ((Integer) args[0]).intValue() - 1; - return this.columnNames[col]; - - } else if ( - methodName.equals("getColumnLabel")) { - - int col = ((Integer) args[0]).intValue() - 1; - return this.columnLabels[col]; - - } else if (methodName.equals("hashCode")) { - return Integer.valueOf(System.identityHashCode(proxy)); - - } else if (methodName.equals("toString")) { - return "MockResultSetMetaData " + System.identityHashCode(proxy); - - } else if (methodName.equals("equals")) { - return Boolean.valueOf(proxy == args[0]); - - } else { - throw new UnsupportedOperationException("Unsupported method: " + methodName); - } - } -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java b/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java deleted file mode 100644 index 9466e2f..0000000 --- a/src/test/java/org/apache/commons/dbutils/ProxyFactoryTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import java.lang.reflect.InvocationHandler; -import java.lang.reflect.Method; - -/** - * ProxyFactoryTest performs simple type checking on proxy objects returned - * from a ProxyFactory. - */ -public class ProxyFactoryTest extends BaseTestCase { - - private static final InvocationHandler stub = new InvocationHandler() { - - @Override - public Object invoke(Object proxy, Method method, Object[] args) - throws Throwable { - - return null; - } - }; - - public void testCreateConnection() { - assertNotNull(ProxyFactory.instance().createConnection(stub)); - } - - public void testCreateDriver() { - assertNotNull(ProxyFactory.instance().createDriver(stub)); - } - - public void testCreatePreparedStatement() { - assertNotNull(ProxyFactory.instance().createPreparedStatement(stub)); - } - - public void testCreateResultSet() { - assertNotNull(ProxyFactory.instance().createResultSet(stub)); - } - - public void testCreateResultSetMetaData() { - assertNotNull(ProxyFactory.instance().createResultSetMetaData(stub)); - } - - public void testCreateStatement() { - assertNotNull(ProxyFactory.instance().createStatement(stub)); - } - - public void testCreateCallableStatement() { - assertNotNull(ProxyFactory.instance().createCallableStatement(stub)); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/QueryExecutorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/QueryExecutorTest.java b/src/test/java/org/apache/commons/dbutils/QueryExecutorTest.java deleted file mode 100644 index 487fed3..0000000 --- a/src/test/java/org/apache/commons/dbutils/QueryExecutorTest.java +++ /dev/null @@ -1,91 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - - -public class QueryExecutorTest { - - private QueryExecutor executor; - - @Mock private ResultSetHandler<Object> handler; - @Mock private Connection conn; - @Mock private PreparedStatement stmt; - @Mock private ResultSet resultSet; - - @Before - public void setup() throws SQLException { - MockitoAnnotations.initMocks(this); - - when(conn.prepareStatement(any(String.class))).thenReturn(stmt); - when(stmt.executeQuery()).thenReturn(resultSet); - when(handler.handle(any(ResultSet.class))).thenReturn(new Object()); - } - - protected void createExecutor(String sql) throws Exception { - executor = new QueryExecutor(conn, sql, true); - } - - @Test - public void testGoodSQL() throws Exception { - createExecutor("insert into blah"); - - Object ret = executor.execute(handler); - - assertNotNull(ret); - verify(handler, times(1)).handle(resultSet); - verify(conn, times(1)).close(); - verify(stmt, times(1)).close(); - } - - @Test(expected=SQLException.class) - public void testUnmappedParams() throws Exception { - createExecutor("insert into blah (:something)"); - - Object ret = executor.execute(handler); - - assertNotNull(ret); - verify(handler, times(1)).handle(resultSet); - verify(conn, times(1)).close(); - verify(stmt, times(1)).close(); - } - - @Test(expected=SQLException.class) - public void testNullHandler() throws Exception { - createExecutor("insert into blah"); - - Object ret = executor.execute(null); - - assertNotNull(ret); - verify(handler, times(1)).handle(resultSet); - verify(conn, times(1)).close(); - verify(stmt, times(1)).close(); - } -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/QueryLoaderTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/QueryLoaderTest.java b/src/test/java/org/apache/commons/dbutils/QueryLoaderTest.java deleted file mode 100644 index c4f42b6..0000000 --- a/src/test/java/org/apache/commons/dbutils/QueryLoaderTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import java.io.IOException; -import java.util.Map; - -/** - * QueryLoaderTest - */ -public class QueryLoaderTest extends BaseTestCase { - - private static final String QUERIES = - "/org/apache/commons/dbutils/TestQueries.properties"; - - public void testLoad() throws IOException { - try { - QueryLoader loader = QueryLoader.instance(); - Map<String,String> q = loader.load(QUERIES); - Map<String,String> q2 = loader.load(QUERIES); - assertTrue(q == q2); // pointer comparison should return true - assertEquals("SELECT * FROM SomeTable", q.get("test.query")); - - loader.unload(QUERIES); - Map<String,String> q3 = loader.load(QUERIES); - assertTrue(q != q3); // pointer comparison should return false - - } catch (IllegalArgumentException e) { - // TODO Figure out why the Maven build can't find the properties - // file. The tests run fine in Eclipse so just catch this - // exception for now. - } - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java b/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java deleted file mode 100644 index 79e24cd..0000000 --- a/src/test/java/org/apache/commons/dbutils/QueryRunnerTest.java +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import static org.junit.Assert.assertNotNull; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.sql.Connection; -import java.sql.SQLException; -import javax.sql.DataSource; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -@SuppressWarnings("boxing") // test code -public class QueryRunnerTest { - QueryRunner runner; - - @Mock DataSource dataSource; - @Mock Connection conn; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); // init the mocks - - when(dataSource.getConnection()).thenReturn(conn); - runner = new QueryRunner(dataSource); - } - - // batch tests - - @Test - public void testBatchSQL() throws SQLException { - assertNotNull(runner.batch("select * from blah where :first=first")); - verify(dataSource, times(1)).getConnection(); - } - - @Test - public void testBatchConnSQL() throws SQLException { - assertNotNull(runner.batch(conn, "select * from blah where :first=first")); - } - - @Test - public void testBatchConnSQLBoolean() throws SQLException { - assertNotNull(runner.batch(conn, true, "select * from blah where :first=first")); - } - - @Test(expected=SQLException.class) - public void testBatchNullConn() throws SQLException { - assertNotNull(runner.batch(null, true, "select")); - } - - @Test(expected=SQLException.class) - public void testBatchNullSQL() throws SQLException { - assertNotNull(runner.batch(conn, true, null)); - } - - // query tests - - @Test - public void testQuerySQL() throws SQLException { - assertNotNull(runner.query("select * from blah where :first=first")); - verify(dataSource, times(1)).getConnection(); - } - - @Test - public void testQueryConnSQL() throws SQLException { - assertNotNull(runner.query(conn, "select * from blah where :first=first")); - } - - @Test - public void testQueryConnSQLBoolean() throws SQLException { - assertNotNull(runner.query(conn, true, "select * from blah where :first=first")); - } - - @Test(expected=SQLException.class) - public void testQueryNullConn() throws SQLException { - assertNotNull(runner.query(null, true, "select")); - } - - @Test(expected=SQLException.class) - public void testQueryNullSQL() throws SQLException { - assertNotNull(runner.query(conn, true, null)); - } - - // insert tests - - @Test - public void testInsertSQL() throws SQLException { - assertNotNull(runner.insert("insert * from blah where :first=first")); - verify(dataSource, times(1)).getConnection(); - } - - @Test - public void testInsertConnSQL() throws SQLException { - assertNotNull(runner.insert(conn, "insert * from blah where :first=first")); - } - - @Test - public void testInsertConnSQLBoolean() throws SQLException { - assertNotNull(runner.insert(conn, true, "insert * from blah where :first=first")); - } - - @Test(expected=SQLException.class) - public void testInsertNullConn() throws SQLException { - assertNotNull(runner.insert(null, true, "select")); - } - - @Test(expected=SQLException.class) - public void testInsertNullSQL() throws SQLException { - assertNotNull(runner.insert(conn, true, null)); - } - - // update tests - - @Test - public void testUpdateSQL() throws SQLException { - assertNotNull(runner.update("select * from blah where :first=first")); - verify(dataSource, times(1)).getConnection(); - } - - @Test - public void testUpdateConnSQL() throws SQLException { - assertNotNull(runner.update(conn, "select * from blah where :first=first")); - } - - @Test - public void testUpdateConnSQLBoolean() throws SQLException { - assertNotNull(runner.update(conn, true, "select * from blah where :first=first")); - } - - @Test(expected=SQLException.class) - public void testUpdateNullConn() throws SQLException { - assertNotNull(runner.update(null, true, "select")); - } - - @Test(expected=SQLException.class) - public void testUpdateNullSQL() throws SQLException { - assertNotNull(runner.update(conn, true, null)); - } - - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/ResultSetIteratorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/ResultSetIteratorTest.java b/src/test/java/org/apache/commons/dbutils/ResultSetIteratorTest.java deleted file mode 100644 index fbe0bbd..0000000 --- a/src/test/java/org/apache/commons/dbutils/ResultSetIteratorTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import java.util.Iterator; - -/** - * ResultSetIteratorTest - */ -public class ResultSetIteratorTest extends BaseTestCase { - - public void testNext() { - - Iterator<Object[]> iter = new ResultSetIterator(this.rs); - - Object[] row = null; - assertTrue(iter.hasNext()); - row = iter.next(); - assertEquals(COLS, row.length); - assertEquals("1", row[0]); - assertEquals("2", row[1]); - assertEquals("3", row[2]); - - assertTrue(iter.hasNext()); - row = iter.next(); - assertEquals(COLS, row.length); - - assertEquals("4", row[0]); - assertEquals("5", row[1]); - assertEquals("6", row[2]); - - assertFalse(iter.hasNext()); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/TestBean.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/TestBean.java b/src/test/java/org/apache/commons/dbutils/TestBean.java deleted file mode 100644 index 0b6156d..0000000 --- a/src/test/java/org/apache/commons/dbutils/TestBean.java +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -/** - * A bean to use in testing toBean() and toBeanList(). - */ -public class TestBean { - - private String one = null; - - private String two = null; - - private String three = null; - - private int intTest = 0; - - private Integer integerTest = Integer.valueOf(0); - - private String doNotSet = "not set"; - - /** - * toBean() should set primitive fields to their defaults (ie. 0) when - * null is returned from the ResultSet. - */ - private int nullPrimitiveTest = 7; - - /** - * toBean() should set Object fields to null when null is returned from the - * ResultSet - */ - private Object nullObjectTest = "overwrite"; - - /** - * A Date will be returned from the ResultSet but the property is a String. - * BeanProcessor should create a String from the Date and set this property. - */ - private String notDate = "not a date"; - - /** - * The ResultSet will have a BigDecimal in this column and the - * BasicColumnProcessor should convert that to a double and store the value - * in this property. - */ - private double columnProcessorDoubleTest = -1; - - /** - * Constructor for TestBean. - */ - public TestBean() { - super(); - } - - public String getOne() { - return one; - } - - public String getThree() { - return three; - } - - public String getTwo() { - return two; - } - - public void setOne(String string) { - one = string; - } - - public void setThree(String string) { - three = string; - } - - public void setTwo(String string) { - two = string; - } - - public String getDoNotSet() { - return doNotSet; - } - - public void setDoNotSet(String string) { - doNotSet = string; - } - - public Integer getIntegerTest() { - return integerTest; - } - - public int getIntTest() { - return intTest; - } - - public void setIntegerTest(Integer integer) { - integerTest = integer; - } - - public void setIntTest(int i) { - intTest = i; - } - - public Object getNullObjectTest() { - return nullObjectTest; - } - - public int getNullPrimitiveTest() { - return nullPrimitiveTest; - } - - public void setNullObjectTest(Object object) { - nullObjectTest = object; - } - - public void setNullPrimitiveTest(int i) { - nullPrimitiveTest = i; - } - - public String getNotDate() { - return notDate; - } - - public void setNotDate(String string) { - notDate = string; - } - - public double getColumnProcessorDoubleTest() { - return columnProcessorDoubleTest; - } - - public void setColumnProcessorDoubleTest(double d) { - columnProcessorDoubleTest = d; - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/UpdateExecutorTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/UpdateExecutorTest.java b/src/test/java/org/apache/commons/dbutils/UpdateExecutorTest.java deleted file mode 100644 index 1b2cebf..0000000 --- a/src/test/java/org/apache/commons/dbutils/UpdateExecutorTest.java +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils; - -import static org.junit.Assert.*; -import static org.mockito.Matchers.any; -import static org.mockito.Mockito.times; -import static org.mockito.Mockito.verify; -import static org.mockito.Mockito.when; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.SQLException; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - - -public class UpdateExecutorTest { - - private UpdateExecutor executor; - - @Mock private Connection conn; - @Mock private PreparedStatement stmt; - - @Before - public void setup() throws SQLException { - MockitoAnnotations.initMocks(this); - - when(conn.prepareStatement(any(String.class))).thenReturn(stmt); - when(stmt.executeUpdate()).thenReturn(20); - } - - protected void createExecutor(String sql) throws Exception { - executor = new UpdateExecutor(conn, sql, true); - } - - @Test - public void testGoodSQL() throws Exception { - createExecutor("insert into blah"); - - int ret = executor.execute(); - - assertEquals(20, ret); - verify(conn, times(1)).close(); - verify(stmt, times(1)).close(); - } - - @Test(expected=SQLException.class) - public void testUnmappedParams() throws Exception { - createExecutor("insert into blah (:something)"); - - int ret = executor.execute(); - - assertEquals(20, ret); - verify(conn, times(1)).close(); - verify(stmt, times(1)).close(); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java deleted file mode 100644 index 7c5a829..0000000 --- a/src/test/java/org/apache/commons/dbutils/handlers/ArrayHandlerTest.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils.handlers; - -import java.sql.SQLException; - -import org.apache.commons.dbutils.BaseTestCase; -import org.apache.commons.dbutils.ResultSetHandler; - -/** - * ArrayHandlerTest - */ -public class ArrayHandlerTest extends BaseTestCase { - - public void testHandle() throws SQLException { - ResultSetHandler<Object[]> h = new ArrayHandler(); - Object[] results = h.handle(this.rs); - - assertNotNull(results); - assertEquals(COLS, results.length); - assertEquals("1", results[0]); - assertEquals("2", results[1]); - assertEquals("3", results[2]); - } - - public void testEmptyResultSetHandle() throws SQLException { - ResultSetHandler<Object[]> h = new ArrayHandler(); - Object[] results = h.handle(this.emptyResultSet); - - assertNull(results); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java deleted file mode 100644 index ea66215..0000000 --- a/src/test/java/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java +++ /dev/null @@ -1,66 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils.handlers; - -import java.sql.SQLException; -import java.util.Iterator; -import java.util.List; - -import org.apache.commons.dbutils.BaseTestCase; -import org.apache.commons.dbutils.ResultSetHandler; - -/** - * ArrayListHandlerTest - */ -public class ArrayListHandlerTest extends BaseTestCase { - - public void testHandle() throws SQLException { - ResultSetHandler<List<Object[]>> h = new ArrayListHandler(); - List<Object[]> results = h.handle(this.rs); - - assertNotNull(results); - assertEquals(ROWS, results.size()); - - Iterator<Object[]> iter = results.iterator(); - Object[] row = null; - assertTrue(iter.hasNext()); - row = iter.next(); - assertEquals(COLS, row.length); - assertEquals("1", row[0]); - assertEquals("2", row[1]); - assertEquals("3", row[2]); - - assertTrue(iter.hasNext()); - row = iter.next(); - assertEquals(COLS, row.length); - - assertEquals("4", row[0]); - assertEquals("5", row[1]); - assertEquals("6", row[2]); - - assertFalse(iter.hasNext()); - } - - public void testEmptyResultSetHandle() throws SQLException { - ResultSetHandler<List<Object[]>> h = new ArrayListHandler(); - List<Object[]> results = h.handle(this.emptyResultSet); - - assertNotNull(results); - assertTrue(results.isEmpty()); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java deleted file mode 100644 index 6c4d6a0..0000000 --- a/src/test/java/org/apache/commons/dbutils/handlers/BeanHandlerTest.java +++ /dev/null @@ -1,48 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils.handlers; - -import java.sql.SQLException; - -import org.apache.commons.dbutils.BaseTestCase; -import org.apache.commons.dbutils.ResultSetHandler; -import org.apache.commons.dbutils.TestBean; - -/** - * BeanHandlerTest - */ -public class BeanHandlerTest extends BaseTestCase { - - public void testHandle() throws SQLException { - ResultSetHandler<TestBean> h = new BeanHandler<TestBean>(TestBean.class); - TestBean results = h.handle(this.rs); - - assertNotNull(results); - assertEquals("1", results.getOne()); - assertEquals("2", results.getTwo()); - assertEquals("3", results.getThree()); - assertEquals("not set", results.getDoNotSet()); - } - - public void testEmptyResultSetHandle() throws SQLException { - ResultSetHandler<TestBean> h = new BeanHandler<TestBean>(TestBean.class); - TestBean results = h.handle(this.emptyResultSet); - - assertNull(results); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java deleted file mode 100644 index 8157e93..0000000 --- a/src/test/java/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils.handlers; - -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.apache.commons.dbutils.TestBean; - -/** - * BeanListHandlerTest - */ -public class BeanListHandlerTest extends BaseTestCase { - - public void testHandle() throws SQLException { - ResultSetHandler<List<TestBean>> h = new BeanListHandler<TestBean>(TestBean.class); - List<TestBean> results = h.handle(this.rs); - - assertNotNull(results); - assertEquals(ROWS, results.size()); - - Iterator<TestBean> iter = results.iterator(); - TestBean row = null; - assertTrue(iter.hasNext()); - row = iter.next(); - assertEquals("1", row.getOne()); - assertEquals("2", row.getTwo()); - assertEquals("3", row.getThree()); - assertEquals("not set", row.getDoNotSet()); - - assertTrue(iter.hasNext()); - row = iter.next(); - - assertEquals("4", row.getOne()); - assertEquals("5", row.getTwo()); - assertEquals("6", row.getThree()); - assertEquals("not set", row.getDoNotSet()); - - assertFalse(iter.hasNext()); - } - - public void testEmptyResultSetHandle() throws SQLException { - ResultSetHandler<List<TestBean>> h = new BeanListHandler<TestBean>(TestBean.class); - List<TestBean> results = h.handle(this.emptyResultSet); - - assertNotNull(results); - assertTrue(results.isEmpty()); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java deleted file mode 100644 index 09ae157..0000000 --- a/src/test/java/org/apache/commons/dbutils/handlers/BeanMapHandlerTest.java +++ /dev/null @@ -1,90 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils.handlers; - -import static org.junit.Assert.*; -import static org.mockito.Mockito.when; - -import java.sql.ResultSet; -import java.sql.ResultSetMetaData; -import java.util.Map; - -import org.apache.commons.dbutils.RowProcessor; -import org.apache.commons.dbutils.TestBean; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; - -public class BeanMapHandlerTest { - - private BeanMapHandler<Long, TestBean> bmh; - private Map<Long, TestBean> res; - @Mock private ResultSet rs; - @Mock private ResultSetMetaData rsmd; - @Mock private RowProcessor rp; - - @Before - public void setUp() throws Exception { - MockitoAnnotations.initMocks(this); - - when(Boolean.valueOf(rs.next())).thenReturn(Boolean.TRUE, Boolean.FALSE); - when(rs.getObject(1)).thenReturn(Long.valueOf(23L)); - when(rs.getObject(2)).thenReturn(Long.valueOf(23L)); - when(rs.getObject("id")).thenReturn(Long.valueOf(23L)); - when(rs.getMetaData()).thenReturn(rsmd); - when(rp.toBean(rs, TestBean.class)).thenReturn(new TestBean()); - } - - private void handle() throws Exception { - res = bmh.handle(rs); - assertNotNull(res.get(Long.valueOf(23L))); - } - - @Test - public void testBeanMapHandlerClassOfV() throws Exception { - bmh = new BeanMapHandler<Long, TestBean>(TestBean.class); - handle(); - } - - @Test - public void testBeanMapHandlerClassOfVRowProcessor() throws Exception { - bmh = new BeanMapHandler<Long, TestBean>(TestBean.class, rp); - handle(); - } - - @Test - public void testBeanMapHandlerClassOfVInt() throws Exception { - bmh = new BeanMapHandler<Long, TestBean>(TestBean.class, 2); - handle(); - } - - @Test - public void testBeanMapHandlerClassOfVString() throws Exception { - bmh = new BeanMapHandler<Long, TestBean>(TestBean.class, "id"); - handle(); - } - - @Test - public void testEmptyResultSet() throws Exception { - when(Boolean.valueOf(rs.next())).thenReturn(Boolean.FALSE); - bmh = new BeanMapHandler<Long, TestBean>(TestBean.class); - res = bmh.handle(rs); - assertNull(res.get(Long.valueOf(23L))); - } - -} http://git-wip-us.apache.org/repos/asf/commons-dbutils/blob/41d6d58c/src/test/java/org/apache/commons/dbutils/handlers/ColumnListHandlerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/dbutils/handlers/ColumnListHandlerTest.java b/src/test/java/org/apache/commons/dbutils/handlers/ColumnListHandlerTest.java deleted file mode 100644 index 141d2a6..0000000 --- a/src/test/java/org/apache/commons/dbutils/handlers/ColumnListHandlerTest.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.dbutils.handlers; - -import java.sql.SQLException; -import java.util.List; - -import org.apache.commons.dbutils.BaseTestCase; -import org.apache.commons.dbutils.ResultSetHandler; - -/** - * ColumnListHandlerTest - */ -public class ColumnListHandlerTest extends BaseTestCase { - - public void testHandle() throws SQLException { - ResultSetHandler<List<String>> h = new ColumnListHandler<String>(); - List<String> results = h.handle(this.rs); - - assertNotNull(results); - assertEquals(ROWS, results.size()); - - assertEquals("1", results.get(0)); - assertEquals("4", results.get(1)); - } - - public void testColumnIndexHandle() throws SQLException { - ResultSetHandler<List<String>> h = new ColumnListHandler<String>(2); - List<String> results = h.handle(this.rs); - - assertNotNull(results); - assertEquals(ROWS, results.size()); - - assertEquals("2", results.get(0)); - assertEquals("5", results.get(1)); - } - - public void testColumnNameHandle() throws SQLException { - ResultSetHandler<List<Integer>> h = new ColumnListHandler<Integer>("intTest"); - List<Integer> results = h.handle(this.rs); - - assertNotNull(results); - assertEquals(ROWS, results.size()); - - assertEquals(new Integer(1), results.get(0)); - assertEquals(new Integer(3), results.get(1)); - } - - public void testEmptyResultSetHandle() throws SQLException { - ResultSetHandler<List<String>> h = new ColumnListHandler<String>(); - List<String> results = h.handle(this.emptyResultSet); - - assertNotNull(results); - assertTrue(results.isEmpty()); - } - -}
