1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.commons.logging.noop;
19
20 import java.io.ByteArrayInputStream;
21 import java.io.ByteArrayOutputStream;
22 import java.io.ObjectInputStream;
23 import java.io.ObjectOutputStream;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.commons.logging.impl.NoOpLog;
28 import org.apache.commons.logging.AbstractLogTest;
29
30
31
32
33
34
35 public class NoOpLogTestCase extends AbstractLogTest
36 {
37
38
39
40 public void setUp() throws Exception {
41 LogFactory.releaseAll();
42
43 System.setProperty(
44 "org.apache.commons.logging.Log",
45 "org.apache.commons.logging.impl.NoOpLog");
46 }
47
48
49
50
51 public void tearDown() {
52 LogFactory.releaseAll();
53 System.getProperties().remove("org.apache.commons.logging.Log");
54 }
55
56
57
58
59
60 public Log getLogObject()
61 {
62 return (Log) new NoOpLog(this.getClass().getName());
63 }
64
65
66 public void testSerializable() throws Exception {
67 Log log = LogFactory.getLog(this.getClass().getName());
68 checkLog(log);
69
70
71 ByteArrayOutputStream baos = new ByteArrayOutputStream();
72 ObjectOutputStream oos = new ObjectOutputStream(baos);
73 oos.writeObject(log);
74 oos.close();
75 ByteArrayInputStream bais =
76 new ByteArrayInputStream(baos.toByteArray());
77 ObjectInputStream ois = new ObjectInputStream(bais);
78 log = (Log) ois.readObject();
79 ois.close();
80
81 checkLog(log);
82 }
83
84
85
86
87 private void checkLog(Log log) {
88
89 assertNotNull("Log exists", log);
90 assertEquals("Log class",
91 "org.apache.commons.logging.impl.NoOpLog",
92 log.getClass().getName());
93
94
95
96 assertFalse(log.isTraceEnabled());
97 assertFalse(log.isDebugEnabled());
98 assertFalse(log.isInfoEnabled());
99 assertFalse(log.isWarnEnabled());
100 assertFalse(log.isErrorEnabled());
101 assertFalse(log.isFatalEnabled());
102 }
103 }