1 17 package org.apache.avalon.framework.logger.test; 18 19 import java.io.OutputStream ; 20 import java.io.OutputStreamWriter ; 21 22 import junit.framework.TestCase; 23 24 import org.apache.avalon.framework.logger.Logger; 25 import org.apache.avalon.framework.logger.LoggerAwareOutputStream; 26 27 33 public class LoggerAwareOutputStreamTestCase extends TestCase 34 { 35 41 public void testLoggerAwareOutputStream() throws Exception 42 { 43 final TestLogger logger = new TestLogger(); 44 final String testString = "a test string"; 45 46 final OutputStream os = 47 new LoggerAwareOutputStream( logger ) { 48 protected void logMessage( String message ) 49 { 50 m_logger.debug( message ); 51 } 52 }; 53 54 final OutputStreamWriter writer = new OutputStreamWriter (os); 55 writer.write(testString, 0, testString.length()); 56 writer.close(); 57 final String message = logger.getDebugMessage(); 58 59 assertEquals("Logged message doesn't equal source string", testString, message); 61 62 } 63 64 67 private class TestLogger implements Logger 68 { 69 72 public TestLogger() 73 { 74 } 75 76 81 public void debug( String message ) 82 { 83 this.message = message; 84 } 85 86 private String message; 87 88 92 public String getDebugMessage() 93 { 94 return message; 95 } 96 97 103 public void debug( String message, Throwable throwable ) 104 { 105 } 106 107 112 public boolean isDebugEnabled() 113 { 114 return true; 115 } 116 117 122 public void info( String message ) 123 { 124 } 125 126 132 public void info( String message, Throwable throwable ) 133 { 134 } 135 136 141 public boolean isInfoEnabled() 142 { 143 return false; 144 } 145 146 151 public void warn( String message ) 152 { 153 } 154 155 161 public void warn( String message, Throwable throwable ) 162 { 163 } 164 165 170 public boolean isWarnEnabled() 171 { 172 return false; 173 } 174 175 180 public void error( String message ) 181 { 182 } 183 184 190 public void error( String message, Throwable throwable ) 191 { 192 } 193 194 199 public boolean isErrorEnabled() 200 { 201 return false; 202 } 203 204 209 public void fatalError( String message ) 210 { 211 } 212 213 219 public void fatalError( String message, Throwable throwable ) 220 { 221 } 222 223 228 public boolean isFatalErrorEnabled() 229 { 230 return false; 231 } 232 233 239 public Logger getChildLogger( String name ) 240 { 241 return this; 242 } 243 } 244 } 245 | Popular Tags |