1 36 package org.columba.ristretto.log; 37 38 import java.io.ByteArrayInputStream ; 39 import java.io.ByteArrayOutputStream ; 40 import java.io.IOException ; 41 import java.io.InputStream ; 42 import java.util.Arrays ; 43 44 import junit.framework.TestCase; 45 46 public class LogInputStreamTest extends TestCase { 47 48 private byte[] buffer; 49 50 public void test1() throws IOException { 51 byte[] result = "S: This is a simple line".getBytes(); 52 byte[] test = "This is a simple line".getBytes(); 53 ByteArrayOutputStream out = new ByteArrayOutputStream (); 54 InputStream in = new LogInputStream( new ByteArrayInputStream ( test ), out); 55 56 in.read(buffer); 57 58 System.out.println( new String ( out.toByteArray())); 59 60 assertTrue( Arrays.equals( result, out.toByteArray())); 61 } 62 63 public void test2() throws IOException { 64 byte[] result = "S: This is a multiple\nS: line".getBytes(); 65 byte[] test = "This is a multiple\nline".getBytes(); 66 ByteArrayOutputStream out = new ByteArrayOutputStream (); 67 InputStream in = new LogInputStream( new ByteArrayInputStream ( test ), out); 68 69 in.read(buffer); 70 71 assertTrue( Arrays.equals( result, out.toByteArray())); 72 } 73 74 public void test3() throws IOException { 75 byte[] result = "S: This is a multiple\nS: line\n".getBytes(); 76 byte[] test = "This is a multiple\nline\n".getBytes(); 77 ByteArrayOutputStream out = new ByteArrayOutputStream (); 78 InputStream in = new LogInputStream( new ByteArrayInputStream ( test ), out); 79 80 in.read(buffer); 81 82 assertTrue( Arrays.equals( result, out.toByteArray())); 83 } 84 87 protected void setUp() throws Exception { 88 super.setUp(); 89 90 buffer = new byte[1000]; 91 } 92 93 } 94 | Popular Tags |