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