KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > util > cursor > impl > CursorImplTest


1 package org.sapia.util.cursor.impl;
2
3 import java.util.ArrayList JavaDoc;
4 import java.util.List JavaDoc;
5
6 import org.sapia.util.cursor.Batch;
7 import org.sapia.util.cursor.Cursor;
8
9 import junit.framework.TestCase;
10
11 /**
12  * @author Yanick Duchesne
13  *
14  * <dl>
15  * <dt><b>Copyright:</b><dd>Copyright &#169; 2002-2004 <a HREF="http://www.sapia-oss.org">Sapia Open Source Software</a>. All Rights Reserved.</dd></dt>
16  * <dt><b>License:</b><dd>Read the license.txt file of the jar or visit the
17  * <a HREF="http://www.sapia-oss.org/license.html">license page</a> at the Sapia OSS web site</dd></dt>
18  * </dl>
19  */

20 public class CursorImplTest extends TestCase{
21   
22   Cursor _cursor;
23   
24   public CursorImplTest(String JavaDoc name){
25     super(name);
26   }
27   
28   public void setUp(){
29     Object JavaDoc[] buffer = new Object JavaDoc[4];
30     List JavaDoc items = new ArrayList JavaDoc();
31     for(int i = 0; i < 12; i++){
32       items.add(""+i);
33     }
34     ListCursorFeed feed = new ListCursorFeed(items);
35     _cursor = new CursorImpl(feed, null, 3);
36   }
37   
38   public void testNextBatch(){
39     Batch next;
40     int count = 0;
41     int totalcount = 0;
42     while(_cursor.hasNextBatch()){
43       next = _cursor.nextBatch();
44       super.assertEquals(3, next.getCount());
45       super.assertEquals(totalcount, next.getAbsolutePos());
46       count++;
47       totalcount = totalcount + next.getCount();
48     }
49     super.assertEquals(4, count);
50   }
51   
52   public void testPreviousBatch(){
53     Batch batch;
54     int count = 0;
55     while(_cursor.hasNextBatch()){
56       batch = _cursor.nextBatch();
57       super.assertEquals(3, batch.getCount());
58       count++;
59     }
60     super.assertEquals(4, count);
61     
62     count = 0;
63     while(_cursor.hasPreviousBatch()){
64       batch = _cursor.previousBatch();
65       super.assertEquals(3, batch.getCount());
66       count++;
67     }
68     super.assertEquals(3, count);
69   }
70
71 }
72
Popular Tags