AdminService { public void setLoggerLevel(LoggerRequest loggerRequest) throws BadRequestException { try { Class.forName(loggerRequest.getName()); } catch (Throwable ignore) { throw new BadRequestException( "The class of '" + loggerRequest.getName() + "' doesn't exists"); } org.apache.log4j.Logger logger = LogManager.getLogger(loggerRequest.getName()); if (null == logger) { throw new BadRequestException("The name of the logger is wrong"); } org.apache.log4j.Level level = org.apache.log4j.Level.toLevel(loggerRequest.getLevel(), null); if (null == level) { throw new BadRequestException("The level of the logger is wrong"); } logger.setLevel(level); }  List<org.apache.log4j.Logger> getLoggers(); org.apache.log4j.Logger getLogger(String name); void setLoggerLevel(LoggerRequest loggerRequest);  }
@Test public void testSetLoggerLevel() { AdminService adminService = new AdminService(); String testLoggerName = "test"; org.apache.log4j.Logger logger = adminService.getLogger(testLoggerName); org.apache.log4j.Level level = logger.getLevel(); boolean setInfo = false; if (org.apache.log4j.Level.INFO == level) { logger.setLevel(org.apache.log4j.Level.DEBUG); } else { logger.setLevel(org.apache.log4j.Level.INFO); setInfo = true; } logger = adminService.getLogger(testLoggerName); assertTrue( "Level of logger should be changed", (setInfo && org.apache.log4j.Level.INFO == logger.getLevel()) || (!setInfo && Level.DEBUG == logger.getLevel())); }