LegacyJavaRuntime extends AbstractJavaRuntime { @Override @SuppressWarnings("removal") @IgnoreJRERequirement public String getCallerClassName(final int depth) { if (hasSunReflection) { return sun.reflect.Reflection.getCallerClass(depth + 1).getName(); } else { return getCallerStackTraceElement(depth + 1).getClassName(); } } LegacyJavaRuntime(); @Override boolean isAndroid(); @Override long getProcessId(); @Override Timestamp getStartTime(); @Override @SuppressWarnings("removal") @IgnoreJRERequirement 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 callerClassNameByIndex() { assertThat(new LegacyJavaRuntime().getCallerClassName(1)).isEqualTo(LegacyJavaRuntimeTest.class.getName()); }
@Test public void callerClassNameBySuccessor() { assertThat(new LegacyJavaRuntime().getCallerClassName(LegacyJavaRuntime.class.getName())) .isEqualTo(LegacyJavaRuntimeTest.class.getName()); }
@Test public void missingSunReflection() { LegacyJavaRuntime runtime = new LegacyJavaRuntime(); Whitebox.setInternalState(runtime, boolean.class, false); assertThat(runtime.getCallerClassName(1)).isEqualTo(LegacyJavaRuntimeTest.class.getName()); }