Commits

tbrugz committed b9306aa

resultset: fix for ResultSetListAdapter;
ResultSetCollectionAdapterchanged changed constructor, tests added

  • Participants
  • Parent commits 8cffc74

Comments (0)

Files changed (3)

src/tbrugz/queryon/resultset/ResultSetCollectionAdapter.java

 
 	final Iterator<E> iterator;
 	
-	public ResultSetCollectionAdapter(String name, List<String> uniqueCols, Collection<E> list) throws IntrospectionException {
-		super(name, uniqueCols, (Class<E>) list.iterator().next().getClass());
+	public ResultSetCollectionAdapter(String name, List<String> uniqueCols, Collection<E> list, Class<E> clazz) throws IntrospectionException {
+		super(name, uniqueCols, clazz);
 		iterator = list.iterator();
 	}
 	

src/tbrugz/queryon/resultset/ResultSetListAdapter.java

 import org.apache.commons.logging.LogFactory;
 
 public class ResultSetListAdapter<E extends Object> extends BaseResultSetCollectionAdapter<E> {
-	static final Log log = LogFactory.getLog(ResultSetCollectionAdapter.class);
+	static final Log log = LogFactory.getLog(ResultSetListAdapter.class);
 
 	final List<E> list;
 	int position;
 	}
 	
 	public ResultSetListAdapter(String name, List<String> uniqueCols, List<String> allCols, List<E> list, Class<E> clazz) throws IntrospectionException {
-		super(name, uniqueCols, allCols, (Class<E>) list.iterator().next().getClass());
+		super(name, uniqueCols, allCols, clazz);
 		this.list = list;
 		//Initially the cursor is positioned before the first row
 		resetPosition();

src_test/tbrugz/queryon/resultset/ResultSetTest.java

 import java.beans.IntrospectionException;
 import java.sql.SQLException;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.junit.Assert;
 import org.junit.Before;
 		ResultSetListAdapter<TestBean> rs = new ResultSetListAdapter<TestBean>("testbeanLA", TestBean.getUniqueCols(), TestBean.getAllCols(), l1, TestBean.class);
 		Assert.assertFalse("Must not have any element", rs.next());
 	}
+	
+	@Test
+	public void testRSCollectionAdapterWithList() throws IntrospectionException, SQLException {
+		ResultSetCollectionAdapter<TestBean> rs = new ResultSetCollectionAdapter<TestBean>("testbeanLA", TestBean.getUniqueCols(), l1, TestBean.class);
+		for(int i=1;i<=3;i++) {
+			Assert.assertTrue("Must have "+i+" element", rs.next());
+		}
+		Assert.assertFalse("Must not have 4th element", rs.next());
+	}
+
+	@Test
+	public void testRSCollectionAdapterWithSet() throws IntrospectionException, SQLException {
+		Set<TestBean> set = new HashSet<TestBean>();
+		set.addAll(l1);
+		
+		ResultSetCollectionAdapter<TestBean> rs = new ResultSetCollectionAdapter<TestBean>("testbeanLA", TestBean.getUniqueCols(), set, TestBean.class);
+		for(int i=1;i<=3;i++) {
+			Assert.assertTrue("Must have "+i+" element", rs.next());
+		}
+		Assert.assertFalse("Must not have 4th element", rs.next());
+	}
 }