DATAJPA-1054 - Remove references to Assert single-arg methods.

Replace references to Assert single-arg methods with references to methods accepting the test object and message.

Related ticket: SPR-15196.
This commit is contained in:
Mark Paluch
2017-01-31 11:05:32 +01:00
parent f909a853a8
commit 308f991575
18 changed files with 84 additions and 70 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2017 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 javax.persistence.EntityManager;
import org.springframework.data.jpa.repository.support.JpaRepositoryFactory;
import org.springframework.data.repository.cdi.CdiRepositoryBean;
import org.springframework.data.repository.config.CustomRepositoryImplementationDetector;
import org.springframework.data.repository.config.CustomRepositoryImplementationDetector;
import org.springframework.util.Assert;
/**
@@ -47,14 +47,14 @@ class JpaRepositoryBean<T> extends CdiRepositoryBean<T> {
* @param entityManagerBean must not be {@literal null}.
* @param qualifiers must not be {@literal null}.
* @param repositoryType must not be {@literal null}.
* @param detector can be {@literal null}.
* @param detector can be {@literal null}.
*/
JpaRepositoryBean(BeanManager beanManager, Bean<EntityManager> entityManagerBean, Set<Annotation> qualifiers,
Class<T> repositoryType, CustomRepositoryImplementationDetector detector) {
Class<T> repositoryType, CustomRepositoryImplementationDetector detector) {
super(qualifiers, repositoryType, beanManager, detector);
super(qualifiers, repositoryType, beanManager, detector);
Assert.notNull(entityManagerBean);
Assert.notNull(entityManagerBean, "EntityManager bean must not be null!");
this.entityManagerBean = entityManagerBean;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2016 the original author or authors.
* Copyright 2008-2017 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.
@@ -48,6 +48,7 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Mark Paluch
*/
public abstract class AbstractJpaQuery implements RepositoryQuery {
@@ -59,13 +60,12 @@ public abstract class AbstractJpaQuery implements RepositoryQuery {
* Creates a new {@link AbstractJpaQuery} from the given {@link JpaQueryMethod}.
*
* @param method
* @param resultFactory
* @param em
*/
public AbstractJpaQuery(JpaQueryMethod method, EntityManager em) {
Assert.notNull(method);
Assert.notNull(em);
Assert.notNull(method, "JpaQueryMethod must not be null!");
Assert.notNull(em, "EntityManager must not be null!");
this.method = method;
this.em = em;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2013 the original author or authors.
* Copyright 2011-2017 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.
@@ -32,6 +32,7 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Mark Paluch
*/
class CriteriaQueryParameterBinder extends ParameterBinder {
@@ -41,14 +42,15 @@ class CriteriaQueryParameterBinder extends ParameterBinder {
* Creates a new {@link CriteriaQueryParameterBinder} for the given {@link Parameters}, values and some
* {@link javax.persistence.criteria.ParameterExpression}.
*
* @param parameters
* @param values
* @param expressions
* @param parameters must not be {@literal null}.
* @param values must not be {@literal null}.
* @param expressions must not be {@literal null}.
*/
CriteriaQueryParameterBinder(JpaParameters parameters, Object[] values, Iterable<ParameterMetadata<?>> expressions) {
super(parameters, values);
Assert.notNull(expressions);
Assert.notNull(expressions, "Iterable of ParameterMetadata must not be null!");
this.expressions = expressions.iterator();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2016 the original author or authors.
* Copyright 2008-2017 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.
@@ -229,8 +229,8 @@ public class JpaQueryCreator extends AbstractQueryCreator<CriteriaQuery<? extend
*/
public PredicateBuilder(Part part, Root<?> root) {
Assert.notNull(part);
Assert.notNull(root);
Assert.notNull(part, "Part must not be null!");
Assert.notNull(root, "Root must not be null!");
this.part = part;
this.root = root;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2016 the original author or authors.
* Copyright 2008-2017 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.
@@ -71,13 +71,13 @@ public abstract class JpaQueryExecution {
* Executes the given {@link AbstractStringBasedJpaQuery} with the given {@link ParameterBinder}.
*
* @param query must not be {@literal null}.
* @param binder must not be {@literal null}.
* @param values must not be {@literal null}.
* @return
*/
public Object execute(AbstractJpaQuery query, Object[] values) {
Assert.notNull(query);
Assert.notNull(values);
Assert.notNull(query, "AbstractJpaQuery must not be null!");
Assert.notNull(values, "Values must not be null!");
Object result;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2014 the original author or authors.
* Copyright 2008-2017 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.
@@ -33,6 +33,7 @@ import org.springframework.util.Assert;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Mark Paluch
*/
public class ParameterBinder {
@@ -48,8 +49,8 @@ public class ParameterBinder {
*/
public ParameterBinder(JpaParameters parameters, Object[] values) {
Assert.notNull(parameters);
Assert.notNull(values);
Assert.notNull(parameters, "JpaParameters must not be null!");
Assert.notNull(values, "Values must not be null!");
Assert.isTrue(parameters.getNumberOfParameters() == values.length, "Invalid number of parameters given!");

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 the original author or authors.
* Copyright 2011-2017 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.
@@ -41,6 +41,7 @@ import org.springframework.util.ObjectUtils;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Mark Paluch
*/
class ParameterMetadataProvider {
@@ -144,12 +145,12 @@ class ParameterMetadataProvider {
* @param <T>
* @param part must not be {@literal null}.
* @param type must not be {@literal null}.
* @param name
* @param parameter
* @return
*/
private <T> ParameterMetadata<T> next(Part part, Class<T> type, Parameter parameter) {
Assert.notNull(type);
Assert.notNull(type, "Type must not be null!");
/*
* We treat Expression types as Object vales since the real value to be bound as a parameter is determined at query time.
@@ -221,7 +222,7 @@ class ParameterMetadataProvider {
*/
public Object prepare(Object value) {
Assert.notNull(value);
Assert.notNull(value, "Value must not be null!");
Class<? extends T> expressionType = expression.getJavaType();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2016 the original author or authors.
* Copyright 2008-2017 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.
@@ -69,6 +69,7 @@ import org.springframework.util.StringUtils;
* @author Thomas Darimont
* @author Komi Innocent
* @author Christoph Strobl
* @author Mark Paluch
*/
public abstract class QueryUtils {
@@ -221,14 +222,14 @@ public abstract class QueryUtils {
/**
* Adds {@literal order by} clause to the JPQL query.
*
* @param query
* @param query must not be {@literal null} or empty.
* @param sort
* @param alias
* @return
*/
public static String applySorting(String query, Sort sort, String alias) {
Assert.hasText(query);
Assert.hasText(query, "Query must not be null or empty!");
if (null == sort || !sort.iterator().hasNext()) {
return query;
@@ -356,16 +357,16 @@ public abstract class QueryUtils {
* entities to the query.
*
* @param <T>
* @param queryString
* @param entities
* @param entityManager
* @param queryString must not be {@literal null}.
* @param entities must not be {@literal null}.
* @param entityManager must not be {@literal null}.
* @return
*/
public static <T> Query applyAndBind(String queryString, Iterable<T> entities, EntityManager entityManager) {
Assert.notNull(queryString);
Assert.notNull(entities);
Assert.notNull(entityManager);
Assert.notNull(queryString, "Querystring must not be null!");
Assert.notNull(entities, "Iterable of entities must not be null!");
Assert.notNull(entityManager, "EntityManager must not be null!");
Iterator<T> iterator = entities.iterator();
@@ -489,8 +490,8 @@ public abstract class QueryUtils {
return orders;
}
Assert.notNull(root);
Assert.notNull(cb);
Assert.notNull(root, "Root must not be null!");
Assert.notNull(cb, "CriteriaBuilder must not be null!");
for (org.springframework.data.domain.Sort.Order order : sort) {
orders.add(toJpaOrder(order, root, cb));

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2013-2016 the original author or authors.
* Copyright 2013-2017 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.
@@ -37,6 +37,7 @@ import org.springframework.util.StringUtils;
* @author Oliver Gierke
* @author Thomas Darimont
* @author Oliver Wehrens
* @author Mark Paluch
*/
class StringQuery {
@@ -729,7 +730,7 @@ class StringQuery {
*/
private static Type getLikeTypeFrom(String expression) {
Assert.hasText(expression);
Assert.hasText(expression, "Expression must not be null or empty!");
if (expression.matches("%.*%")) {
return Type.CONTAINING;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2017 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.
@@ -30,6 +30,7 @@ import org.springframework.util.Assert;
* Base class for {@link JpaEntityInformation} implementations to share common method implementations.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
public abstract class JpaEntityInformationSupport<T, ID extends Serializable> extends AbstractEntityInformation<T, ID>
implements JpaEntityInformation<T, ID> {
@@ -56,8 +57,8 @@ public abstract class JpaEntityInformationSupport<T, ID extends Serializable> ex
@SuppressWarnings({ "rawtypes", "unchecked" })
public static <T> JpaEntityInformation<T, ?> getEntityInformation(Class<T> domainClass, EntityManager em) {
Assert.notNull(domainClass);
Assert.notNull(em);
Assert.notNull(domainClass, "Domain class must not be null!");
Assert.notNull(em, "EntityManager must not be null!");
Metamodel metamodel = em.getMetamodel();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 the original author or authors.
* Copyright 2011-2017 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.
@@ -64,7 +64,7 @@ public class JpaMetamodelEntityInformation<T, ID extends Serializable> extends J
super(domainClass);
Assert.notNull(metamodel);
Assert.notNull(metamodel, "Metamodel must not be null!");
this.metamodel = metamodel;
ManagedType<T> type = metamodel.managedType(domainClass);
@@ -210,7 +210,9 @@ public class JpaMetamodelEntityInformation<T, ID extends Serializable> extends J
* @see org.springframework.data.jpa.repository.support.JpaEntityInformation#getCompositeIdAttributeValue(java.io.Serializable, java.lang.String)
*/
public Object getCompositeIdAttributeValue(Serializable id, String idAttribute) {
Assert.isTrue(hasCompositeId());
Assert.isTrue(hasCompositeId(), "Model must have a composite Id!");
return new DirectFieldAccessFallbackBeanWrapper(id).getPropertyValue(idAttribute);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2015 the original author or authors.
* Copyright 2008-2017 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.
@@ -38,6 +38,7 @@ import org.springframework.util.Assert;
* JPA specific generic repository factory.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
public class JpaRepositoryFactory extends RepositoryFactorySupport {
@@ -52,7 +53,7 @@ public class JpaRepositoryFactory extends RepositoryFactorySupport {
*/
public JpaRepositoryFactory(EntityManager entityManager) {
Assert.notNull(entityManager);
Assert.notNull(entityManager, "EntityManager must not be null!");
this.entityManager = entityManager;
this.extractor = PersistenceProvider.fromEntityManager(entityManager);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2011 the original author or authors.
* Copyright 2011-2017 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.
@@ -35,6 +35,7 @@ import com.querydsl.jpa.impl.JPAUpdateClause;
* Base class for implementing repositories using QueryDsl library.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
@Repository
public abstract class QueryDslRepositorySupport {
@@ -50,7 +51,8 @@ public abstract class QueryDslRepositorySupport {
* @param domainClass must not be {@literal null}.
*/
public QueryDslRepositorySupport(Class<?> domainClass) {
Assert.notNull(domainClass);
Assert.notNull(domainClass, "Domain class must not be null!");
this.builder = new PathBuilderFactory().create(domainClass);
}
@@ -62,7 +64,7 @@ public abstract class QueryDslRepositorySupport {
@PersistenceContext
public void setEntityManager(EntityManager entityManager) {
Assert.notNull(entityManager);
Assert.notNull(entityManager, "EntityManager must not be null!");
this.querydsl = new Querydsl(entityManager, builder);
this.entityManager = entityManager;
}
@@ -88,7 +90,7 @@ public abstract class QueryDslRepositorySupport {
/**
* Returns a fresh {@link JPQLQuery}.
*
* @param path must not be {@literal null}.
* @param paths must not be {@literal null}.
* @return the Querydsl {@link JPQLQuery}.
*/
protected JPQLQuery<Object> from(EntityPath<?>... paths) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2014 the original author or authors.
* Copyright 2012-2017 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.
@@ -46,6 +46,7 @@ import com.querydsl.jpa.impl.JPAQuery;
*
* @author Oliver Gierke
* @author Thomas Darimont
* @author Mark Paluch
*/
public class Querydsl {
@@ -61,8 +62,8 @@ public class Querydsl {
*/
public Querydsl(EntityManager em, PathBuilder<?> builder) {
Assert.notNull(em);
Assert.notNull(builder);
Assert.notNull(em, "EntityManager must not be null!");
Assert.notNull(builder, "PathBuilder must not be null!");
this.em = em;
this.provider = PersistenceProvider.fromEntityManager(em);

View File

@@ -92,8 +92,8 @@ public class SimpleJpaRepository<T, ID extends Serializable>
*/
public SimpleJpaRepository(JpaEntityInformation<T, ?> entityInformation, EntityManager entityManager) {
Assert.notNull(entityInformation);
Assert.notNull(entityManager);
Assert.notNull(entityInformation, "JpaEntityInformation must not be null!");
Assert.notNull(entityManager, "EntityManager must not be null!");
this.entityInformation = entityInformation;
this.em = entityManager;
@@ -705,8 +705,9 @@ public class SimpleJpaRepository<T, ID extends Serializable>
private <S, U extends T> Root<U> applySpecificationToCriteria(Specification<U> spec, Class<U> domainClass,
CriteriaQuery<S> query) {
Assert.notNull(query);
Assert.notNull(domainClass);
Assert.notNull(domainClass, "Domain class must not be null!");
Assert.notNull(query, "CriteriaQuery must not be null!");
Root<U> root = query.from(domainClass);
if (spec == null) {
@@ -752,7 +753,7 @@ public class SimpleJpaRepository<T, ID extends Serializable>
*/
private static Long executeCountQuery(TypedQuery<Long> query) {
Assert.notNull(query);
Assert.notNull(query, "TypedQuery must not be null!");
List<Long> totals = query.getResultList();
Long total = 0L;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2011 the original author or authors.
* Copyright 2008-2017 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.
@@ -23,6 +23,7 @@ import org.springframework.util.Assert;
* Stub implementation for {@link AuditorAware}. Returns {@literal null} for the current auditor.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
public class AuditorAwareStub implements AuditorAware<AuditableUser> {
@@ -32,7 +33,7 @@ public class AuditorAwareStub implements AuditorAware<AuditableUser> {
public AuditorAwareStub(AuditableUserRepository repository) {
Assert.notNull(repository);
Assert.notNull(repository, "AuditableUserRepository must not be null!");
this.repository = repository;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2011 the original author or authors.
* Copyright 2008-2017 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.
@@ -40,8 +40,8 @@ public class SampleEntityPK implements Serializable {
public SampleEntityPK(String first, String second) {
Assert.notNull(first);
Assert.notNull(second);
Assert.notNull(first, "First must not be null!");
Assert.notNull(second, "Second must not be null!");
this.first = first;
this.second = second;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2011 the original author or authors.
* Copyright 2008-2017 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.
@@ -38,6 +38,7 @@ import org.springframework.util.Assert;
* intermediate interface.
*
* @author Oliver Gierke
* @author Mark Paluch
*/
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:config/namespace-customfactory-context.xml")
@@ -57,8 +58,6 @@ public class CustomRepositoryFactoryConfigTests {
@Test(expected = UnsupportedOperationException.class)
public void testCustomFactoryUsed() {
Assert.notNull(userRepository);
userRepository.customMethod(1);
}