From 1d57a05f7fe3602b41be4635568c60180705c2e6 Mon Sep 17 00:00:00 2001 From: David Madden Date: Sun, 18 Nov 2018 07:45:21 +0000 Subject: [PATCH] DATAJPA-1451 - Make Assert messages consistent. Assert for notEmpty rather than length > 0. Make the messages match the actual assertion. Original pull request: #303. --- .../org/springframework/data/jpa/domain/JpaSort.java | 5 +++-- .../data/jpa/mapping/JpaMetamodelMappingContext.java | 3 ++- .../query/AbstractStringBasedJpaQuery.java | 3 ++- .../jpa/repository/support/SimpleJpaRepository.java | 12 ++++++------ ...lasspathScanningPersistenceUnitPostProcessor.java | 3 ++- 5 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/springframework/data/jpa/domain/JpaSort.java b/src/main/java/org/springframework/data/jpa/domain/JpaSort.java index 122481255..c747b22ce 100644 --- a/src/main/java/org/springframework/data/jpa/domain/JpaSort.java +++ b/src/main/java/org/springframework/data/jpa/domain/JpaSort.java @@ -34,6 +34,7 @@ import org.springframework.util.Assert; * @author Thomas Darimont * @author Oliver Gierke * @author Christoph Strobl + * @author David Madden */ public class JpaSort extends Sort { @@ -132,7 +133,7 @@ public class JpaSort extends Sort { */ public JpaSort andUnsafe(@Nullable Direction direction, String... properties) { - Assert.notEmpty(properties, "Properties must not be null!"); + Assert.notEmpty(properties, "Properties must not be empty!"); List orders = new ArrayList(); @@ -156,7 +157,7 @@ public class JpaSort extends Sort { private static Path[] paths(Attribute[] attributes) { Assert.notNull(attributes, "Attributes must not be null!"); - Assert.isTrue(attributes.length > 0, "Attributes must not be empty"); + Assert.notEmpty(attributes, "Attributes must not be empty!"); Path[] paths = new Path[attributes.length]; diff --git a/src/main/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContext.java b/src/main/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContext.java index b89648506..3b51d957a 100644 --- a/src/main/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContext.java +++ b/src/main/java/org/springframework/data/jpa/mapping/JpaMetamodelMappingContext.java @@ -38,6 +38,7 @@ import org.springframework.util.Assert; * @author Oliver Gierke * @author Christoph Strobl * @author Mark Paluch + * @author David Madden * @since 1.3 */ public class JpaMetamodelMappingContext @@ -54,7 +55,7 @@ public class JpaMetamodelMappingContext public JpaMetamodelMappingContext(Set models) { Assert.notNull(models, "JPA metamodel must not be null!"); - Assert.notEmpty(models, "At least one JPA metamodel must be present!"); + Assert.notEmpty(models, "JPA metamodel must not be empty!"); this.models = new Metamodels(models); this.persistenceProvider = PersistenceProvider.fromMetamodel(models.iterator().next()); diff --git a/src/main/java/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQuery.java b/src/main/java/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQuery.java index 15b54bcaf..25c7decc7 100644 --- a/src/main/java/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQuery.java +++ b/src/main/java/org/springframework/data/jpa/repository/query/AbstractStringBasedJpaQuery.java @@ -35,6 +35,7 @@ import org.springframework.util.Assert; * @author Thomas Darimont * @author Jens Schauder * @author Tom Hombergs + * @author David Madden */ abstract class AbstractStringBasedJpaQuery extends AbstractJpaQuery { @@ -60,7 +61,7 @@ abstract class AbstractStringBasedJpaQuery extends AbstractJpaQuery { Assert.hasText(queryString, "Query string must not be null or empty!"); Assert.notNull(evaluationContextProvider, "ExpressionEvaluationContextProvider must not be null!"); - Assert.notNull(parser, "Parser must not be null or empty!"); + Assert.notNull(parser, "Parser must not be null!"); this.evaluationContextProvider = evaluationContextProvider; this.query = new ExpressionBasedStringQuery(queryString, method.getEntityInformation(), parser); diff --git a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java index 93bf0dd6f..921a93e34 100644 --- a/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java +++ b/src/main/java/org/springframework/data/jpa/repository/support/SimpleJpaRepository.java @@ -68,6 +68,7 @@ import org.springframework.util.Assert; * @author Christoph Strobl * @author Stefan Fussenegger * @author Jens Schauder + * @author David Madden * @param the type of the entity to handle * @param the type of the entity's identifier */ @@ -167,7 +168,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation implements JpaRepositoryImplementation implements JpaRepositoryImplementation entities) { - Assert.notNull(entities, "The given Iterable of entities not be null!"); + Assert.notNull(entities, "Entities must not be null!"); for (T entity : entities) { delete(entity); @@ -205,7 +205,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation entities) { - Assert.notNull(entities, "The given Iterable of entities not be null!"); + Assert.notNull(entities, "Entities must not be null!"); if (!entities.iterator().hasNext()) { return; @@ -341,7 +341,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation findAllById(Iterable ids) { - Assert.notNull(ids, "The given Iterable of Id's must not be null!"); + Assert.notNull(ids, "Ids must not be null!"); if (!ids.iterator().hasNext()) { return Collections.emptyList(); @@ -553,7 +553,7 @@ public class SimpleJpaRepository implements JpaRepositoryImplementation List saveAll(Iterable entities) { - Assert.notNull(entities, "The given Iterable of entities not be null!"); + Assert.notNull(entities, "Entities must not be null!"); List result = new ArrayList(); diff --git a/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java b/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java index 90b454067..ae1701616 100644 --- a/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java +++ b/src/main/java/org/springframework/data/jpa/support/ClasspathScanningPersistenceUnitPostProcessor.java @@ -53,6 +53,7 @@ import org.springframework.util.StringUtils; * @author Oliver Gierke * @author Thomas Darimont * @author Mark Paluch + * @author David Madden */ public class ClasspathScanningPersistenceUnitPostProcessor implements PersistenceUnitPostProcessor, ResourceLoaderAware, EnvironmentAware { @@ -73,7 +74,7 @@ public class ClasspathScanningPersistenceUnitPostProcessor */ public ClasspathScanningPersistenceUnitPostProcessor(String basePackage) { - Assert.hasText(basePackage, "Base package must not be null!"); + Assert.hasText(basePackage, "Base package must not be null or empty!"); this.basePackage = basePackage; }