FailsafeLogger implements Logger { public Logger getLogger() { return logger; } FailsafeLogger(Logger logger); Logger getLogger(); void setLogger(Logger logger); @Override void trace(String msg, Throwable e); @Override void trace(Throwable e); @Override void trace(String msg); @Override void debug(String msg, Throwable e); @Override void debug(Throwable e); @Override void debug(String msg); @Override void info(String msg, Throwable e); @Override void info(String msg); @Override void warn(String msg, Throwable e); @Override void warn(String msg); @Override void error(String msg, Throwable e); @Override void error(String msg); @Override void error(Throwable e); @Override void info(Throwable e); @Override void warn(Throwable e); @Override boolean isTraceEnabled(); @Override boolean isDebugEnabled(); @Override boolean isInfoEnabled(); @Override boolean isWarnEnabled(); @Override boolean isErrorEnabled();  }
@Test(expected = RuntimeException.class) public void testGetLogger() { Logger failLogger = mock(Logger.class); FailsafeLogger failsafeLogger = new FailsafeLogger(failLogger); doThrow(new RuntimeException()).when(failLogger).error(anyString()); failsafeLogger.getLogger().error("should get error"); }
@Test public void testGetLogger() { Assertions.assertThrows(RuntimeException.class, () -> { Logger failLogger = mock(Logger.class); FailsafeLogger failsafeLogger = new FailsafeLogger(failLogger); doThrow(new RuntimeException()).when(failLogger).error(anyString()); failsafeLogger.getLogger().error("should get error"); }); }