### Question:
StacktraceCommand implements Stacktrace.Command { @ShellMethod(key = {"stacktrace"}, value = "Display the full stacktrace of the last error.") public void stacktrace() { Throwable lastError = TypePostProcessorResultHandler.THREAD_CONTEXT.get(); if (lastError != null) { lastError.printStackTrace(this.terminal.writer()); } }  @ShellMethod(key = {"stacktrace"}, value = "Display the full stacktrace of the last error.") void stacktrace(); @Autowired @Lazy void setTerminal(Terminal terminal);  }### Answer:
@Test void stacktrace() { TypePostProcessorResultHandler.THREAD_CONTEXT.set(null); StacktraceCommand cmd = new StacktraceCommand(); Terminal terminal = Mockito.mock(Terminal.class); Mockito.when(terminal.writer()).thenReturn(new PrintWriter(new StringWriter())); cmd.setTerminal(terminal); cmd.stacktrace(); Mockito.verify(terminal, Mockito.never()).writer(); TypePostProcessorResultHandler.THREAD_CONTEXT.set(new IllegalArgumentException("[TEST]")); cmd.stacktrace(); Mockito.verify(terminal, Mockito.times(1)).writer(); }