INT-4221: Properly use Spring's Assert class

JIRA: https://jira.spring.io/browse/INT-4221

* Upgrade to those versions of Spring project dependencies which potentially will provide similar fix

**Cherry-pick to 4.3.x**
This commit is contained in:
Artem Bilan
2017-01-30 22:27:59 -05:00
parent d9c6ffee74
commit 6e7653f18f
22 changed files with 76 additions and 64 deletions

View File

@@ -127,7 +127,7 @@ subprojects { subproject ->
slf4jVersion = "1.7.21"
tomcatVersion = "8.0.33"
smackVersion = '4.1.7'
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '1.6.7.RELEASE'
springAmqpVersion = project.hasProperty('springAmqpVersion') ? project.springAmqpVersion : '1.6.8.BUILD-SNAPSHOT'
springDataJpaVersion = '1.10.1.RELEASE'
springDataMongoVersion = '1.9.1.RELEASE'
springDataRedisVersion = '1.7.1.RELEASE'
@@ -135,7 +135,7 @@ subprojects { subproject ->
springSecurityVersion = '4.1.0.RELEASE'
springSocialTwitterVersion = '1.1.2.RELEASE'
springRetryVersion = '1.1.3.RELEASE'
springVersion = project.hasProperty('springVersion') ? project.springVersion : '4.3.6.RELEASE'
springVersion = project.hasProperty('springVersion') ? project.springVersion : '4.3.7.BUILD-SNAPSHOT'
springWsVersion = '2.3.0.RELEASE'
xmlUnitVersion = '1.6'
xstreamVersion = '1.4.7'

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-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.
@@ -61,8 +61,8 @@ public class BrokerRunning extends TestWatcher {
* @return a new rule that assumes an existing running broker
*/
public static BrokerRunning isRunningWithEmptyQueues(Queue... queues) {
Assert.notNull(queues);
Assert.noNullElements(queues);
Assert.notNull(queues, "'queues' must not be null");
Assert.noNullElements(queues, "'queues' must not contain null elements");
return new BrokerRunning(queues);
}
@@ -72,8 +72,8 @@ public class BrokerRunning extends TestWatcher {
* @return a new rule that assumes an existing running broker
*/
public static BrokerRunning isRunningWithEmptyQueues(String... queues) {
Assert.notNull(queues);
Assert.noNullElements(queues);
Assert.notNull(queues, "'queues' must not be null");
Assert.noNullElements(queues, "'queues' must not contain null elements");
return new BrokerRunning(queues);
}

View File

@@ -154,7 +154,7 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
public void setLockRegistry(LockRegistry lockRegistry) {
Assert.isTrue(!this.lockRegistrySet, "'this.lockRegistry' can not be reset once its been set");
Assert.notNull("'lockRegistry' must not be null");
Assert.notNull(lockRegistry, "'lockRegistry' must not be null");
this.lockRegistry = lockRegistry;
this.lockRegistrySet = true;
}
@@ -170,12 +170,12 @@ public abstract class AbstractCorrelatingMessageHandler extends AbstractMessageP
}
public void setCorrelationStrategy(CorrelationStrategy correlationStrategy) {
Assert.notNull(correlationStrategy);
Assert.notNull(correlationStrategy, "'correlationStrategy' must not be null");
this.correlationStrategy = correlationStrategy;
}
public void setReleaseStrategy(ReleaseStrategy releaseStrategy) {
Assert.notNull(releaseStrategy);
Assert.notNull(releaseStrategy, "'releaseStrategy' must not be null");
this.releaseStrategy = releaseStrategy;
this.sequenceAware = this.releaseStrategy instanceof SequenceSizeReleaseStrategy;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-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,7 +48,7 @@ class IdempotentReceiverAutoProxyCreator extends AbstractAutoProxyCreator {
private volatile Map<String, List<String>> idempotentEndpoints; // double check locking requires volatile
public void setIdempotentEndpointsMapping(List<Map<String, String>> idempotentEndpointsMapping) {
Assert.notEmpty(idempotentEndpointsMapping);
Assert.notEmpty(idempotentEndpointsMapping, "'idempotentEndpointsMapping' must not be empty");
this.idempotentEndpointsMapping = idempotentEndpointsMapping; //NOSONAR (inconsistent sync)
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-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,7 +45,7 @@ public class ValueExpression<V> implements Expression {
@SuppressWarnings("unchecked")
public ValueExpression(V value) {
Assert.notNull(value);
Assert.notNull(value, "'value' must not be null");
this.value = value;
this.aClass = (Class<V>) this.value.getClass();
this.typedResultValue = new TypedValue(this.value);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-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.
@@ -72,7 +72,7 @@ public class IdempotentReceiverInterceptor extends AbstractHandleMessageAdvice i
private BeanFactory beanFactory;
public IdempotentReceiverInterceptor(MessageSelector messageSelector) {
Assert.notNull(messageSelector);
Assert.notNull(messageSelector, "'messageSelector' must not be null");
this.messageSelector = messageSelector;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-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.
@@ -63,8 +63,8 @@ public class ScatterGatherHandler extends AbstractReplyProducingMessageHandler i
public ScatterGatherHandler(MessageChannel scatterChannel, MessageHandler gatherer) {
Assert.notNull(scatterChannel);
Assert.notNull(gatherer);
Assert.notNull(scatterChannel, "'scatterChannel' must not be null");
Assert.notNull(gatherer, "'gatherer' must not be null");
Class<?> gathererClass = AopUtils.getTargetClass(gatherer);
checkClass(gathererClass, "org.springframework.integration.aggregator.AggregatingMessageHandler", "gatherer");
this.scatterChannel = scatterChannel;
@@ -73,7 +73,7 @@ public class ScatterGatherHandler extends AbstractReplyProducingMessageHandler i
public ScatterGatherHandler(MessageHandler scatterer, MessageHandler gatherer) {
this(new FixedSubscriberChannel(scatterer), gatherer);
Assert.notNull(scatterer);
Assert.notNull(scatterer, "'scatterer' must not be null");
Class<?> scattererClass = AopUtils.getTargetClass(scatterer);
checkClass(scattererClass, "org.springframework.integration.router.RecipientListRouter", "scatterer");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014 the original author or authors.
* Copyright 2014-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.
@@ -70,8 +70,8 @@ public class MetadataStoreSelector implements MessageSelector {
public MetadataStoreSelector(MessageProcessor<String> keyStrategy, MessageProcessor<String> valueStrategy,
ConcurrentMetadataStore metadataStore) {
Assert.notNull(keyStrategy);
Assert.notNull(metadataStore);
Assert.notNull(keyStrategy, "'keyStrategy' must not be null");
Assert.notNull(metadataStore, "'metadataStore' must not be null");
this.metadataStore = metadataStore;
this.keyStrategy = keyStrategy;
this.valueStrategy = valueStrategy;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-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.
@@ -72,7 +72,7 @@ public final class MutableMessageBuilder<T> extends AbstractIntegrationMessageBu
* @return A MutableMessageBuilder.
*/
public static <T> MutableMessageBuilder<T> fromMessage(Message<T> message) {
Assert.notNull(message, "message must not be null");
Assert.notNull(message, "'message' must not be null");
return new MutableMessageBuilder<T>(message);
}
@@ -88,7 +88,7 @@ public final class MutableMessageBuilder<T> extends AbstractIntegrationMessageBu
@Override
public AbstractIntegrationMessageBuilder<T> setHeader(String headerName, Object headerValue) {
Assert.notNull(headerName);
Assert.notNull(headerName, "'headerName' must not be null");
if (headerValue == null) {
this.removeHeader(headerName);
}

View File

@@ -54,8 +54,8 @@ public class RoutingSlipHeaderValueMessageProcessor
private BeanFactory beanFactory;
public RoutingSlipHeaderValueMessageProcessor(Object... routingSlipPath) {
Assert.notNull(routingSlipPath);
Assert.noNullElements(routingSlipPath);
Assert.notNull(routingSlipPath, "'routingSlipPath' must not be null");
Assert.noNullElements(routingSlipPath, "'routingSlipPath' must not contain null elements");
for (Object entry : routingSlipPath) {
if (!(entry instanceof String
|| entry instanceof MessageChannel

View File

@@ -14,4 +14,5 @@
</int:converter>
<bean id="integrationConversionService" class="org.springframework.context.support.ConversionServiceFactoryBean"/>
</beans>

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-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.
@@ -16,6 +16,8 @@
package org.springframework.integration.config.xml;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -30,16 +32,17 @@ import org.springframework.core.convert.support.GenericConversionService;
import org.springframework.integration.support.utils.IntegrationUtils;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.util.Assert;
/**
* @author Oleg Zhurakousky
* @author Artem Bilan
*
*/
@ContextConfiguration
@RunWith(SpringJUnit4ClassRunner.class)
public class ConverterParserWithExistingConversionServiceTests {
@Autowired
private ApplicationContext applicationContext;
@@ -49,9 +52,10 @@ public class ConverterParserWithExistingConversionServiceTests {
@Test
public void testConversionServiceAvailability() {
Assert.isTrue(applicationContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME).equals(conversionService));
Assert.isTrue(conversionService.canConvert(TestBean1.class, TestBean2.class));
Assert.isTrue(conversionService.canConvert(TestBean1.class, TestBean3.class));
assertTrue(applicationContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME)
.equals(conversionService));
assertTrue(conversionService.canConvert(TestBean1.class, TestBean2.class));
assertTrue(conversionService.canConvert(TestBean1.class, TestBean3.class));
}
@Test
public void testParentConversionServiceAvailability() {
@@ -63,13 +67,17 @@ public class ConverterParserWithExistingConversionServiceTests {
childContext.refresh();
GenericConversionService conversionServiceParent = parentContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, GenericConversionService.class);
GenericConversionService conversionServiceChild = childContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME, GenericConversionService.class);
Assert.isTrue(conversionServiceParent == conversionServiceChild); // validating that they are pointing to the same object
GenericConversionService conversionServiceParent =
parentContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
GenericConversionService.class);
GenericConversionService conversionServiceChild =
childContext.getBean(IntegrationUtils.INTEGRATION_CONVERSION_SERVICE_BEAN_NAME,
GenericConversionService.class);
assertTrue(conversionServiceParent == conversionServiceChild); // validating that they are pointing to the same object
conversionServiceChild.addConverter(new TestConverter());
conversionServiceChild.addConverter(new TestConverter3());
Assert.isTrue(conversionServiceChild.canConvert(TestBean1.class, TestBean2.class));
Assert.isTrue(conversionServiceChild.canConvert(TestBean1.class, TestBean3.class));
assertTrue(conversionServiceChild.canConvert(TestBean1.class, TestBean2.class));
assertTrue(conversionServiceChild.canConvert(TestBean1.class, TestBean3.class));
childContext.close();
parentContext.close();
}

View File

@@ -668,6 +668,8 @@ public class AdvisedMessageHandlerTests {
RetryTemplate retryTemplate = new RetryTemplate();
retryTemplate.setRetryPolicy(new SimpleRetryPolicy() {
static final long serialVersionUID = -1;
@Override
public boolean canRetry(RetryContext context) {
return false;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-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.
@@ -56,7 +56,7 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS
* @param file The absolute path of the file.
*/
public void setFile(File file) {
Assert.notNull("'file' cannot be null");
Assert.notNull(file, "'file' cannot be null");
this.file = file;
}
@@ -72,7 +72,7 @@ public abstract class FileTailingMessageProducerSupport extends MessageProducerS
* @param taskExecutor The task executor.
*/
public void setTaskExecutor(TaskExecutor taskExecutor) {
Assert.notNull("'taskExecutor' cannot be null");
Assert.notNull(taskExecutor, "'taskExecutor' cannot be null");
this.taskExecutor = taskExecutor;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-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.
@@ -82,12 +82,12 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements
}
public void setControlEncoding(String controlEncoding) {
Assert.hasText(controlEncoding);
Assert.hasText(controlEncoding, "'controlEncoding' must not be empty");
this.controlEncoding = controlEncoding;
}
public void setConfig(FTPClientConfig config) {
Assert.notNull(config);
Assert.notNull(config, "'config' must not be null");
this.config = config;
}
@@ -96,7 +96,7 @@ public abstract class AbstractFtpSessionFactory<T extends FTPClient> implements
}
public void setHost(String host) {
Assert.hasText(host);
Assert.hasText(host, "'host' must not be empty");
this.host = host;
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-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.messaging.Message;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.MessageHeaders;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* Message Mapper for converting to and from UDP DatagramPackets. When
@@ -149,7 +150,7 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
* Prefix raw byte[] from message with 'acknowledge to' and 'message id' "headers".
*/
private DatagramPacket fromMessageWithAck(Message<?> message) throws Exception {
Assert.hasLength(this.ackAddress);
Assert.state(StringUtils.hasText(this.ackAddress), "'ackAddress' must not be empty");
byte[] bytes = getPayloadAsBytes(message);
ByteBuffer buffer = ByteBuffer.allocate(100 + bytes.length);
if (this.lengthCheck) {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2001-2016 the original author or authors.
* Copyright 2001-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,7 @@ import org.springframework.messaging.MessageDeliveryException;
import org.springframework.messaging.MessageHandlingException;
import org.springframework.messaging.MessagingException;
import org.springframework.util.Assert;
import org.springframework.util.StringUtils;
/**
* A {@link org.springframework.messaging.MessageHandler} implementation that maps a Message into
@@ -213,7 +214,7 @@ public class UnicastSendingMessageHandler extends
}
this.acknowledge = acknowledge;
if (this.acknowledge) {
Assert.hasLength(ackHost);
Assert.state(StringUtils.hasText(ackHost), "'ackHost' must not be empty");
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2015-2016 the original author or authors.
* Copyright 2015-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.
@@ -47,7 +47,7 @@ public class MulticastRule extends TestWatcher {
}
public MulticastRule(String group) {
Assert.hasText(group);
Assert.hasText(group, "'group' must not be empty");
this.group = group;
System.setProperty("java.net.preferIPv4Stack", "true");
System.setProperty("multicast.group", this.group);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-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.
@@ -103,10 +103,9 @@ public final class JpaUtils {
*
*/
public static <T> Query applyAndBind(String queryString, Iterable<T> entities, EntityManager entityManager) {
Assert.notNull(queryString);
Assert.notNull(entities);
Assert.notNull(entityManager);
Assert.hasText(queryString, "'queryString' must not be empty");
Assert.notNull(entities, "'entities' must not be null");
Assert.notNull(entityManager, "'entityManager' must not be null");
Iterator<T> iterator = entities.iterator();

View File

@@ -94,8 +94,8 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe
protected MessageBuilderFactory messageBuilderFactory = new DefaultMessageBuilderFactory();
public AbstractConfigurableMongoDbMessageStore(MongoTemplate mongoTemplate, String collectionName) {
Assert.notNull("'mongoTemplate' must not be null");
Assert.hasText("'collectionName' must not be empty");
Assert.notNull(mongoTemplate, "'mongoTemplate' must not be null");
Assert.hasText(collectionName, "'collectionName' must not be empty");
this.collectionName = collectionName;
this.mongoTemplate = mongoTemplate;
this.mongoDbFactory = null;
@@ -107,8 +107,8 @@ public abstract class AbstractConfigurableMongoDbMessageStore extends AbstractMe
public AbstractConfigurableMongoDbMessageStore(MongoDbFactory mongoDbFactory,
MappingMongoConverter mappingMongoConverter, String collectionName) {
Assert.notNull("'mongoDbFactory' must not be null");
Assert.hasText("'collectionName' must not be empty");
Assert.notNull(mongoDbFactory, "'mongoDbFactory' must not be null");
Assert.hasText(collectionName, "'collectionName' must not be empty");
this.collectionName = collectionName;
this.mongoDbFactory = mongoDbFactory;
this.mappingMongoConverter = mappingMongoConverter;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2012 the original author or authors.
* Copyright 2002-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,7 +37,7 @@ public class SftpFileInfo extends AbstractFileInfo<LsEntry> {
public SftpFileInfo(LsEntry lsEntry) {
Assert.notNull("LsEntry must not be null");
Assert.notNull(lsEntry, "'lsEntry' must not be null");
this.lsEntry = lsEntry;
this.attrs = lsEntry.getAttrs();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-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.
@@ -76,7 +76,7 @@ public final class ClientWebSocketContainer extends IntegrationWebSocketContaine
}
public void setHeadersMap(Map<String, String> headers) {
Assert.notNull(headers);
Assert.notNull(headers, "'headers' must not be null");
HttpHeaders httpHeaders = new HttpHeaders();
for (Map.Entry<String, String> entry : headers.entrySet()) {
String[] values = StringUtils.commaDelimitedListToStringArray(entry.getValue());