1 16 17 package org.apache.commons.logging.noop; 18 19 import java.io.ByteArrayInputStream ; 20 import java.io.ByteArrayOutputStream ; 21 import java.io.ObjectInputStream ; 22 import java.io.ObjectOutputStream ; 23 24 import org.apache.commons.logging.Log; 25 import org.apache.commons.logging.LogFactory; 26 import org.apache.commons.logging.impl.NoOpLog; 27 import org.apache.commons.logging.AbstractLogTest; 28 29 34 public class NoOpLogTestCase extends AbstractLogTest 35 { 36 39 public void setUp() throws Exception { 40 LogFactory.releaseAll(); 41 42 System.setProperty( 43 "org.apache.commons.logging.Log", 44 "org.apache.commons.logging.impl.NoOpLog"); 45 } 46 47 50 public void tearDown() { 51 LogFactory.releaseAll(); 52 } 53 54 58 public Log getLogObject() 59 { 60 return (Log) new NoOpLog(this.getClass().getName()); 61 } 62 63 public void testSerializable() throws Exception { 65 Log log = LogFactory.getLog(this.getClass().getName()); 66 checkLog(log); 67 68 ByteArrayOutputStream baos = new ByteArrayOutputStream (); 70 ObjectOutputStream oos = new ObjectOutputStream (baos); 71 oos.writeObject(log); 72 oos.close(); 73 ByteArrayInputStream bais = 74 new ByteArrayInputStream (baos.toByteArray()); 75 ObjectInputStream ois = new ObjectInputStream (bais); 76 log = (Log) ois.readObject(); 77 ois.close(); 78 79 checkLog(log); 80 } 81 82 83 85 private void checkLog(Log log) { 86 87 assertNotNull("Log exists", log); 88 assertEquals("Log class", 89 "org.apache.commons.logging.impl.NoOpLog", 90 log.getClass().getName()); 91 92 assertFalse(log.isTraceEnabled()); 95 assertFalse(log.isDebugEnabled()); 96 assertFalse(log.isInfoEnabled()); 97 assertFalse(log.isWarnEnabled()); 98 assertFalse(log.isErrorEnabled()); 99 assertFalse(log.isFatalEnabled()); 100 } 101 } 102 | Popular Tags |