polishing

Updating pull request for SPR-9541
This commit is contained in:
Stephane Nicoll 2014-05-06 16:04:39 +02:00
parent 371e3a7ac0
commit e18308851d
6 changed files with 41 additions and 31 deletions

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,7 +25,7 @@ import org.springframework.dao.support.PersistenceExceptionTranslator;
* instances to Spring's {@link DataAccessException} hierarchy.
*
* @author Jan Stamer
* @since 3.2
* @since 4.1
* @see org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor
*/
public class EclipseLinkExceptionTranslator implements PersistenceExceptionTranslator {
@ -42,7 +42,7 @@ public class EclipseLinkExceptionTranslator implements PersistenceExceptionTrans
* the {@code org.springframework.dao} hierarchy.
* @param ex EclipseLinkException that occurred
* @return a corresponding DataAccessException
* @see SessionFactoryUtils#convertEclipseLinkAccessException
* @see EclipseLinkUtils#convertEclipseLinkAccessException
*/
protected DataAccessException convertEclipseLinkAccessException(EclipseLinkException ex) {
return EclipseLinkUtils.convertEclipseLinkAccessException(ex);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -25,14 +25,15 @@ import org.springframework.dao.UncategorizedDataAccessException;
* <code>org.springframework.dao</code> exceptions.
*
* @author Jan Stamer
* @since 3.2
* @since 4.1
* @see EclipseLinkUtils#convertEclipseLinkAccessException(EclipseLinkException)
*/
@SuppressWarnings("serial")
public class EclipseLinkSystemException extends UncategorizedDataAccessException {
/**
* Create a new HibernateSystemException, wrapping an arbitrary
* HibernateException.
* {@link EclipseLinkException}.
* @param cause the HibernateException thrown
*/
public EclipseLinkSystemException(EclipseLinkException cause) {

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -31,7 +31,7 @@ public abstract class EclipseLinkUtils {
/**
* Convert the given EclipseLinkException to an appropriate exception from
* the <code>org.springframework.dao</code> hierarchy.
* @param ex EclipseLinkException that occured
* @param ex EclipseLinkException that occurred
* @return the corresponding DataAccessException instance
* @see EclipseLinkExceptionTranslator#convertEclipseLinkAccessException(EclipseLinkException)
*/

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,26 +16,29 @@
package org.springframework.orm.eclipselink;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.springframework.dao.DataAccessException;
import org.junit.Test;
/**
* @author Jan Stamer
* @since 3.2
*/
public class EclipseLinkExceptionTranslatorTests extends TestCase {
public class EclipseLinkExceptionTranslatorTests {
public void testWithWrongException() {
@Test
public void wrongException() {
EclipseLinkExceptionTranslator exceptionTranslator = new EclipseLinkExceptionTranslator();
assertNull(exceptionTranslator.translateExceptionIfPossible(new IllegalArgumentException()));
}
public void testWithEclipseLinkException() {
@SuppressWarnings("ThrowableResultOfMethodCallIgnored")
@Test
public void eclipseLinkException() {
EclipseLinkExceptionTranslator exceptionTranslator = new EclipseLinkExceptionTranslator();
assertNotNull(exceptionTranslator.translateExceptionIfPossible(DatabaseException.databaseAccessorNotConnected()));
assertTrue(exceptionTranslator.translateExceptionIfPossible(DatabaseException.databaseAccessorNotConnected()) instanceof DataAccessException);
assertNotNull(exceptionTranslator.translateExceptionIfPossible(
DatabaseException.databaseAccessorNotConnected()));
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,24 +16,27 @@
package org.springframework.orm.eclipselink;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.hibernate.HibernateException;
import org.junit.Test;
/**
* @author Jan Stamer
* @since 3.2
*/
public class EclipseLinkSytemExceptionTests extends TestCase {
@SuppressWarnings("serial")
public class EclipseLinkSystemExceptionTests {
public void testWithNull() {
@Test
public void withNull() {
EclipseLinkSystemException exception = new EclipseLinkSystemException(null);
assertNull(exception.getCause());
assertNull(exception.getMessage());
}
public void testCreateWithCause() {
@Test
public void createWithCause() {
DatabaseException dbExceptionWithCause = new DatabaseException("my custom exception cause") {
};
EclipseLinkSystemException elSystemException = new EclipseLinkSystemException(dbExceptionWithCause);
@ -41,7 +44,8 @@ public class EclipseLinkSytemExceptionTests extends TestCase {
assertTrue(elSystemException.getMessage().contains("my custom exception cause"));
}
public void testCreateWithNullCause() throws HibernateException {
@Test
public void createWithNullCause() throws HibernateException {
DatabaseException dbExceptionWithCause = new DatabaseException((String) null) {
};
EclipseLinkSystemException elSystemException = new EclipseLinkSystemException(dbExceptionWithCause);

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-2014 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,23 +16,25 @@
package org.springframework.orm.eclipselink;
import junit.framework.TestCase;
import static org.junit.Assert.*;
import org.eclipse.persistence.exceptions.DatabaseException;
import org.springframework.dao.DataAccessException;
import org.junit.Test;
/**
* @author Jan Stamer
* @since 3.2
*/
public class EclipseLinkUtilsTests extends TestCase {
public class EclipseLinkUtilsTests {
public void testWithNull() {
assertTrue(EclipseLinkUtils.convertEclipseLinkAccessException(null) instanceof DataAccessException);
@Test
public void withNull() {
assertNotNull(EclipseLinkUtils.convertEclipseLinkAccessException(null));
}
@Test
public void testWithEclipseLinkException() {
assertTrue(EclipseLinkUtils.convertEclipseLinkAccessException(DatabaseException.databaseAccessorNotConnected()) instanceof DataAccessException);
assertNotNull(EclipseLinkUtils.convertEclipseLinkAccessException(
DatabaseException.databaseAccessorNotConnected()));
}
}