commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dfabul...@apache.org
Subject svn commit: r752322 - in /commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils: ./ handlers/
Date Wed, 11 Mar 2009 00:36:43 GMT
Author: dfabulich
Date: Wed Mar 11 00:36:43 2009
New Revision: 752322

URL: http://svn.apache.org/viewvc?rev=752322&view=rev
Log:
Fixing tests based on sebb's feedback.

Modified:
    commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java
    commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BeanProcessorTest.java
    commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ProxyFactoryTest.java
    commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ResultSetIteratorTest.java
    commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java
    commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
    commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/MapListHandlerTest.java

Modified: commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java?rev=752322&r1=752321&r2=752322&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java
(original)
+++ commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BasicRowProcessorTest.java
Wed Mar 11 00:36:43 2009
@@ -40,43 +40,53 @@
 
     public void testToArray() throws SQLException {
 
-        int rowCount = 0;
         Object[] a = null;
-        while (this.rs.next()) {
-            a = processor.toArray(this.rs);
-            assertEquals(COLS, a.length);
-            rowCount++;
-        }
+        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(ROWS, rowCount);
         assertEquals("4", a[0]);
         assertEquals("5", a[1]);
         assertEquals("6", a[2]);
+            
+        assertFalse(this.rs.next());
     }
 
     public void testToBean() throws SQLException, ParseException {
 
-        int rowCount = 0;
-        TestBean b = null;
-        while (this.rs.next()) {
-            b = (TestBean) processor.toBean(this.rs, TestBean.class);
-            assertNotNull(b);
-            rowCount++;
-        }
-
-        assertEquals(ROWS, rowCount);
-        assertEquals("4", b.getOne());
-        assertEquals("5", b.getTwo());
-        assertEquals("6", b.getThree());
-        assertEquals("not set", b.getDoNotSet());
-        assertEquals(3, b.getIntTest());
-        assertEquals(new Integer(4), b.getIntegerTest());
-        assertEquals(null, b.getNullObjectTest());
-        assertEquals(0, b.getNullPrimitiveTest());
+        TestBean row = null;
+        assertTrue(this.rs.next());
+        row = (TestBean) 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 = (TestBean) 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(new Integer(4), row.getIntegerTest());
+        assertEquals(null, row.getNullObjectTest());
+        assertEquals(0, row.getNullPrimitiveTest());
         // test date -> string handling
-        assertNotNull(b.getNotDate());
-        assertTrue(!"not a date".equals(b.getNotDate()));
-        datef.parse(b.getNotDate());
+        assertNotNull(row.getNotDate());
+        assertTrue(!"not a date".equals(row.getNotDate()));
+        datef.parse(row.getNotDate());
+        
+        assertFalse(this.rs.next());
+        
     }
 
     public void testToBeanList() throws SQLException, ParseException {
@@ -85,8 +95,13 @@
         assertNotNull(list);
         assertEquals(ROWS, list.size());
 
-        TestBean b = (TestBean) list.get(1);
-
+        TestBean b = (TestBean) list.get(0);
+        assertEquals("1", b.getOne());
+        assertEquals("2", b.getTwo());
+        assertEquals("3", b.getThree());
+        assertEquals("not set", b.getDoNotSet());
+        
+        b = (TestBean) list.get(1);
         assertEquals("4", b.getOne());
         assertEquals("5", b.getTwo());
         assertEquals("6", b.getThree());
@@ -103,19 +118,22 @@
 
     public void testToMap() throws SQLException {
 
-        int rowCount = 0;
-        Map m = null;
-        while (this.rs.next()) {
-            m = processor.toMap(this.rs);
-            assertNotNull(m);
-            assertEquals(COLS, m.keySet().size());
-            rowCount++;
-        }
+        assertTrue(this.rs.next());
+        Map 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(ROWS, rowCount);
         assertEquals("4", m.get("One")); // case shouldn't matter
         assertEquals("5", m.get("two"));
         assertEquals("6", m.get("THREE"));
+            
+        assertFalse(this.rs.next());
     }
 
 }

Modified: commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BeanProcessorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BeanProcessorTest.java?rev=752322&r1=752321&r2=752322&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BeanProcessorTest.java
(original)
+++ commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/BeanProcessorTest.java
Wed Mar 11 00:36:43 2009
@@ -23,16 +23,16 @@
     private static final BeanProcessor beanProc = new BeanProcessor();
 
     public void testProcess() throws SQLException {
-        int rowCount = 0;
         TestBean b = null;
-        while (this.rs.next()) {
-            b = (TestBean) beanProc.toBean(this.rs, TestBean.class);
-            assertNotNull(b);
-            rowCount++;
-        }
-
-        assertEquals(ROWS, rowCount);
+        assertTrue(this.rs.next());
+        b = (TestBean) beanProc.toBean(this.rs, TestBean.class);
+        assertEquals(13.0, b.getColumnProcessorDoubleTest(), 0);
+        
+        assertTrue(this.rs.next());
+        b = (TestBean) beanProc.toBean(this.rs, TestBean.class);
         assertEquals(13.0, b.getColumnProcessorDoubleTest(), 0);
+
+        assertFalse(this.rs.next());
     }
 
 }

Modified: commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ProxyFactoryTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ProxyFactoryTest.java?rev=752322&r1=752321&r2=752322&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ProxyFactoryTest.java
(original)
+++ commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ProxyFactoryTest.java
Wed Mar 11 00:36:43 2009
@@ -18,13 +18,6 @@
 
 import java.lang.reflect.InvocationHandler;
 import java.lang.reflect.Method;
-import java.sql.CallableStatement;
-import java.sql.Connection;
-import java.sql.Driver;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.ResultSetMetaData;
-import java.sql.Statement;
 
 /**
  * ProxyFactoryTest performs simple type checking on proxy objects returned
@@ -42,42 +35,31 @@
 	};
 
 	public void testCreateConnection() {
-		assertTrue(
-			ProxyFactory.instance().createConnection(stub)
-				instanceof Connection);
+		assertNotNull(ProxyFactory.instance().createConnection(stub));
 	}
 
 	public void testCreateDriver() {
-		assertTrue(
-			ProxyFactory.instance().createDriver(stub) instanceof Driver);
+		assertNotNull(ProxyFactory.instance().createDriver(stub));
 	}
 
 	public void testCreatePreparedStatement() {
-		assertTrue(
-			ProxyFactory.instance().createPreparedStatement(stub)
-				instanceof PreparedStatement);
+		assertNotNull(ProxyFactory.instance().createPreparedStatement(stub));
 	}
 
 	public void testCreateResultSet() {
-		assertTrue(
-			ProxyFactory.instance().createResultSet(stub) instanceof ResultSet);
+		assertNotNull(ProxyFactory.instance().createResultSet(stub));
 	}
 
 	public void testCreateResultSetMetaData() {
-		assertTrue(
-			ProxyFactory.instance().createResultSetMetaData(stub)
-				instanceof ResultSetMetaData);
+		assertNotNull(ProxyFactory.instance().createResultSetMetaData(stub));
 	}
 
 	public void testCreateStatement() {
-		assertTrue(
-			ProxyFactory.instance().createStatement(stub) instanceof Statement);
+		assertNotNull(ProxyFactory.instance().createStatement(stub));
 	}
 
 	public void testCreateCallableStatement() {
-		assertTrue(
-			ProxyFactory.instance().createCallableStatement(stub)
-				instanceof CallableStatement);
+		assertNotNull(ProxyFactory.instance().createCallableStatement(stub));
 	}
 
 }

Modified: commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ResultSetIteratorTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ResultSetIteratorTest.java?rev=752322&r1=752321&r2=752322&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ResultSetIteratorTest.java
(original)
+++ commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/ResultSetIteratorTest.java
Wed Mar 11 00:36:43 2009
@@ -27,20 +27,23 @@
 		
 		Iterator iter = new ResultSetIterator(this.rs);
 
-		int rowCount = 0;
 		Object[] row = null;
-		while (iter.hasNext()) {
-			rowCount++;
-			row = (Object[]) iter.next();
-
-			assertNotNull(row);
-			assertEquals(COLS, row.length);
-		}
+		assertTrue(iter.hasNext());
+		row = (Object[]) iter.next();
+		assertEquals(COLS, row.length);
+		assertEquals("1", row[0]);
+		assertEquals("2", row[1]);
+		assertEquals("3", row[2]);
+		
+		assertTrue(iter.hasNext());
+		row = (Object[]) iter.next();
+		assertEquals(COLS, row.length);
 
-		assertEquals(ROWS, rowCount);
 		assertEquals("4", row[0]);
 		assertEquals("5", row[1]);
 		assertEquals("6", row[2]);
+		
+		assertFalse(iter.hasNext());
 	}
 
 }

Modified: commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java?rev=752322&r1=752321&r2=752322&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java
(original)
+++ commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/ArrayListHandlerTest.java
Wed Mar 11 00:36:43 2009
@@ -36,15 +36,23 @@
 		assertEquals(ROWS, results.size());
 
 		Iterator iter = results.iterator();
-		Object[] row = null;
-		while (iter.hasNext()) {
-			row = (Object[]) iter.next();
-			assertEquals(COLS, row.length);
-		}
+	    Object[] row = null;
+	    assertTrue(iter.hasNext());
+	    row = (Object[]) iter.next();
+	    assertEquals(COLS, row.length);
+	    assertEquals("1", row[0]);
+	    assertEquals("2", row[1]);
+	    assertEquals("3", row[2]);
+	        
+	    assertTrue(iter.hasNext());
+	    row = (Object[]) iter.next();
+	    assertEquals(COLS, row.length);
 
-		assertEquals("4", row[0]);
-		assertEquals("5", row[1]);
-		assertEquals("6", row[2]);
+	    assertEquals("4", row[0]);
+	    assertEquals("5", row[1]);
+	    assertEquals("6", row[2]);
+	        
+	    assertFalse(iter.hasNext());
 	}
 
 	public void testEmptyResultSetHandle() throws SQLException {

Modified: commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java?rev=752322&r1=752321&r2=752322&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
(original)
+++ commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/BeanListHandlerTest.java
Wed Mar 11 00:36:43 2009
@@ -38,15 +38,22 @@
 
 		Iterator iter = results.iterator();
 		TestBean row = null;
-		while (iter.hasNext()) {
-			row = (TestBean) iter.next();
-			assertNotNull(row);
-		}
+        assertTrue(iter.hasNext());
+        row = (TestBean) iter.next();
+        assertEquals("1", row.getOne());
+        assertEquals("2", row.getTwo());
+        assertEquals("3", row.getThree());
+        assertEquals("not set", row.getDoNotSet());
+            
+        assertTrue(iter.hasNext());
+        row = (TestBean) iter.next();
 
-		assertEquals("4", row.getOne());
-		assertEquals("5", row.getTwo());
-		assertEquals("6", row.getThree());
-		assertEquals("not set", row.getDoNotSet());
+        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 {

Modified: commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/MapListHandlerTest.java
URL: http://svn.apache.org/viewvc/commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/MapListHandlerTest.java?rev=752322&r1=752321&r2=752322&view=diff
==============================================================================
--- commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/MapListHandlerTest.java
(original)
+++ commons/proper/dbutils/trunk/src/test/org/apache/commons/dbutils/handlers/MapListHandlerTest.java
Wed Mar 11 00:36:43 2009
@@ -38,14 +38,22 @@
 
 		Iterator iter = results.iterator();
         Map row = null;
-		while (iter.hasNext()) {
-			row = (Map) iter.next();
-			assertEquals(COLS, row.keySet().size());
-		}
+        assertTrue(iter.hasNext());
+        row = (Map) iter.next();
+        assertEquals(COLS, row.keySet().size());
+        assertEquals("1", row.get("one"));
+        assertEquals("2", row.get("TWO"));
+        assertEquals("3", row.get("Three"));
+            
+        assertTrue(iter.hasNext());
+        row = (Map) iter.next();
+        assertEquals(COLS, row.keySet().size());
 
-		assertEquals("4", row.get("one"));
-		assertEquals("5", row.get("TWO"));
-		assertEquals("6", row.get("Three"));
+        assertEquals("4", row.get("one"));
+        assertEquals("5", row.get("TWO"));
+        assertEquals("6", row.get("Three"));
+            
+        assertFalse(iter.hasNext());
 	}
 
 	public void testEmptyResultSetHandle() throws SQLException {



Mime
View raw message