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
27
28
29
30
31 public class CategoryTest extends TestCase {
32
33
34
35
36 public CategoryTest(final String name) {
37 super(name);
38 }
39
40
41
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
52
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
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
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
81
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
91
92 private static class MockCategory extends Logger {
93
94
95
96
97 public MockCategory(final String name) {
98 super(name);
99 repository = new Hierarchy(this);
100 }
101
102
103
104
105
106 public void info(final String msg) {
107 Priority info = Level.INFO;
108 forcedLog(MockCategory.class.toString(), info, msg, null);
109 }
110 }
111 }