From 56b3842ac11508bf885c3286eda75fe33b7efce5 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 31 Jan 2017 15:37:25 +0100 Subject: [PATCH] DATACOUCH-274 - 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. --- .../core/convert/ConverterRegistration.java | 5 +++-- .../core/convert/CustomConversions.java | 21 ++++++++++--------- .../convert/MappingCouchbaseConverter.java | 11 +++++----- .../ValidatingCouchbaseEventListener.java | 5 +++-- .../config/RepositoryOperationsMapping.java | 7 ++++--- .../query/AbstractN1qlBasedQuery.java | 8 ++++--- .../query/PartTreeN1qlBasedQuery.java | 7 ++++--- .../support/CouchbaseRepositoryFactory.java | 7 ++++--- .../support/N1qlCouchbaseRepository.java | 8 ++++--- .../support/SimpleCouchbaseRepository.java | 7 ++++--- 10 files changed, 49 insertions(+), 37 deletions(-) diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/ConverterRegistration.java b/src/main/java/org/springframework/data/couchbase/core/convert/ConverterRegistration.java index 2b55fdcc..cd8ea7ed 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/ConverterRegistration.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/ConverterRegistration.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 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. @@ -24,6 +24,7 @@ import org.springframework.util.Assert; * * @author Oliver Gierke * @author Michael Nitschinger + * @author Mark Paluch */ class ConverterRegistration { @@ -39,7 +40,7 @@ class ConverterRegistration { * @param isWriting whether to force to consider the converter for reading. */ public ConverterRegistration(ConvertiblePair convertiblePair, boolean isReading, boolean isWriting) { - Assert.notNull(convertiblePair); + Assert.notNull(convertiblePair, "ConvertiblePair must not be null!"); this.convertiblePair = convertiblePair; reading = isReading; diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java b/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java index 29a16236..2e1c81de 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/CustomConversions.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 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. @@ -45,6 +45,7 @@ import org.springframework.util.Assert; * * @author Michael Nitschinger * @author Oliver Gierke + * @author Mark Paluch */ public class CustomConversions { @@ -77,7 +78,7 @@ public class CustomConversions { * @param converters the list of custom converters. */ public CustomConversions(final List converters) { - Assert.notNull(converters); + Assert.notNull(converters, "List of Converters must not be null!"); readingPairs = new LinkedHashSet(); writingPairs = new LinkedHashSet(); @@ -216,7 +217,7 @@ public class CustomConversions { * @return */ public Class getCustomWriteTarget(Class sourceType, Class requestedTargetType) { - Assert.notNull(sourceType); + Assert.notNull(sourceType, "Source type must not be null!"); return getCustomTarget(sourceType, requestedTargetType, writingPairs); } @@ -228,7 +229,7 @@ public class CustomConversions { * @return */ public boolean hasCustomWriteTarget(Class sourceType) { - Assert.notNull(sourceType); + Assert.notNull(sourceType, "Source type must not be null!"); return hasCustomWriteTarget(sourceType, null); } @@ -241,7 +242,7 @@ public class CustomConversions { * @return */ public boolean hasCustomWriteTarget(Class sourceType, Class requestedTargetType) { - Assert.notNull(sourceType); + Assert.notNull(sourceType, "Source type must not be null!"); return getCustomWriteTarget(sourceType, requestedTargetType) != null; } @@ -253,8 +254,8 @@ public class CustomConversions { * @return */ public boolean hasCustomReadTarget(Class sourceType, Class requestedTargetType) { - Assert.notNull(sourceType); - Assert.notNull(requestedTargetType); + Assert.notNull(sourceType, "Source type must not be null!"); + Assert.notNull(requestedTargetType, "Requested target type must not be null!"); return getCustomReadTarget(sourceType, requestedTargetType) != null; } @@ -267,7 +268,7 @@ public class CustomConversions { * @return */ private Class getCustomReadTarget(Class sourceType, Class requestedTargetType) { - Assert.notNull(sourceType); + Assert.notNull(sourceType, "Source type must not be null!"); if (requestedTargetType == null) { return null; } @@ -297,8 +298,8 @@ public class CustomConversions { */ private static Class getCustomTarget(Class sourceType, Class requestedTargetType, Iterable pairs) { - Assert.notNull(sourceType); - Assert.notNull(pairs); + Assert.notNull(sourceType, "Source type must not be null!"); + Assert.notNull(pairs, "Pairs must not be null!"); for (GenericConverter.ConvertiblePair typePair : pairs) { if (typePair.getSourceType().isAssignableFrom(sourceType)) { diff --git a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java index e28920ea..57f84d23 100644 --- a/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java +++ b/src/main/java/org/springframework/data/couchbase/core/convert/MappingCouchbaseConverter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 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. @@ -64,6 +64,7 @@ import org.springframework.util.CollectionUtils; * @author Michael Nitschinger * @author Oliver Gierke * @author Geoffrey Mina + * @author Mark Paluch */ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter implements ApplicationContextAware { @@ -296,7 +297,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter @SuppressWarnings("unchecked") protected Map readMap(final TypeInformation type, final CouchbaseDocument source, final Object parent) { - Assert.notNull(source); + Assert.notNull(source, "CouchbaseDocument must not be null!"); Class mapType = typeMapper.readType(source, type).getType(); Map map = CollectionFactory.createMap(mapType, source.export().keySet().size()); @@ -630,7 +631,7 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter */ @SuppressWarnings("unchecked") private Object readCollection(final TypeInformation targetType, final CouchbaseList source, final Object parent) { - Assert.notNull(targetType); + Assert.notNull(targetType, "Target type must not be null!"); Class collectionType = targetType.getType(); if (source.isEmpty()) { @@ -788,8 +789,8 @@ public class MappingCouchbaseConverter extends AbstractCouchbaseConverter public CouchbasePropertyValueProvider(final CouchbaseDocument source, final DefaultSpELExpressionEvaluator evaluator, final Object parent) { - Assert.notNull(source); - Assert.notNull(evaluator); + Assert.notNull(source, "CouchbaseDocument must not be null!"); + Assert.notNull(evaluator, "DefaultSpELExpressionEvaluator must not be null!"); this.source = source; this.evaluator = evaluator; diff --git a/src/main/java/org/springframework/data/couchbase/core/mapping/event/ValidatingCouchbaseEventListener.java b/src/main/java/org/springframework/data/couchbase/core/mapping/event/ValidatingCouchbaseEventListener.java index 9860fc58..cc5cb281 100644 --- a/src/main/java/org/springframework/data/couchbase/core/mapping/event/ValidatingCouchbaseEventListener.java +++ b/src/main/java/org/springframework/data/couchbase/core/mapping/event/ValidatingCouchbaseEventListener.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 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. @@ -33,6 +33,7 @@ import org.springframework.util.Assert; * * @author Maciej Walkowiak * @author Michael Nitschinger + * @author Mark Paluch */ public class ValidatingCouchbaseEventListener extends AbstractCouchbaseEventListener { @@ -46,7 +47,7 @@ public class ValidatingCouchbaseEventListener extends AbstractCouchbaseEventList * @param validator must not be {@literal null}. */ public ValidatingCouchbaseEventListener(Validator validator) { - Assert.notNull(validator); + Assert.notNull(validator, "Validator must not be null!"); this.validator = validator; } diff --git a/src/main/java/org/springframework/data/couchbase/repository/config/RepositoryOperationsMapping.java b/src/main/java/org/springframework/data/couchbase/repository/config/RepositoryOperationsMapping.java index b762b8b3..ed24e457 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/config/RepositoryOperationsMapping.java +++ b/src/main/java/org/springframework/data/couchbase/repository/config/RepositoryOperationsMapping.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 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. @@ -31,6 +31,7 @@ import org.springframework.util.Assert; * by repository domain type or as a default fallback. * * @author Simon Baslé + * @author Mark Paluch */ public class RepositoryOperationsMapping { private CouchbaseOperations defaultOperations; @@ -44,7 +45,7 @@ public class RepositoryOperationsMapping { * @param defaultOperations the default fallback couchbase operations. */ public RepositoryOperationsMapping(CouchbaseOperations defaultOperations) { - Assert.notNull(defaultOperations); + Assert.notNull(defaultOperations, "CouchbaseOperations must not be null!"); this.defaultOperations = defaultOperations; } @@ -55,7 +56,7 @@ public class RepositoryOperationsMapping { * @return the mapping, for chaining. */ public RepositoryOperationsMapping setDefault(CouchbaseOperations aDefault) { - Assert.notNull(aDefault); + Assert.notNull(aDefault, "CouchbaseOperations must not be null!"); this.defaultOperations = aDefault; return this; } diff --git a/src/main/java/org/springframework/data/couchbase/repository/query/AbstractN1qlBasedQuery.java b/src/main/java/org/springframework/data/couchbase/repository/query/AbstractN1qlBasedQuery.java index 4adc6453..b8b47fd8 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/query/AbstractN1qlBasedQuery.java +++ b/src/main/java/org/springframework/data/couchbase/repository/query/AbstractN1qlBasedQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 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. @@ -50,6 +50,7 @@ import org.springframework.util.Assert; * * @author Simon Baslé * @author Subhashni Balakrishnan + * @author Mark Paluch */ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery { @@ -171,7 +172,8 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery { } protected Object executePaged(N1qlQuery query, N1qlQuery countQuery, Pageable pageable, Class typeToRead) { - Assert.notNull(pageable); + Assert.notNull(pageable, "Pageable must not be null!"); + long total = 0L; logIfNecessary(countQuery); List countResult = couchbaseOperations.findByN1QLProjection(countQuery, CountFragment.class); @@ -185,7 +187,7 @@ public abstract class AbstractN1qlBasedQuery implements RepositoryQuery { } protected Object executeSliced(N1qlQuery query, N1qlQuery countQuery, Pageable pageable, Class typeToRead) { - Assert.notNull(pageable); + Assert.notNull(pageable, "Pageable must not be null!"); logIfNecessary(query); List result = couchbaseOperations.findByN1QL(query, typeToRead); int pageSize = pageable.getPageSize(); diff --git a/src/main/java/org/springframework/data/couchbase/repository/query/PartTreeN1qlBasedQuery.java b/src/main/java/org/springframework/data/couchbase/repository/query/PartTreeN1qlBasedQuery.java index 025be3b3..ea77f85f 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/query/PartTreeN1qlBasedQuery.java +++ b/src/main/java/org/springframework/data/couchbase/repository/query/PartTreeN1qlBasedQuery.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 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. @@ -41,6 +41,7 @@ import org.springframework.util.Assert; * * @author Simon Baslé * @author Subhashni Balakrishnan + * @author Mark Paluch */ public class PartTreeN1qlBasedQuery extends AbstractN1qlBasedQuery { @@ -85,11 +86,11 @@ public class PartTreeN1qlBasedQuery extends AbstractN1qlBasedQuery { if (queryMethod.isPageQuery()) { Pageable pageable = accessor.getPageable(); - Assert.notNull(pageable); + Assert.notNull(pageable, "Pageable must not be null!"); return selectFromWhereOrderBy.limit(pageable.getPageSize()).offset(pageable.getOffset()); } else if (queryMethod.isSliceQuery() && accessor.getPageable() != null) { Pageable pageable = accessor.getPageable(); - Assert.notNull(pageable); + Assert.notNull(pageable, "Pageable must not be null!"); return selectFromWhereOrderBy.limit(pageable.getPageSize() + 1).offset(pageable.getOffset()); } else if (partTree.isLimiting()) { return selectFromWhereOrderBy.limit(partTree.getMaxResults()); diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java b/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java index 5052590d..3836acb3 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/CouchbaseRepositoryFactory.java @@ -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. @@ -57,6 +57,7 @@ import org.springframework.util.Assert; * @author Michael Nitschinger * @author Simon Baslé * @author Oliver Gierke + * @author Mark Paluch */ public class CouchbaseRepositoryFactory extends RepositoryFactorySupport { @@ -88,8 +89,8 @@ public class CouchbaseRepositoryFactory extends RepositoryFactorySupport { * @param couchbaseOperationsMapping the template for the underlying actions. */ public CouchbaseRepositoryFactory(final RepositoryOperationsMapping couchbaseOperationsMapping, final IndexManager indexManager) { - Assert.notNull(couchbaseOperationsMapping); - Assert.notNull(indexManager); + Assert.notNull(couchbaseOperationsMapping, "RepositoryOperationsMapping must not be null!"); + Assert.notNull(indexManager, "IndexManager must not be null!"); this.couchbaseOperationsMapping = couchbaseOperationsMapping; this.indexManager = indexManager; diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/N1qlCouchbaseRepository.java b/src/main/java/org/springframework/data/couchbase/repository/support/N1qlCouchbaseRepository.java index dab43b9f..91b22fbf 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/N1qlCouchbaseRepository.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/N1qlCouchbaseRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2015 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. @@ -44,6 +44,8 @@ import org.springframework.util.Assert; /** * A {@link CouchbasePagingAndSortingRepository} implementation. It uses N1QL for its {@link PagingAndSortingRepository} * method implementation. + * + * @author Mark Paluch */ public class N1qlCouchbaseRepository extends SimpleCouchbaseRepository @@ -61,7 +63,7 @@ public class N1qlCouchbaseRepository @Override public Iterable findAll(Sort sort) { - Assert.notNull(sort); + Assert.notNull(sort, "Sort must not be null!"); //prepare elements of the query WherePath selectFrom = N1qlUtils.createSelectFromForEntity(getCouchbaseOperations().getCouchbaseBucket().name()); @@ -80,7 +82,7 @@ public class N1qlCouchbaseRepository @Override public Page findAll(Pageable pageable) { - Assert.notNull(pageable); + Assert.notNull(pageable, "Pageable must not be null"); ScanConsistency consistency = getCouchbaseOperations().getDefaultConsistency().n1qlConsistency(); //prepare the count total query diff --git a/src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java b/src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java index 08214668..154a163c 100644 --- a/src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java +++ b/src/main/java/org/springframework/data/couchbase/repository/support/SimpleCouchbaseRepository.java @@ -1,5 +1,5 @@ /* - * Copyright 2013 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. @@ -38,6 +38,7 @@ import org.springframework.util.StringUtils; * Repository base implementation for Couchbase. * * @author Michael Nitschinger + * @author Mark Paluch */ public class SimpleCouchbaseRepository implements CouchbaseRepository { @@ -63,8 +64,8 @@ public class SimpleCouchbaseRepository implements Co * @param couchbaseOperations the reference to the template used. */ public SimpleCouchbaseRepository(final CouchbaseEntityInformation metadata, final CouchbaseOperations couchbaseOperations) { - Assert.notNull(couchbaseOperations); - Assert.notNull(metadata); + Assert.notNull(metadata, "CouchbaseEntityInformation must not be null!"); + Assert.notNull(couchbaseOperations, "CouchbaseOperations must not be null!"); entityInformation = metadata; this.couchbaseOperations = couchbaseOperations;