1 4 package org.oddjob.logging; 5 6 import java.io.IOException ; 7 import java.io.OutputStream ; 8 9 import junit.framework.TestCase; 10 11 14 public class LoggingOutputStreamTest extends TestCase { 15 16 OutputStream test; 17 18 String text; 19 LogLevel level; 20 21 class MyLL implements LogListener { 22 23 public void logEvent(LogEvent logEvent) { 24 level = logEvent.getLevel(); 25 text = logEvent.getMessage(); 26 } 27 } 28 29 protected void setUp() { 30 LogArchive logArchive = new LogArchive("org.oddjob.test", 20); 31 test = new LoggingOutputStream(System.out, LogLevel.WARN, 32 logArchive); 33 text = null; 34 level = null; 35 logArchive.addListener(new MyLL(), LogLevel.DEBUG, -1, 1000); 36 } 37 38 public void testByteArray() throws IOException { 39 test.write("Hello\nWorld".getBytes()); 40 assertEquals("Hello\n", text); 41 test.close(); 42 assertEquals("World", text); 43 } 44 45 public void testByteArray2() throws IOException { 46 test.write("01234Hello\nWorld".getBytes(), 5, 11); 47 assertEquals("Hello\n", text); 48 test.close(); 49 assertEquals("World", text); 50 } 51 } 52 | Popular Tags |