View Javadoc

    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.log4j;
    19
    20  import junit.framework.TestCase;
    21
    22  import java.util.Locale;
    23
    24
    25  /***
    26   * Tests of Priority.
    27   *
    28   * @author Curt Arnold
    29   * @since 1.2.14
    30   */
    31  public class PriorityTest extends TestCase {
    32    /***
    33     * Constructs new instance of test.
    34     * @param name test name.
    35     */
    36    public PriorityTest(final String name) {
    37      super(name);
    38    }
    39
    40    /***
    41     * Tests Priority.OFF_INT.
    42     */
    43    public void testOffInt() {
    44      assertEquals(Integer.MAX_VALUE, Priority.OFF_INT);
    45    }
    46
    47    /***
    48     * Tests Priority.FATAL_INT.
    49     */
    50    public void testFatalInt() {
    51      assertEquals(50000, Priority.FATAL_INT);
    52    }
    53
    54    /***
    55     * Tests Priority.ERROR_INT.
    56     */
    57    public void testErrorInt() {
    58      assertEquals(40000, Priority.ERROR_INT);
    59    }
    60
    61    /***
    62     * Tests Priority.WARN_INT.
    63     */
    64    public void testWarnInt() {
    65      assertEquals(30000, Priority.WARN_INT);
    66    }
    67
    68    /***
    69     * Tests Priority.INFO_INT.
    70     */
    71    public void testInfoInt() {
    72      assertEquals(20000, Priority.INFO_INT);
    73    }
    74
    75    /***
    76     * Tests Priority.DEBUG_INT.
    77     */
    78    public void testDebugInt() {
    79      assertEquals(10000, Priority.DEBUG_INT);
    80    }
    81
    82    /***
    83     * Tests Priority.ALL_INT.
    84     */
    85    public void testAllInt() {
    86      assertEquals(Integer.MIN_VALUE, Priority.ALL_INT);
    87    }
    88
    89    /***
    90     * Tests Priority.FATAL.
    91     * @deprecated
    92     */
    93    public void testFatal() {
    94      assertTrue(Priority.FATAL instanceof Level);
    95    }
    96
    97    /***
    98     * Tests Priority.ERROR.
    99     * @deprecated
    100    */
    101   public void testERROR() {
    102     assertTrue(Priority.ERROR instanceof Level);
    103   }
    104
    105   /***
    106    * Tests Priority.WARN.
    107    * @deprecated
    108    */
    109   public void testWARN() {
    110     assertTrue(Priority.WARN instanceof Level);
    111   }
    112
    113   /***
    114    * Tests Priority.INFO.
    115    * @deprecated
    116    */
    117   public void testINFO() {
    118     assertTrue(Priority.INFO instanceof Level);
    119   }
    120
    121   /***
    122    * Tests Priority.DEBUG.
    123    * @deprecated
    124    */
    125   public void testDEBUG() {
    126     assertTrue(Priority.DEBUG instanceof Level);
    127   }
    128
    129   /***
    130    * Tests Priority.equals(null).
    131    * @deprecated
    132    */
    133   public void testEqualsNull() {
    134     assertFalse(Priority.DEBUG.equals(null));
    135   }
    136
    137   /***
    138    * Tests Priority.equals(Level.DEBUG).
    139    * @deprecated
    140    */
    141   public void testEqualsLevel() {
    142     //
    143     //   this behavior violates the equals contract.
    144     //
    145     assertTrue(Priority.DEBUG.equals(Level.DEBUG));
    146   }
    147
    148   /***
    149    * Tests getAllPossiblePriorities().
    150    * @deprecated
    151    */
    152   public void testGetAllPossiblePriorities() {
    153     Priority[] priorities = Priority.getAllPossiblePriorities();
    154     assertEquals(5, priorities.length);
    155   }
    156
    157   /***
    158    * Tests toPriority(String).
    159    * @deprecated
    160    */
    161   public void testToPriorityString() {
    162     assertTrue(Priority.toPriority("DEBUG") == Level.DEBUG);
    163   }
    164
    165   /***
    166    * Tests toPriority(int).
    167    * @deprecated
    168    */
    169   public void testToPriorityInt() {
    170     assertTrue(Priority.toPriority(Priority.DEBUG_INT) == Level.DEBUG);
    171   }
    172
    173   /***
    174    * Tests toPriority(String, Priority).
    175    * @deprecated
    176    */
    177   public void testToPriorityStringPriority() {
    178     assertTrue(Priority.toPriority("foo", Priority.DEBUG) == Priority.DEBUG);
    179   }
    180
    181   /***
    182    * Tests toPriority(int, Priority).
    183    * @deprecated
    184    */
    185   public void testToPriorityIntPriority() {
    186     assertTrue(Priority.toPriority(17, Priority.DEBUG) == Priority.DEBUG);
    187   }
    188
    189     /***
    190      * Test that dotless lower I + "nfo" is recognized as INFO.
    191      * @deprecated
    192      */
    193   public void testDotlessLowerI() {
    194       Priority level = Priority.toPriority("\u0131nfo");
    195       assertEquals("INFO", level.toString());
    196   }
    197
    198     /***
    199      * Test that dotted lower I + "nfo" is recognized as INFO
    200      * even in Turkish locale.
    201      * @deprecated
    202      */
    203   public void testDottedLowerI() {
    204       Locale defaultLocale = Locale.getDefault();
    205       Locale turkey = new Locale("tr", "TR");
    206       Locale.setDefault(turkey);
    207       Priority level = Priority.toPriority("info");
    208       Locale.setDefault(defaultLocale);
    209       assertEquals("INFO", level.toString());
    210   }
    211
    212 }