### Question:
RotateLogListener extends SimpleLogListener implements Configurable, Destroyable { protected synchronized void openLogFile() throws IOException { if (f != null) f.close(); f = new FileOutputStream (logName, true); setPrintStream (new PrintStream(f)); p.println ("<?xml version=\"1.0\" encoding=\"UTF-8\"?>"); p.println ("<logger class=\"" + getClass().getName() + "\">"); } 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 testCheckSizeThrowsNullPointerException() throws Throwable { RotateLogListener rotateLogListener = new RotateLogListener(); try { rotateLogListener.openLogFile(); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull(ex.getMessage(), "ex.getMessage()"); assertNull(rotateLogListener.f, "rotateLogListener.f"); assertNotNull(rotateLogListener.p, "rotateLogListener.p"); } }
@Test public void testOpenLogFileThrowsNullPointerException() throws Throwable { RotateLogListener dailyLogListener = new DailyLogListener(); try { dailyLogListener.openLogFile(); fail("Expected NullPointerException to be thrown"); } catch (NullPointerException ex) { assertNull(((DailyLogListener) dailyLogListener).f, "(DailyLogListener) dailyLogListener.f"); assertNotNull(((DailyLogListener) dailyLogListener).p, "(DailyLogListener) dailyLogListener.p"); } }