ErrorLogger implements ErrorHandler { public <T extends ExceptionWithContext> void log(L level, T throwable) { log(level, (Throwable) throwable, throwable.getContext().orElse(ErrorContext.builder().related("Missing Context").build())); } @Inject  ErrorLogger(
            PlanPlugin plugin,
            PluginLogger logger,
            PlanFiles files,
            Lazy<ServerProperties> serverProperties,
            Lazy<VersionChecker> versionChecker,
            Lazy<Formatters> formatters
    ); void log(L level, T throwable); void log(L level, Throwable throwable, ErrorContext context); void mergeAdditionalContext(Throwable throwable, ErrorContext context); @Override @Deprecated void log(L level, Class caughtBy, Throwable throwable);  }
@Test void simpleErrorIsLogged() throws IOException { IllegalStateException error = new IllegalStateException(); assertTimeoutPreemptively(Duration.ofMillis(500), () -> UNDER_TEST.log(L.WARN, error, ErrorContext.builder() .whatToDo("Succeed the test") .related("Test object") .build()) ); List<String> lines = getLines(error.getClass().getSimpleName()); assertTrue(lines.contains("java.lang.IllegalStateException"), () -> "Did not contain 'java.lang.IllegalStateException', " + lines); }
@Test void errorWithACauseIsLogged() throws IOException { IllegalStateException error = new IllegalStateException( new IllegalArgumentException( new NullPointerException() ) ); assertTimeoutPreemptively(Duration.ofMillis(500), () -> UNDER_TEST.log(L.WARN, error, ErrorContext.builder() .whatToDo("Succeed the test") .related("Test object") .build()) ); List<String> lines = getLines(error.getClass().getSimpleName()); assertTrue(lines.contains("java.lang.IllegalStateException: java.lang.IllegalArgumentException: java.lang.NullPointerException"), () -> "Did not contain 'java.lang.IllegalStateException: java.lang.IllegalArgumentException: java.lang.NullPointerException', " + lines); assertTrue(lines.contains("Caused by:"), () -> "Did not contain 'Caused by:', " + lines); assertTrue(lines.contains("java.lang.IllegalArgumentException: java.lang.NullPointerException"), () -> "Did not contain 'java.lang.IllegalArgumentException: java.lang.NullPointerException', " + lines); assertTrue(lines.contains("java.lang.NullPointerException"), () -> "Did not contain 'caused by: java.lang.NullPointerException', " + lines); }
@Test void errorWithSuppressedIsLogged() throws IOException { IllegalStateException error = new IllegalStateException(); error.addSuppressed(new IllegalArgumentException()); error.addSuppressed(new NullPointerException()); assertTimeoutPreemptively(Duration.ofMillis(500), () -> UNDER_TEST.log(L.WARN, error, ErrorContext.builder() .whatToDo("Succeed the test") .related("Test object") .build()) ); List<String> lines = getLines(error.getClass().getSimpleName()); assertTrue(lines.contains("java.lang.IllegalStateException"), () -> "Did not contain 'java.lang.IllegalStateException', " + lines); assertTrue(lines.contains(" Suppressed:"), () -> "Did not contain ' Suppressed:', " + lines); assertTrue(lines.contains(" java.lang.IllegalArgumentException"), () -> "Did not contain ' java.lang.IllegalArgumentException', " + lines); assertTrue(lines.contains(" java.lang.NullPointerException"), () -> "Did not contain ' java.lang.NullPointerException', " + lines); }