src/test/java/ru/indvdum/jpa/tests/AbstractJPAEntityTest.groovy
changeset 20 a05948e9458c
parent 15 7d8a7e7635d2
     1.1 --- a/src/test/java/ru/indvdum/jpa/tests/AbstractJPAEntityTest.groovy	Thu Dec 20 19:59:53 2012 +0400
     1.2 +++ b/src/test/java/ru/indvdum/jpa/tests/AbstractJPAEntityTest.groovy	Sun Dec 23 03:24:53 2012 +0400
     1.3 @@ -17,7 +17,7 @@
     1.4  import org.junit.Test
     1.5  
     1.6  import ru.indvdum.jpa.dao.JPADataAccessObject
     1.7 -import ru.indvdum.jpa.entities.AbstractEntity;
     1.8 +import ru.indvdum.jpa.entities.AbstractEntity
     1.9  
    1.10  
    1.11  /**
    1.12 @@ -100,6 +100,8 @@
    1.13  	 * @return created entity object
    1.14  	 */
    1.15  	protected Object createEntity(Class entityClass) {
    1.16 +		if (entityClass.isInterface())
    1.17 +			return null;
    1.18  		assertNotNull entityClass.annotations.find {it instanceof Entity}
    1.19  		def entity = entityClass.newInstance()
    1.20  		assert entity.class == entityClass
    1.21 @@ -167,10 +169,10 @@
    1.22  			newValue = type.newInstance(uniqueValue++ % Byte.MAX_VALUE + 1i)
    1.23  		} else if(type == String.class) {
    1.24  			newValue = (String) "test${uniqueValue++}"
    1.25 -		} else if(type instanceof Class && (type as Class).annotations.find {it instanceof Entity} != null) { // modifying of a primary keys is deprecated
    1.26 +		} else if(type instanceof Class && ((type as Class).isInterface() || (type as Class).annotations.find {it instanceof Entity} != null)) { // modifying of a primary keys is deprecated
    1.27  			// an attempt to use already created entities
    1.28  			def currentValue = getFieldValue(entity, field)
    1.29 -			newValue = toRemove.find {it.class == type && it != currentValue}
    1.30 +			newValue = toRemove.find {it.class.isAssignableFrom(type) && it != currentValue}
    1.31  			if(newValue == null)
    1.32  				newValue = createEntity(type as Class)
    1.33  		} else if(Enum.class.isAssignableFrom(type)) {