### Question:
DefaultAuditor implements Auditor { @Override public void audit(AuditEntry logEntry) { if (shouldAudit(logEntry)) { AuditEntry obfuscatedEntry = obfuscator.obfuscate(logEntry); performAudit(obfuscatedEntry); } } DefaultAuditor(AuditLogger logger, AuditFilter filter, AuditObfuscator obfuscator, LogTimingStrategy logTimingStrategy);   DefaultAuditor(AuditLogger logger, AuditFilter filter, AuditObfuscator obfuscator, AuditMetrics auditMetrics, LogTimingStrategy logTimingStrategy); @Override void setup(); @Override void audit(AuditEntry logEntry); @Override boolean shouldLogForStatus(Status status); @Override boolean shouldLogFailedBatchSummary(); @Override void setLogTimingStrategy(LogTimingStrategy logTimingStrategy); @Override void addLogger(AuditLogger logger); @Override void removeLogger(AuditLogger logger);  }### Answer:
@Test public void testAuditFiltered() { AuditEntry logEntry = AuditEntry.newBuilder().build(); when(mockFilter.isWhitelisted(logEntry)).thenReturn(true); long timeTaken = timedOperation(() -> auditor.audit(logEntry)); verify(mockFilter).isWhitelisted(logEntry); verify(mockAuditMetrics).filterAuditRequest(timingCaptor.capture(), eq(TimeUnit.NANOSECONDS)); verifyNoMoreInteractions(mockAuditMetrics); verifyZeroInteractions(mockLogger, mockObfuscator); long timeMeasured = timingCaptor.getValue(); assertThat(timeMeasured).isLessThanOrEqualTo(timeTaken); }
@Test public void testAuditFilteredThrowsException() { AuditEntry logEntry = AuditEntry.newBuilder().build(); when(mockFilter.isWhitelisted(logEntry)).thenThrow(new ReadTimeoutException(ConsistencyLevel.QUORUM, 1, 1, false)); long timeTaken = timedOperation(() -> auditor.audit(logEntry), CassandraException.class); verify(mockAuditMetrics).filterAuditRequest(timingCaptor.capture(), eq(TimeUnit.NANOSECONDS)); verifyNoMoreInteractions(mockAuditMetrics); verifyZeroInteractions(mockLogger, mockObfuscator); long timeMeasured = timingCaptor.getValue(); assertThat(timeMeasured).isLessThanOrEqualTo(timeTaken); }
@Test public void testAuditNotFiltered() { AuditEntry logEntry = AuditEntry.newBuilder().build(); when(mockFilter.isWhitelisted(logEntry)).thenReturn(false); when(mockObfuscator.obfuscate(logEntry)).thenReturn(logEntry); long timeTaken = timedOperation(() -> auditor.audit(logEntry)); verify(mockFilter).isWhitelisted(logEntry); verify(mockObfuscator).obfuscate(logEntry); verify(mockLogger).log(logEntry); verify(mockAuditMetrics).filterAuditRequest(timingCaptor.capture(), eq(TimeUnit.NANOSECONDS)); verify(mockAuditMetrics).logAuditRequest(timingCaptor.capture(), eq(TimeUnit.NANOSECONDS)); long timeMeasured = timingCaptor.getAllValues().stream().mapToLong(l -> l).sum(); assertThat(timeMeasured).isLessThanOrEqualTo(timeTaken); }