BasicOperationsTestCase xref

    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    *
    9    *      http://www.apache.org/licenses/LICENSE-2.0
    10   *
    11   * Unless required by applicable law or agreed to in writing, software
    12   * distributed under the License is distributed on an "AS IS" BASIS,
    13   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    14   * See the License for the specific language governing permissions and
    15   * limitations under the License.
    16   */
    17
    18  package org.apache.commons.logging;
    19
    20  import junit.framework.TestCase;
    21
    22  /**
    23   * Tests the basic logging operations to ensure that they all function
    24   * without exception failure. In other words, that they do no fail by
    25   * throwing exceptions.
    26   * This is the minimum requirement for any well behaved logger
    27   * and so this test should be run for each kind.
    28   */
    29  public class BasicOperationsTestCase extends TestCase
    30  {
    31      public void testIsEnabledClassLog()
    32      {
    33          Log log = LogFactory.getLog(BasicOperationsTestCase.class);
    34          executeIsEnabledTest(log);
    35      }
    36
    37      public void testIsEnabledNamedLog()
    38      {
    39          Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
    40          executeIsEnabledTest(log);
    41      }
    42
    43      public void executeIsEnabledTest(Log log)
    44      {
    45          try
    46          {
    47              log.isTraceEnabled();
    48              log.isDebugEnabled();
    49              log.isInfoEnabled();
    50              log.isWarnEnabled();
    51              log.isErrorEnabled();
    52              log.isFatalEnabled();
    53          }
    54          catch (Throwable t)
    55          {
    56              t.printStackTrace();
    57              fail("Exception thrown: " + t);
    58          }
    59      }
    60
    61
    62      public void testMessageWithoutExceptionClassLog()
    63      {
    64          Log log = LogFactory.getLog(BasicOperationsTestCase.class);
    65          executeMessageWithoutExceptionTest(log);
    66      }
    67
    68      public void testMessageWithoutExceptionNamedLog()
    69      {
    70          Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
    71          executeMessageWithoutExceptionTest(log);
    72      }
    73
    74      public void executeMessageWithoutExceptionTest(Log log)
    75      {
    76          try
    77          {
    78              log.trace("Hello, Mum");
    79              log.debug("Hello, Mum");
    80              log.info("Hello, Mum");
    81              log.warn("Hello, Mum");
    82              log.error("Hello, Mum");
    83              log.fatal("Hello, Mum");
    84          }
    85          catch (Throwable t)
    86          {
    87              t.printStackTrace();
    88              fail("Exception thrown: " + t);
    89          }
    90      }
    91
    92      public void testMessageWithExceptionClassLog()
    93      {
    94          Log log = LogFactory.getLog(BasicOperationsTestCase.class);
    95          executeMessageWithExceptionTest(log);
    96      }
    97
    98      public void testMessageWithExceptionNamedLog()
    99      {
    100         Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
    101         executeMessageWithExceptionTest(log);
    102     }
    103
    104     public void executeMessageWithExceptionTest(Log log)
    105     {
    106         try
    107         {
    108             log.trace("Hello, Mum", new ArithmeticException());
    109             log.debug("Hello, Mum", new ArithmeticException());
    110             log.info("Hello, Mum", new ArithmeticException());
    111             log.warn("Hello, Mum", new ArithmeticException());
    112             log.error("Hello, Mum", new ArithmeticException());
    113             log.fatal("Hello, Mum", new ArithmeticException());
    114         }
    115         catch (Throwable t)
    116         {
    117             t.printStackTrace();
    118             fail("Exception thrown: " + t);
    119         }
    120     }
    121 }