1 17 package org.apache.geronimo.system.logging.log4j; 18 19 import junit.framework.TestCase; 20 import org.apache.log4j.Level; 21 22 26 public final class XLevelTest extends TestCase { 27 private static final int TRACE_SYSLOG_EQ = 7; 28 private static final String TRACE_STRING = "TRACE"; 29 private static final int TRACE_INT = Level.DEBUG_INT - 1; 30 private static final int MOCK_INT = TRACE_INT - 99; 31 32 private final static class MockLevel extends Level { 33 MockLevel() { 34 super(MOCK_INT, "MOCK", 99); 35 } 36 } 37 38 private final static Level MOCK = new MockLevel(); 39 40 46 public void testConstants() { 47 assertEquals("XLevel.TRACE_INT is defined as Level.DEBUG_INT-1", XLevel.TRACE_INT, TRACE_INT); 48 final Object o = XLevel.TRACE; 49 assertTrue("XLevel.TRACE is an instance of XLevel", o instanceof XLevel); 50 final XLevel traceLevel = (XLevel) o; 51 assertEquals("XLevel.TRACE syslog equivalent is indeed " + TRACE_SYSLOG_EQ, traceLevel.getSyslogEquivalent(), TRACE_SYSLOG_EQ); 52 assertEquals("XLevel.TRACE name is TRACE", traceLevel.toString(), TRACE_STRING); 53 assertEquals("XLevel.TRACE int level is " + TRACE_INT, traceLevel.toInt(), TRACE_INT); 54 } 55 56 64 public void testToLevelWithDefault() { 65 assertSame("Default value is indeed returned if null name is passed", XLevel.toLevel(null, MOCK), MOCK); 66 assertSame("XLevel.TRACE is returned if the name is equal to \"TRACE\" irrespecctive of case", XLevel.toLevel("trAce"), XLevel.TRACE); 67 Level levelResults = Level.toLevel("MOCK", MOCK); 68 Level xLevelResults = XLevel.toLevel("MOCK", MOCK); 69 assertSame("In all other cases conversion is deferred to Level", xLevelResults, levelResults); 70 assertSame("If conversion fails the default value is returned", xLevelResults, MOCK); 71 } 72 73 79 public void testToLevel() { 80 assertSame("XLevel.TRACE is returned if null name is passed", XLevel.toLevel(null), XLevel.TRACE); 81 assertSame("XLevel.TRACE is returned if the name is equal to \"TRACE\" irrespective of case", XLevel.toLevel("trAce"), XLevel.TRACE); 82 Level levelResults = Level.toLevel("MOCK", XLevel.TRACE); 83 Level xLevelResults = XLevel.toLevel("MOCK"); 84 assertSame("In all other cases conversion is deferred to Level", xLevelResults, levelResults); 85 assertSame("If conversion fails XLevel.TRACE is returned", xLevelResults, XLevel.TRACE); 86 } 87 88 94 public void testToLevelInt() { 95 assertSame("XLevel.TRACE is returned is " + TRACE_INT + "is passed", XLevel.toLevel(TRACE_INT), XLevel.TRACE); 96 Level levelResults = Level.toLevel(MOCK_INT); 97 Level xLevelResults = XLevel.toLevel(MOCK_INT); 98 assertSame("In all other cases conversion is deferred to Level", xLevelResults, levelResults); 99 assertSame("If conversion fails Level.DEBUG is returned", xLevelResults, Level.DEBUG); 100 } 101 102 } 103 | Popular Tags |