1 package org.sapia.ubik.net.nio.util; 2 3 import java.nio.ByteBuffer ; 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 21 public class ReadHelperTest extends TestCase{ 22 23 public ReadHelperTest(String name){ 24 super(name); 25 } 26 27 public void testRead() throws Exception { 28 StringBuffer buf = new StringBuffer (); 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 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 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 readStr = new String (read); 51 super.assertEquals(dataStr, readStr); 52 53 } 54 55 } 56 | Popular Tags |