1 16 17 package org.apache.commons.logging; 18 19 import junit.framework.TestCase; 20 21 28 public class BasicOperationsTest extends TestCase 29 { 30 public BasicOperationsTest(String testName) 31 { 32 super(testName); 33 } 34 35 public void testIsEnabledClassLog() 36 { 37 Log log = LogFactory.getLog(BasicOperationsTest.class); 38 executeIsEnabledTest(log); 39 } 40 41 public void testIsEnabledNamedLog() 42 { 43 Log log = LogFactory.getLog(BasicOperationsTest.class.getName()); 44 executeIsEnabledTest(log); 45 } 46 47 public void executeIsEnabledTest(Log log) 48 { 49 try 50 { 51 log.isTraceEnabled(); 52 log.isDebugEnabled(); 53 log.isInfoEnabled(); 54 log.isWarnEnabled(); 55 log.isErrorEnabled(); 56 log.isFatalEnabled(); 57 } 58 catch (Throwable t) 59 { 60 t.printStackTrace(); 61 fail("Exception thrown: " + t); 62 } 63 } 64 65 66 public void testMessageWithoutExceptionClassLog() 67 { 68 Log log = LogFactory.getLog(BasicOperationsTest.class); 69 executeMessageWithoutExceptionTest(log); 70 } 71 72 public void testMessageWithoutExceptionNamedLog() 73 { 74 Log log = LogFactory.getLog(BasicOperationsTest.class.getName()); 75 executeMessageWithoutExceptionTest(log); 76 } 77 78 public void executeMessageWithoutExceptionTest(Log log) 79 { 80 try 81 { 82 log.trace("Hello, Mum"); 83 log.debug("Hello, Mum"); 84 log.info("Hello, Mum"); 85 log.warn("Hello, Mum"); 86 log.error("Hello, Mum"); 87 log.fatal("Hello, Mum"); 88 } 89 catch (Throwable t) 90 { 91 t.printStackTrace(); 92 fail("Exception thrown: " + t); 93 } 94 } 95 96 public void testMessageWithExceptionClassLog() 97 { 98 Log log = LogFactory.getLog(BasicOperationsTest.class); 99 executeMessageWithExceptionTest(log); 100 } 101 102 public void testMessageWithExceptionNamedLog() 103 { 104 Log log = LogFactory.getLog(BasicOperationsTest.class.getName()); 105 executeMessageWithExceptionTest(log); 106 } 107 108 public void executeMessageWithExceptionTest(Log log) 109 { 110 try 111 { 112 log.trace("Hello, Mum", new ArithmeticException ()); 113 log.debug("Hello, Mum", new ArithmeticException ()); 114 log.info("Hello, Mum", new ArithmeticException ()); 115 log.warn("Hello, Mum", new ArithmeticException ()); 116 log.error("Hello, Mum", new ArithmeticException ()); 117 log.fatal("Hello, Mum", new ArithmeticException ()); 118 } 119 catch (Throwable t) 120 { 121 t.printStackTrace(); 122 fail("Exception thrown: " + t); 123 } 124 } 125 } 126 | Popular Tags |