### Question:
LoggingDataAccessExceptionMapper extends LoggingExceptionMapper<DataAccessException> { @Override protected void logException(long id, DataAccessException exception) { final Throwable cause = exception.getCause(); if (cause instanceof SQLException) { for (Throwable throwable : (SQLException) cause) { logger.error(formatLogMessage(id, throwable), throwable); } } else { logger.error(formatLogMessage(id, exception), exception); } }    }### Answer:
@Test public void logsUnderlyingSQLException() { SQLException cause = new SQLException("BAR"); DataAccessException e = new DataAccessException("FOO", cause); mapper.logException(0, e); verify(logger).error(anyString(), eq(cause)); }
@Test public void logsAllUnderlyingCauses() { SQLException one = new SQLException("a"); SQLException two = new SQLException("b"); SQLException e = new SQLException("fail"); e.setNextException(one); e.setNextException(two); DataAccessException dae = new DataAccessException("moar fail", e); mapper.logException(0, dae); verify(logger).error(anyString(), eq(e)); verify(logger).error(anyString(), eq(one)); verify(logger).error(anyString(), eq(two)); }
@Test public void logsExceptionItselfIfNoSQLException() { DataAccessException e = new DataAccessException("BAZ"); mapper.logException(0, e); verify(logger).error(anyString(), eq(e)); }