1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.log4j;
19
20 import junit.framework.TestCase;
21
22 import java.lang.reflect.Method;
23
24
25 /***
26 * Tests of Category.
27 *
28 * @author Curt Arnold
29 * @since 1.2.14
30 */
31 public class CategoryTest extends TestCase {
32 /***
33 * Constructs new instance of test.
34 * @param name test name.
35 */
36 public CategoryTest(final String name) {
37 super(name);
38 }
39
40 /***
41 * Tests Category.forcedLog.
42 */
43 public void testForcedLog() {
44 MockCategory category = new MockCategory("org.example.foo");
45 category.setAdditivity(false);
46 category.addAppender(new VectorAppender());
47 category.info("Hello, World");
48 }
49
50 /***
51 * Tests that the return type of getChainedPriority is Priority.
52 * @throws Exception thrown if Category.getChainedPriority can not be found.
53 */
54 public void testGetChainedPriorityReturnType() throws Exception {
55 Method method = Category.class.getMethod("getChainedPriority", (Class[]) null);
56 assertTrue(method.getReturnType() == Priority.class);
57 }
58
59 /***
60 * Tests l7dlog(Priority, String, Throwable).
61 */
62 public void testL7dlog() {
63 Logger logger = Logger.getLogger("org.example.foo");
64 logger.setLevel(Level.ERROR);
65 Priority debug = Level.DEBUG;
66 logger.l7dlog(debug, "Hello, World", null);
67 }
68
69 /***
70 * Tests l7dlog(Priority, String, Object[], Throwable).
71 */
72 public void testL7dlog4Param() {
73 Logger logger = Logger.getLogger("org.example.foo");
74 logger.setLevel(Level.ERROR);
75 Priority debug = Level.DEBUG;
76 logger.l7dlog(debug, "Hello, World", new Object[0], null);
77 }
78
79 /***
80 * Tests setPriority(Priority).
81 * @deprecated
82 */
83 public void testSetPriority() {
84 Logger logger = Logger.getLogger("org.example.foo");
85 Priority debug = Level.DEBUG;
86 logger.setPriority(debug);
87 }
88
89 /***
90 * Derived category to check method signature of forcedLog.
91 */
92 private static class MockCategory extends Logger {
93 /***
94 * Create new instance of MockCategory.
95 * @param name category name
96 */
97 public MockCategory(final String name) {
98 super(name);
99 repository = new Hierarchy(this);
100 }
101
102 /***
103 * Request an info level message.
104 * @param msg message
105 */
106 public void info(final String msg) {
107 Priority info = Level.INFO;
108 forcedLog(MockCategory.class.toString(), info, msg, null);
109 }
110 }
111 }