@Test public void process_shouldStoreTheStackTraceInAFileBasedOnTheFingerPrint() throws Exception { Throwable expectedException = new RuntimeException("blah!"); String expectedFingerprint = "12345"; String expectedFilename = "stacktrace_" + expectedFingerprint + ".txt"; String expectedStacktraceUri = "file: String expectedMessage = expectedException.toString() + " (" + expectedStacktraceUri + ")"; when(fingerprintCalculator.calculateFingerprint(expectedException)).thenReturn(expectedFingerprint); Path expectedPath = mock(Path.class, withSettings().defaultAnswer(RETURNS_DEEP_STUBS)); when(mockDestinationDirectory.resolve(expectedFilename)).thenReturn(expectedPath); when(expectedPath.toUri()).thenReturn(new URI(expectedStacktraceUri)); pretendMockPathDoesNotExist(expectedPath); ByteArrayOutputStream simulatedFileOutputStream = new ByteArrayOutputStream(); when(Files.newOutputStream(expectedPath, CREATE_NEW, WRITE)).thenReturn(simulatedFileOutputStream); TestPrintStream expectedFileContents = new TestPrintStream(); expectedException.printStackTrace(expectedFileContents); StringBuilder output = new StringBuilder(); processor.process(expectedException, output); verify(expectedPath.getFileSystem().provider()).newOutputStream(expectedPath, CREATE_NEW, WRITE); assertEquals(expectedFileContents.toString(), new String(simulatedFileOutputStream.toByteArray())); assertEquals(expectedMessage, output.toString()); }
@Override public void process(Throwable throwable, StringBuilder output) throws Exception { Path stackTraceFile = calculateFilenameForException(throwable); writeStacktraceToPathIfNecessary(throwable, stackTraceFile); printSubstituteMessage(output, throwable, stackTraceFile); }
FilesystemStackTraceProcessor implements StackTraceProcessor { @Override public void process(Throwable throwable, StringBuilder output) throws Exception { Path stackTraceFile = calculateFilenameForException(throwable); writeStacktraceToPathIfNecessary(throwable, stackTraceFile); printSubstituteMessage(output, throwable, stackTraceFile); } }
FilesystemStackTraceProcessor implements StackTraceProcessor { @Override public void process(Throwable throwable, StringBuilder output) throws Exception { Path stackTraceFile = calculateFilenameForException(throwable); writeStacktraceToPathIfNecessary(throwable, stackTraceFile); printSubstituteMessage(output, throwable, stackTraceFile); } FilesystemStackTraceProcessor(Path destination, ThrowableFingerprintCalculator fingerprintCalculator); }
FilesystemStackTraceProcessor implements StackTraceProcessor { @Override public void process(Throwable throwable, StringBuilder output) throws Exception { Path stackTraceFile = calculateFilenameForException(throwable); writeStacktraceToPathIfNecessary(throwable, stackTraceFile); printSubstituteMessage(output, throwable, stackTraceFile); } FilesystemStackTraceProcessor(Path destination, ThrowableFingerprintCalculator fingerprintCalculator); @Override void process(Throwable throwable, StringBuilder output); Path getDestination(); }
FilesystemStackTraceProcessor implements StackTraceProcessor { @Override public void process(Throwable throwable, StringBuilder output) throws Exception { Path stackTraceFile = calculateFilenameForException(throwable); writeStacktraceToPathIfNecessary(throwable, stackTraceFile); printSubstituteMessage(output, throwable, stackTraceFile); } FilesystemStackTraceProcessor(Path destination, ThrowableFingerprintCalculator fingerprintCalculator); @Override void process(Throwable throwable, StringBuilder output); Path getDestination();  }