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