KickJava   Java API By Example, From Geeks To Geeks.

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


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.TestHandler;
8 import org.sapia.ubik.net.nio.TestWriteChannel;
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 WriteHelperTest extends TestCase{
22   
23   public WriteHelperTest(String JavaDoc name){
24     super(name);
25   }
26   
27   public void testWrite() 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     TestWriteChannel channel = new TestWriteChannel();
40     TestHandler handler = new TestHandler(data);
41     TestChannelManager manager = new TestChannelManager();
42     ByteBuffer JavaDoc buffer = ByteBuffer.allocate(10);
43     TestCycle cycle = new TestCycle(channel, handler, manager);
44     cycle.setByteBuffer(buffer);
45     WriteHelper helper = new WriteHelper();
46     helper.write(cycle);
47     byte[] written = channel.getBytes();
48     super.assertEquals(data.length, written.length);
49     String JavaDoc writtenStr = new String JavaDoc(written);
50     super.assertEquals(dataStr, writtenStr);
51   }
52
53 }
54
Popular Tags