KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > sapia > ubik > net > nio > util > ReadHelperTest


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

21 public class ReadHelperTest extends TestCase{
22   
23   public ReadHelperTest(String JavaDoc name){
24     super(name);
25   }
26   
27   public void testRead() throws Exception JavaDoc{
28     StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
29     int from = (int)'a';
30     int to = ((int)'z')+1;
31     
32     for(int i = 0; i < 5; i++){
33       for(int j = from; j < to; j++){
34         buf.append((char)j);
35       }
36     }
37     String JavaDoc dataStr = buf.toString();
38     byte[] data = dataStr.getBytes();
39     TestReadChannel channel =
40       new TestReadChannel(data, 10);
41     TestHandler handler = new TestHandler(data.length);
42     TestChannelManager manager = new TestChannelManager();
43     ByteBuffer JavaDoc buffer = ByteBuffer.allocate(10);
44     TestCycle cycle = new TestCycle(channel, handler, manager);
45     cycle.setByteBuffer(buffer);
46     ReadHelper helper = new ReadHelper();
47     helper.read(cycle);
48     byte[] read = handler.getBytes();
49     super.assertEquals(data.length, read.length);
50     String JavaDoc readStr = new String JavaDoc(read);
51     super.assertEquals(dataStr, readStr);
52     
53   }
54
55 }
56
Popular Tags