1 32 package net.sf.retrotranslator.runtime.java.nio; 33 34 import java.nio.CharBuffer ; 35 import junit.framework.TestCase; 36 37 40 public class _CharBufferTestCase extends TestCase { 41 42 public void testReadEmpty() throws Exception { 43 CharBuffer source = CharBuffer.wrap(""); 44 assertEquals(-1, source.read(CharBuffer.allocate(10))); 45 } 46 47 public void testRead() throws Exception { 48 CharBuffer source = CharBuffer.wrap("abc"); 49 CharBuffer target = CharBuffer.allocate(10); 50 assertEquals(3, source.read(target)); 51 target.limit(target.position()); 52 target.position(0); 53 assertEquals("abc", target.toString()); 54 } 55 56 public void testReadLimited() throws Exception { 57 CharBuffer source = CharBuffer.wrap("abcdefgh"); 58 CharBuffer target = CharBuffer.allocate(4); 59 assertEquals(4, source.read(target)); 60 target.limit(target.position()); 61 target.position(0); 62 assertEquals("abcd", target.toString()); 63 } 64 65 public void testAppend() throws Exception { 66 CharBuffer buffer = CharBuffer.allocate(10); 67 buffer.append("abc").append("xyz", 1, 2).append('0'); 68 buffer.limit(buffer.position()); 69 buffer.position(0); 70 assertEquals("abcy0", buffer.toString()); 71 } 72 } | Popular Tags |