### Question:
PerformanceMonitoringExecutionObserver implements ExecutionObserver { @Override public void onResult(ExecutionResult executionResult) { double duration = timer.stop(); if (catchFailures) { monitor.addEvent(name, operation, duration, !executionResult.isFault()); } else { monitor.addEvent(name, operation, duration); } delegate.onResult(executionResult); } PerformanceMonitoringExecutionObserver(ExecutionObserver delegate, KPIMonitor monitor, KPITimer timer,
                                                  boolean catchFailures, String name, String operation); @Override void onResult(ExecutionResult executionResult);  }### Answer:
@Test public void shouldReportDuration() throws Exception { when(mockTimer.stop()).thenReturn(32D); observer = new PerformanceMonitoringExecutionObserver(mockObserver, mockMonitor, mockTimer, false, "name", "operation"); observer.onResult(mockResult); verify(mockObserver).onResult(mockResult); verify(mockMonitor).addEvent("name", "operation", 32D); }
@Test public void shouldReportDurationOnFault() throws Exception { when(mockTimer.stop()).thenReturn(32D); when(mockResult.isFault()).thenReturn(true); observer = new PerformanceMonitoringExecutionObserver(mockObserver, mockMonitor, mockTimer, false, "name", "operation"); observer.onResult(mockResult); verify(mockObserver).onResult(mockResult); verify(mockMonitor).addEvent("name", "operation", 32D); }
@Test public void shouldReportDurationCatchFailures() throws Exception { when(mockTimer.stop()).thenReturn(32D); observer = new PerformanceMonitoringExecutionObserver(mockObserver, mockMonitor, mockTimer, true, "name", "operation"); observer.onResult(mockResult); verify(mockObserver).onResult(mockResult); verify(mockMonitor).addEvent("name", "operation", 32D, true); }
@Test public void shouldReportDurationOnFaultCatchFailures() throws Exception { when(mockTimer.stop()).thenReturn(32D); when(mockResult.isFault()).thenReturn(true); observer = new PerformanceMonitoringExecutionObserver(mockObserver, mockMonitor, mockTimer, true, "name", "operation"); observer.onResult(mockResult); verify(mockObserver).onResult(mockResult); verify(mockMonitor).addEvent("name", "operation", 32D, false); }