Project Report: fawkez

Packagesummary org.jcoderz.commons.logging

org.jcoderz.commons.logging.LogElementTest

LineHitsNoteSource
1  /*
2   * $Id: LogElementTest.java 1279 2009-02-11 20:13:00Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.commons.logging;
34  
35  import java.util.logging.Handler;
36  import java.util.logging.Level;
37  import java.util.logging.LogRecord;
38  import java.util.logging.Logger;
39  
40  import org.jcoderz.commons.BaseException;
41  import org.jcoderz.commons.BaseRuntimeException;
42  import org.jcoderz.commons.LogFormatterOutputTest;
43  
44  
45  /**
46   * This class is used for testing the LogElement wrapper of a LogRecord. It
47   * installs a LogFormatter, which allocates a LogElement for each LogRecord to
48   * publish and uses LogFormatterOutputTest for generating the log messages.
49   *
50   */
51 (1)(2)public class LogElementTest
52        extends LogFormatterOutputTest
53  {
5475    private static final String CLASSNAME = FormatTest.class.getName();
55100    private static final Logger logger = Logger.getLogger(CLASSNAME);
56  
57100    private static final Logger ROOT_LOGGER = Logger.getLogger("");
58  
59100    private Handler mHandler = null;
60  
61100    private static class LogElementHandler
62           extends Handler
63     {
64        /**
65         * Closes this Handler, this is a NOP.
66         *
67         * @see java.util.logging.Handler#close()
68         */
69        public void close ()
70              throws SecurityException
71        {
72           // nop
730       }
74  
75        /**
76         * Flushes this Handler, this is a NOP.
77         *
78         * @see java.util.logging.Handler#flush()
79         */
80        public void flush ()
81        {
82           // nop
830       }
84  
85        /**
86         * Just allocates a new LogElement from the log record.
87         *
88         * @see java.util.logging.Handler#publish(java.util.logging.LogRecord)
89         *
90 (3)       * TODO Check LogElement elements.
91         */
92        public void publish (LogRecord record)
93        {
94100          final LogElement element = new LogElement(record);
95100          LoggerUtil.checkLogItem(element, record);
96100       }
97     }
98  
99     /**
100      * Creates a new test case instance.
101      */
102 (4)   public LogElementTest ()
103     {
104100       super();
105100    }
106  
107 (5)   public void testSimpleLogRecord ()
108     {
109100       logger.info("testSimpleLogRecord: " + getClass().getName());
110100    }
111  
112     /**
113      * Installs an additional Handler, which publishes RocRecords using
114      * LogElements.
115      *
116      * @see junit.framework.TestCase#setUp()
117      */
118     protected void setUp ()
119     {
120100       mHandler = new LogElementHandler();
121100       ROOT_LOGGER.addHandler(mHandler);
122100       Logger.getLogger(BaseException.class.getName()).setLevel(Level.INFO);
123100(6)      Logger.getLogger(BaseRuntimeException.class.getName()).setLevel(Level.INFO);
124100    }
125  
126     /**
127      * Deinstalls the additional Handler.
128      *
129      * @see junit.framework.TestCase#setUp()
130      */
131     protected void tearDown ()
132     {
133100       if (mHandler != null)
134        {
135100          ROOT_LOGGER.removeHandler(mHandler);
136100          mHandler = null;
137        }
138100    }
139  }

Findings in this File

c (1) 51 : 0 Type Javadoc comment is missing an @author tag.
d (2) 51 : 8 Class contains more than one logger.
i (3) 90 : 0 Comment matches to-do format '(TODO|FIXME|CHECKME)'. (test code)
c (4) 102 : 11 Avoid unnecessary constructors - the compiler will generate these for you
c (5) 107 : 4 Missing a Javadoc comment.
c (6) 123 : 0 Line is longer than 80 characters.