1 17 package org.apache.log.util.test; 18 19 import java.io.ByteArrayOutputStream ; 20 import java.io.PrintStream ; 21 import junit.framework.TestCase; 22 import org.apache.log.Hierarchy; 23 import org.apache.log.Logger; 24 import org.apache.log.Priority; 25 import org.apache.log.format.RawFormatter; 26 import org.apache.log.output.io.StreamTarget; 27 import org.apache.log.util.LoggerOutputStream; 28 29 34 public final class UtilTestCase 35 extends TestCase 36 { 37 private static final String EOL = System.getProperty( "line.separator", "\n" ); 38 private static final RawFormatter FORMATTER = new RawFormatter(); 39 40 private static final String MSG = "No soup for you!"; 41 private static final String RMSG = MSG; 42 43 public UtilTestCase( final String name ) 44 { 45 super( name ); 46 } 47 48 private String getResult( final ByteArrayOutputStream output ) 49 { 50 final String result = output.toString(); 51 output.reset(); 52 return result; 53 } 54 55 public void testStackIntrospector() 56 throws Exception 57 { 58 73 } 74 75 public void testLoggerOutputStream() 76 throws Exception 77 { 78 final ByteArrayOutputStream output = new ByteArrayOutputStream (); 79 final StreamTarget target = new StreamTarget( output, FORMATTER ); 80 81 final Hierarchy hierarchy = new Hierarchy(); 82 hierarchy.setDefaultLogTarget( target ); 83 84 final Logger logger = hierarchy.getLoggerFor( "myLogger" ); 85 final LoggerOutputStream outputStream = new LoggerOutputStream( logger, Priority.DEBUG ); 86 final PrintStream printer = new PrintStream ( outputStream, true ); 87 88 printer.println( MSG ); 89 assertEquals( "LoggerOutputStream", RMSG + EOL, getResult( output ) ); 90 91 printer.print( MSG ); 93 printer.flush(); 94 assertEquals( "LoggerOutputStream", RMSG, getResult( output ) ); 95 96 printer.close(); 97 } 98 } 99 | Popular Tags |