1 17 package org.apache.geronimo.system.logging.log4j; 18 19 import junit.framework.TestCase; 20 import org.apache.log4j.Priority; 21 import org.apache.log4j.Level; 22 import org.apache.commons.logging.Log; 23 24 27 public class AbstractLog4jLogTest extends TestCase { 28 protected final static Object MESSAGE = new Object (); 29 protected final static Throwable THROWABLE = new Throwable (); 30 protected MockLogger mockLogger; 31 protected Log log; 32 protected String logFQCN; 33 34 protected void doTestDelegatedToLog(Priority priority, Object object, Throwable throwable) { 35 assertTrue("Method delegates to Logger.log", 36 mockLogger.logCalled 37 & mockLogger.calledWithString == logFQCN 38 & mockLogger.calledWithPriority == priority 39 & mockLogger.calledWithObject == object 40 & mockLogger.calledWithThrowable == throwable); 41 } 42 43 48 public void testIsWarnEnabled() { 49 log.isWarnEnabled(); 50 assertTrue("Method delegates to Logger.isEnabledFor", 51 mockLogger.isEnabledForCalled 52 & mockLogger.calledWithPriority==Level.WARN); 53 } 54 55 61 public void testWarnNull() { 62 log.warn(MESSAGE); 63 doTestDelegatedToLog(Level.WARN, MESSAGE, null); 64 } 65 66 72 public void testWarnThrowable() { 73 log.warn(MESSAGE, THROWABLE); 74 doTestDelegatedToLog(Level.WARN, MESSAGE, THROWABLE); 75 } 76 77 82 public void testIsErrorEnabled() { 83 log.isErrorEnabled(); 84 assertTrue("Method delegates to Logger.isEnabledFor", 85 mockLogger.isEnabledForCalled 86 & mockLogger.calledWithPriority==Level.ERROR); 87 } 88 89 95 public void testErrorNull() { 96 log.error(MESSAGE); 97 doTestDelegatedToLog(Level.ERROR, MESSAGE, null); 98 } 99 100 106 public void testErrorThrowable() { 107 log.error(MESSAGE, THROWABLE); 108 doTestDelegatedToLog(Level.ERROR, MESSAGE, THROWABLE); 109 } 110 111 116 public void testIsFatalEnabled() { 117 log.isFatalEnabled(); 118 assertTrue("Method delegates to Logger.isEnabledFor", 119 mockLogger.isEnabledForCalled 120 & mockLogger.calledWithPriority==Level.FATAL); 121 } 122 123 129 public void testFatalNull() { 130 log.fatal(MESSAGE); 131 doTestDelegatedToLog(Level.FATAL, MESSAGE, null); 132 } 133 134 140 public void testFatalThrowable() { 141 log.fatal(MESSAGE, THROWABLE); 142 doTestDelegatedToLog(Level.FATAL, MESSAGE, THROWABLE); 143 } 144 } 145 | Popular Tags |