KickJava   Java API By Example, From Geeks To Geeks.

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


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

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

14 public class LoggingPrintStreamTest extends TestCase {
15
16     PrintStream 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         ConsoleArchiveImpl cai = new ConsoleArchiveImpl();
31         test = new LoggingPrintStream(System.out, LogLevel.WARN, cai.consoleLog());
32         text = null;
33         level = null;
34         cai.consoleLog().addListener(new MyLL(), LogLevel.DEBUG, -1, 1000);
35     }
36     
37     public void testPrintlnString() {
38         test.println("Hello");
39         assertEquals("Hello" + System.getProperty("line.separator"), text);
40         assertEquals(LogLevel.WARN, level);
41     }
42     
43     public void testLn() throws IOException JavaDoc {
44         test.print("Hello");
45         assertNull(text);
46         test.println();
47         assertEquals("Hello" + System.getProperty("line.separator"), text);
48     }
49 }
50
Popular Tags