### Question:
LoggerContext extends ContextBase implements ILoggerFactory,
        LifeCycle { public final Logger getLogger(final Class<?> clazz) { return getLogger(clazz.getName()); } LoggerContext(); @Override void putProperty(String key, String val); void putProperties(Properties props); @Override void setName(String name); final Logger getLogger(final Class<?> clazz); Logger getLogger(final String name); Logger exists(String name); List<Logger> getLoggerList(); LoggerContextVO getLoggerContextRemoteView(); void setPackagingDataEnabled(boolean packagingDataEnabled); boolean isPackagingDataEnabled(); @Override void reset(); TurboFilterList getTurboFilterList(); void addTurboFilter(TurboFilter newFilter); void resetTurboFilterList(); void addListener(LoggerContextListener listener); void removeListener(LoggerContextListener listener); List<LoggerContextListener> getCopyOfListenerList(); void start(); void stop(); @Override String toString(); int getMaxCallerDataDepth(); void setMaxCallerDataDepth(int maxCallerDataDepth); List<String> getFrameworkPackages(); static final boolean DEFAULT_PACKAGING_DATA; }### Answer:
@Test public void loggerNameEndingInDotOrDollarShouldWork() { { String loggerName = "toto.x."; Logger logger = lc.getLogger(loggerName); assertEquals(loggerName, logger.getName()); } { String loggerName = "toto.x$"; Logger logger = lc.getLogger(loggerName); assertEquals(loggerName, logger.getName()); } }
@Test public void testRootGetLogger() { Logger root = lc.getLogger(Logger.ROOT_LOGGER_NAME); assertEquals(Level.DEBUG, root.getLevel()); assertEquals(Level.DEBUG, root.getEffectiveLevel()); }
@Test public void testLoggerX() { Logger x = lc.getLogger("x"); assertNotNull(x); assertEquals("x", x.getName()); assertNull(x.getLevel()); assertEquals(Level.DEBUG, x.getEffectiveLevel()); }
@Test public void testNull() { try { lc.getLogger((String) null); fail("null should cause an exception"); } catch (IllegalArgumentException e) { } }
@Test public void testLoggerMultipleChildren() { assertEquals(1, instanceCount()); Logger xy0 = lc.getLogger("x.y0"); LoggerTestHelper.assertNameEquals(xy0, "x.y0"); Logger xy1 = lc.getLogger("x.y1"); LoggerTestHelper.assertNameEquals(xy1, "x.y1"); LoggerTestHelper.assertLevels(null, xy0, Level.DEBUG); LoggerTestHelper.assertLevels(null, xy1, Level.DEBUG); assertEquals(4, instanceCount()); for (int i = 0; i < 100; i++) { Logger xy_i = lc.getLogger("x.y" + i); LoggerTestHelper.assertNameEquals(xy_i, "x.y" + i); LoggerTestHelper.assertLevels(null, xy_i, Level.DEBUG); } assertEquals(102, instanceCount()); }
@Test public void testMultiLevel() { Logger wxyz = lc.getLogger("w.x.y.z"); LoggerTestHelper.assertNameEquals(wxyz, "w.x.y.z"); LoggerTestHelper.assertLevels(null, wxyz, Level.DEBUG); Logger wx = lc.getLogger("w.x"); wx.setLevel(Level.INFO); LoggerTestHelper.assertNameEquals(wx, "w.x"); LoggerTestHelper.assertLevels(Level.INFO, wx, Level.INFO); LoggerTestHelper.assertLevels(null, lc.getLogger("w.x.y"), Level.INFO); LoggerTestHelper.assertLevels(null, wxyz, Level.INFO); }
@Test public void testStatusWithUnconfiguredContext() { Logger logger = lc.getLogger(LoggerContextTest.class); for (int i = 0; i < 3; i++) { logger.debug("test"); } logger = lc.getLogger("x.y.z"); for (int i = 0; i < 3; i++) { logger.debug("test"); } StatusManager sm = lc.getStatusManager(); assertTrue("StatusManager has recieved too many messages", sm.getCount() == 1); }