1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.logging.noop;
18
19 import java.io.ByteArrayInputStream;
20 import java.io.ByteArrayOutputStream;
21 import java.io.ObjectInputStream;
22 import java.io.ObjectOutputStream;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.commons.logging.impl.NoOpLog;
27 import org.apache.commons.logging.AbstractLogTest;
28
29 /***
30 * Tests for NoOpLog logging adapter.
31 * <p>
32 * This simply applies the tests defined in AbstractLogTest to this class.
33 */
34 public class NoOpLogTestCase extends AbstractLogTest
35 {
36 /***
37 * Set up instance variables required by this test case.
38 */
39 public void setUp() throws Exception {
40 LogFactory.releaseAll();
41
42 System.setProperty(
43 "org.apache.commons.logging.Log",
44 "org.apache.commons.logging.impl.NoOpLog");
45 }
46
47 /***
48 * Tear down instance variables required by this test case.
49 */
50 public void tearDown() {
51 LogFactory.releaseAll();
52 }
53
54 /***
55 * Override the abstract method from the parent class so that the
56 * inherited tests can access the right Log object type.
57 */
58 public Log getLogObject()
59 {
60 return (Log) new NoOpLog(this.getClass().getName());
61 }
62
63
64 public void testSerializable() throws Exception {
65 Log log = LogFactory.getLog(this.getClass().getName());
66 checkLog(log);
67
68
69 ByteArrayOutputStream baos = new ByteArrayOutputStream();
70 ObjectOutputStream oos = new ObjectOutputStream(baos);
71 oos.writeObject(log);
72 oos.close();
73 ByteArrayInputStream bais =
74 new ByteArrayInputStream(baos.toByteArray());
75 ObjectInputStream ois = new ObjectInputStream(bais);
76 log = (Log) ois.readObject();
77 ois.close();
78
79 checkLog(log);
80 }
81
82
83
84
85 private void checkLog(Log log) {
86
87 assertNotNull("Log exists", log);
88 assertEquals("Log class",
89 "org.apache.commons.logging.impl.NoOpLog",
90 log.getClass().getName());
91
92
93
94 assertFalse(log.isTraceEnabled());
95 assertFalse(log.isDebugEnabled());
96 assertFalse(log.isInfoEnabled());
97 assertFalse(log.isWarnEnabled());
98 assertFalse(log.isErrorEnabled());
99 assertFalse(log.isFatalEnabled());
100 }
101 }