01: /*
02: * Copyright (C) The DNA Group. All rights reserved.
03: *
04: * This software is published under the terms of the DNA
05: * Software License version 1.1, a copy of which has been included
06: * with this distribution in the LICENSE.txt file.
07: */
08: package org.codehaus.dna;
09:
10: import junit.framework.TestCase;
11:
12: /**
13: *
14: * @author Peter Donald
15: * @version $Revision: 1.2 $ $Date: 2004/05/01 09:51:48 $
16: */
17: public class LogEnabledTestCase extends TestCase {
18: public void testGetLogger() throws Exception {
19: final MockLogEnabled logEnabled = new MockLogEnabled();
20: final MockLogger logger = new MockLogger("base");
21: logEnabled.enableLogging(logger);
22: assertEquals("logger", logger, logEnabled.getLogger());
23: }
24:
25: public void testSetupLoggerOnLogEnabled() throws Exception {
26: final MockLogEnabled logEnabled = new MockLogEnabled();
27: final MockLogEnabled childLogEnabled = new MockLogEnabled();
28: final MockLogger logger = new MockLogger("base");
29: logEnabled.enableLogging(logger);
30: logEnabled.setupLogger(childLogEnabled);
31: assertEquals("logEnabled.logger", logger, logEnabled
32: .getLogger());
33: assertEquals("childLogEnabled.logger", logger, childLogEnabled
34: .getLogger());
35: }
36:
37: public void testSetupLoggerOnNonLogEnabled() throws Exception {
38: final MockLogEnabled logEnabled = new MockLogEnabled();
39: final MockLogger logger = new MockLogger("base");
40: logEnabled.enableLogging(logger);
41: logEnabled.setupLogger(new Object());
42: }
43:
44: public void testSetupLoggerWithNameOnLogEnabled() throws Exception {
45: final MockLogEnabled logEnabled = new MockLogEnabled();
46: final MockLogEnabled childLogEnabled = new MockLogEnabled();
47: final MockLogger logger = new MockLogger("base");
48: logEnabled.enableLogging(logger);
49: logEnabled.setupLogger(childLogEnabled, "child");
50: assertEquals("logEnabled.logger", logger, logEnabled
51: .getLogger());
52: assertEquals("childLogEnabled.logger.name", "base.child",
53: ((MockLogger) childLogEnabled.getLogger()).getName());
54: }
55:
56: public void testSetupLoggerWithNullName() throws Exception {
57: final MockLogEnabled logEnabled = new MockLogEnabled();
58: final MockLogEnabled childLogEnabled = new MockLogEnabled();
59: final MockLogger logger = new MockLogger("base");
60: logEnabled.enableLogging(logger);
61: try {
62: logEnabled.setupLogger(childLogEnabled, null);
63: } catch (final NullPointerException npe) {
64: assertEquals("npe.message", "name", npe.getMessage());
65: return;
66: }
67: fail("Expected to fail setting up child logger with null name");
68: }
69: }
|