@Test
public void testSegmentOnProcessFailure() throws Throwable {

    // Test to ensure that the exception is populated to the segment when an error occurs during the
    // processXRayTrace call.
    Exception expectedException = new RuntimeException("An intended exception");
    // Cause an intended exception to be thrown so that getCurrentSegmentOptional() is called.
    when(mockRecorder.beginSubsegment(any())).thenThrow(expectedException);
    Segment mockSegment = mock(Segment.class);
    when(mockRecorder.getCurrentSegmentOptional()).thenReturn(Optional.of(mockSegment));
    when(mockRecorder.getCurrentSegment()).thenReturn(mockSegment);
    try {
        xRayInterceptor.processXRayTrace(mockPjp);
    } catch (Exception e) {
        verify(mockSegment).addException(expectedException);
    }
}