### Question:
RotateLogListener extends SimpleLogListener implements Configurable, Destroyable { public void setConfiguration (Configuration cfg) throws ConfigurationException { if (maxCopies == 0) { maxCopies = cfg.getInt("copies", 0); } if (sleepTime == 0) { sleepTime = cfg.getInt("window") * 1000; } if (logName == null) { logName = cfg.get ("file"); } if (maxSize == 0) { maxSize = cfg.getLong("maxsize"); maxSize = maxSize <= 0 ? DEFAULT_MAXSIZE : maxSize; } rotateOnStartup = cfg.getBoolean("rotate-on-startup", false); if (fileNamePattern == null) { fileNamePattern = cfg.get("file-name-pattern", null); } if (fileNamePattern != null && !fileNamePattern.isEmpty()) { logName = fileNameFromPattern(logName, fileNamePattern); } if (timer == null) { timer = () -> { Timer timer = DefaultTimer.getTimer(); if (sleepTime != 0) timer.schedule(rotate = new Rotate(), sleepTime, sleepTime); }; } if (rotationAlgo == null) { rotationAlgo = () -> { for (int i = maxCopies; i > 0; ) { File dest = new File(logName + "." + i); File source = new File(logName + (--i > 0 ? "." + i : "")); dest.delete(); source.renameTo(dest); } }; } runPostConfiguration(); } RotateLogListener(); void setConfiguration(Configuration cfg); synchronized LogEvent log(LogEvent ev); void logRotate(); synchronized void logRotate(boolean isStartup); void destroy(); static final int CHECK_INTERVAL; static final long DEFAULT_MAXSIZE; }### Answer:
@Test public void testSetConfigurationThrowsNullPointerException() throws Throwable { RotateLogListener rotateLogListener = new RotateLogListener(); Configuration cfg = new SubConfiguration(); try { rotateLogListener.setConfiguration(cfg); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { if (isJavaVersionAtMost(JAVA_14)) { assertNull(ex.getMessage(), "ex.getMessage()"); } else { assertEquals("Cannot invoke \"org.jpos.core.Configuration.getInt(String, int)\" because \"this.cfg\" is null", ex.getMessage(), "ex.getMessage()"); } assertNull(rotateLogListener.logName, "rotateLogListener.logName"); assertEquals(0L, rotateLogListener.sleepTime, "rotateLogListener.sleepTime"); assertEquals(0L, rotateLogListener.maxSize, "rotateLogListener.maxSize"); assertEquals(0, rotateLogListener.maxCopies, "rotateLogListener.maxCopies"); assertNull(rotateLogListener.rotate, "rotateLogListener.rotate"); assertNull(rotateLogListener.f, "rotateLogListener.f"); assertNotNull(rotateLogListener.p, "rotateLogListener.p"); } }