### Question:
Neo4jPersistenceExceptionTranslator implements PersistenceExceptionTranslator { @Override public DataAccessException translateExceptionIfPossible(RuntimeException ex) { if (ex instanceof DataAccessException) { return (DataAccessException) ex; } else if (ex instanceof DiscoveryException) { return translateImpl((Neo4jException) ex, TransientDataAccessResourceException::new); } else if (ex instanceof DatabaseException) { return translateImpl((Neo4jException) ex, NonTransientDataAccessResourceException::new); } else if (ex instanceof ServiceUnavailableException) { return translateImpl((Neo4jException) ex, NonTransientDataAccessResourceException::new); } else if (ex instanceof SessionExpiredException) { return translateImpl((Neo4jException) ex, RecoverableDataAccessException::new); } else if (ex instanceof ProtocolException) { return translateImpl((Neo4jException) ex, NonTransientDataAccessResourceException::new); } else if (ex instanceof TransientException) { return translateImpl((Neo4jException) ex, TransientDataAccessResourceException::new); } else if (ex instanceof ValueException) { return translateImpl((Neo4jException) ex, InvalidDataAccessApiUsageException::new); } else if (ex instanceof AuthenticationException) { return translateImpl((Neo4jException) ex, PermissionDeniedDataAccessException::new); } else if (ex instanceof ResultConsumedException) { return translateImpl((Neo4jException) ex, InvalidDataAccessApiUsageException::new); } else if (ex instanceof FatalDiscoveryException) { return translateImpl((Neo4jException) ex, NonTransientDataAccessResourceException::new); } else if (ex instanceof TransactionNestingException) { return translateImpl((Neo4jException) ex, InvalidDataAccessApiUsageException::new); } else if (ex instanceof ClientException) { return translateImpl((Neo4jException) ex, InvalidDataAccessResourceUsageException::new); } log.warn(() -> String.format("Don't know how to translate exception of type %s", ex.getClass())); return null; }  @Override DataAccessException translateExceptionIfPossible(RuntimeException ex);  }### Answer:
@Test void shouldHandleNullErrorCode() { Neo4jPersistenceExceptionTranslator translator = new Neo4jPersistenceExceptionTranslator(); DataAccessException dataAccessException = translator .translateExceptionIfPossible(new LossyCoercion("Long", "Int")); assertThat(dataAccessException).isNotNull().isInstanceOf(InvalidDataAccessApiUsageException.class); assertThat(dataAccessException.getMessage()) .isEqualTo("Cannot coerce Long to Int without losing precision; Error code 'N/A'"); }
@Test void shouldKeepErrorCodeIntact() { Neo4jPersistenceExceptionTranslator translator = new Neo4jPersistenceExceptionTranslator(); DataAccessException dataAccessException = translator .translateExceptionIfPossible( new ClientException("Neo.ClientError.Statement.EntityNotFound", "Something went wrong.")); assertThat(dataAccessException).isNotNull().isInstanceOf(InvalidDataAccessResourceUsageException.class); assertThat(dataAccessException.getMessage()) .isEqualTo("Something went wrong.; Error code 'Neo.ClientError.Statement.EntityNotFound'"); }