@Test
 public void testTranslatesIllegalArgumentException() {
   IllegalArgumentException iae = new IllegalArgumentException();
   DataAccessException dex = EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(iae);
   assertSame(iae, dex.getCause());
   assertTrue(dex instanceof InvalidDataAccessApiUsageException);
 }
 /** We do not convert unknown exceptions. They may result from user code. */
 @Test
 public void testDoesNotTranslateUnfamiliarException() {
   UnsupportedOperationException userRuntimeException = new UnsupportedOperationException();
   assertNull(
       "Exception should not be wrapped",
       EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(userRuntimeException));
 }
  /*
   * Test method for
   * 'org.springframework.orm.jpa.EntityManagerFactoryUtils.convertJpaAccessException(PersistenceException)'
   */
  @Test
  @SuppressWarnings("serial")
  public void testConvertJpaPersistenceException() {
    EntityNotFoundException entityNotFound = new EntityNotFoundException();
    assertSame(
        JpaObjectRetrievalFailureException.class,
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityNotFound).getClass());

    NoResultException noResult = new NoResultException();
    assertSame(
        EmptyResultDataAccessException.class,
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(noResult).getClass());

    NonUniqueResultException nonUniqueResult = new NonUniqueResultException();
    assertSame(
        IncorrectResultSizeDataAccessException.class,
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(nonUniqueResult).getClass());

    OptimisticLockException optimisticLock = new OptimisticLockException();
    assertSame(
        JpaOptimisticLockingFailureException.class,
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(optimisticLock).getClass());

    EntityExistsException entityExists = new EntityExistsException("foo");
    assertSame(
        DataIntegrityViolationException.class,
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(entityExists).getClass());

    TransactionRequiredException transactionRequired = new TransactionRequiredException("foo");
    assertSame(
        InvalidDataAccessApiUsageException.class,
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(transactionRequired)
            .getClass());

    PersistenceException unknown = new PersistenceException() {};
    assertSame(
        JpaSystemException.class,
        EntityManagerFactoryUtils.convertJpaAccessExceptionIfPossible(unknown).getClass());
  }