ModernJavaRuntime extends AbstractJavaRuntime { @Override public StackTraceElement getCallerStackTraceElement(final int depth) { return StackWalker.getInstance().walk(new FixedStackFrameExtractor(depth)).toStackTraceElement(); } ModernJavaRuntime(); @Override boolean isAndroid(); @Override long getProcessId(); @Override Timestamp getStartTime(); @Override String getCallerClassName(final int depth); @Override String getCallerClassName(final String loggerClassName); @Override StackTraceElement getCallerStackTraceElement(final int depth); @Override StackTraceElement getCallerStackTraceElement(final String loggerClassName); @Override Timestamp createTimestamp(); @Override TimestampFormatter createTimestampFormatter(final String pattern, final Locale locale);  }
@Test public void callerStackTraceElementByIndex() { assertThat(new ModernJavaRuntime().getCallerStackTraceElement(1)).isEqualTo(new Throwable().getStackTrace()[0]); }
@Test public void callerStackTraceElementBySuccessor() { String className = ModernJavaRuntime.class.getName(); assertThat(new ModernJavaRuntime().getCallerStackTraceElement(className)).isEqualTo(new Throwable().getStackTrace()[0]); }
@Test public void missingSuccessorForCallerStackTraceElement() { ModernJavaRuntime runtime = new ModernJavaRuntime(); assertThatThrownBy(() -> runtime.getCallerStackTraceElement(Logger.class.getName())) .isInstanceOf(IllegalStateException.class) .hasMessageContaining(Logger.class.getName()); }