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.io.File;
23
24 import java.lang.reflect.Method;
25
26
27 /***
28 *
29 * FileAppender tests.
30 *
31 * @author Curt Arnold
32 */
33 public class FileAppenderTest extends TestCase {
34 /***
35 * Tests that any necessary directories are attempted to
36 * be created if they don't exist. See bug 9150.
37 *
38 */
39 public void testDirectoryCreation() {
40
41
42 if (!System.getProperty("java.version").startsWith("1.1.")) {
43 File newFile = new File("output/newdir/temp.log");
44 newFile.delete();
45
46 File newDir = new File("output/newdir");
47 newDir.delete();
48
49 org.apache.log4j.FileAppender wa = new org.apache.log4j.FileAppender();
50 wa.setFile("output/newdir/temp.log");
51 wa.setLayout(new PatternLayout("%m%n"));
52 wa.activateOptions();
53
54 assertTrue(new File("output/newdir/temp.log").exists());
55 }
56 }
57
58 /***
59 * Tests that the return type of getThreshold is Priority.
60 * @throws Exception
61 */
62 public void testGetThresholdReturnType() throws Exception {
63 Method method = FileAppender.class.getMethod("getThreshold", (Class[]) null);
64 assertTrue(method.getReturnType() == Priority.class);
65 }
66
67 /***
68 * Tests getThreshold and setThreshold.
69 */
70 public void testgetSetThreshold() {
71 FileAppender appender = new FileAppender();
72 Priority debug = Level.DEBUG;
73 Priority all = Level.ALL;
74 assertNull(appender.getThreshold());
75 appender.setThreshold(debug);
76 assertTrue(appender.getThreshold() == debug);
77 }
78
79 /***
80 * Tests isAsSevereAsThreshold.
81 */
82 public void testIsAsSevereAsThreshold() {
83 FileAppender appender = new FileAppender();
84 Priority debug = Level.DEBUG;
85 assertTrue(appender.isAsSevereAsThreshold(debug));
86 }
87 }