### Question:
Slf4jAuditLogger implements AuditLogger { @Override public void log(AuditEntry logEntry) { auditLogger.info(formatter.getLogTemplate(), formatter.getArgumentsForEntry(logEntry)); } Slf4jAuditLogger(Map<String, String> parameters); @VisibleForTesting  Slf4jAuditLogger(Map<String, String> parameters, String loggerName); @VisibleForTesting  Slf4jAuditLogger(Slf4jAuditLoggerConfig auditConfig, Logger logger); @Override void log(AuditEntry logEntry); static final String AUDIT_LOGGER_NAME; }### Answer:
@Test public void testDefaultFormatAuditEntryNoBatch() { Slf4jAuditLogger logger = loggerWithConfig(DEFAULT_LOG_FORMAT); logger.log(logEntryWithoutBatch); assertThat(getSlf4jLogMessage()) .isEqualTo("client:'127.0.0.1'|user:'user'|status:'ATTEMPT'|operation:'insert into ks.tbl (key, val) values (?, ?)['kalle', 'anka']'"); }
@Test public void testDefaultFormatAuditEntryWithAll() { Slf4jAuditLogger logger = loggerWithConfig(DEFAULT_LOG_FORMAT); logger.log(logEntryWithAll); assertThat(getSlf4jLogMessage()) .isEqualTo("client:'127.0.0.1'|user:'user'|batchId:'12345678-aaaa-bbbb-cccc-123456789abc'|status:'ATTEMPT'|operation:'insert into ks.tbl (key, val) values (?, ?)['kalle', 'anka']'"); }
@Test public void testCustomLogFormat() { Slf4jAuditLogger logger = loggerWithConfig("User = ${USER}, Status = {${STATUS}}, Query = ${OPERATION_NAKED}"); logger.log(logEntryWithoutBatch); assertThat(getSlf4jLogMessage()) .isEqualTo("User = user, Status = {ATTEMPT}, Query = insert into ks.tbl (key, val) values (?, ?)"); }
@Test public void testCustomLogFormatWithSubject() { Slf4jAuditLogger logger = loggerWithConfig("User = ${USER}, Status = {${STATUS}}, Subject = ${SUBJECT}"); logger.log(logEntryWithAll); assertThat(getSlf4jLogMessage()) .isEqualTo("User = user, Status = {ATTEMPT}, Subject = the_subject"); }
@Test public void testAnchorCharactersAreEscapedWhenUsedInLogFormat() { Slf4jAuditLogger logger = loggerWithConfig("{}User=${USER}{}Status=${STATUS}"); logger.log(logEntryWithoutBatch); assertThat(getSlf4jLogMessage()) .isEqualTo("{}User=user{}Status=ATTEMPT"); }