KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > oddjob > logging > LoggingOutputStreamTest


1 /*
2  * (c) Rob Gordon 2005
3  */

4 package org.oddjob.logging;
5
6 import java.io.IOException JavaDoc;
7 import java.io.OutputStream JavaDoc;
8
9 import junit.framework.TestCase;
10
11 /**
12  *
13  */

14 public class LoggingOutputStreamTest extends TestCase {
15
16     OutputStream JavaDoc test;
17     
18     String JavaDoc 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 JavaDoc {
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 JavaDoc {
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