Revisit Assert to avoid single-arg assert methods (with refined messages)

Issue: SPR-15196
This commit is contained in:
Juergen Hoeller
2017-01-30 22:15:53 +01:00
parent 768802fa96
commit 1b2dc3638f
118 changed files with 708 additions and 828 deletions

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.
@@ -33,7 +33,7 @@ public class ClassWithComplexConstructor {
@Autowired
public ClassWithComplexConstructor(Dependency dependency) {
Assert.notNull(dependency);
Assert.notNull(dependency, "No Dependency bean injected");
this.dependency = dependency;
}
@@ -42,7 +42,8 @@ public class ClassWithComplexConstructor {
}
public void method() {
Assert.isTrue(this.selfReference != this && AopUtils.isCglibProxy(this.selfReference));
Assert.state(this.selfReference != this && AopUtils.isCglibProxy(this.selfReference),
"Self reference must be a CGLIB proxy");
this.dependency.method();
}

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.
@@ -1250,7 +1250,7 @@ public class ConfigurationClassPostProcessorTests {
@PostConstruct
public void validate() {
Assert.notNull(provider);
Assert.notNull(provider, "No ServiceBeanProvider injected");
}
}
@@ -1291,7 +1291,7 @@ public class ConfigurationClassPostProcessorTests {
@PostConstruct
public void validate() {
Assert.notNull(provider);
Assert.notNull(provider, "No ServiceBeanProvider injected");
}
}
@@ -1403,7 +1403,7 @@ public class ConfigurationClassPostProcessorTests {
static class DependingFoo {
DependingFoo(BarArgument bar) {
Assert.notNull(bar);
Assert.notNull(bar, "No BarArgument injected");
}
}

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.
@@ -72,7 +72,8 @@ public class Service implements ApplicationContextAware, MessageSourceAware, Dis
Thread thread = new Thread() {
@Override
public void run() {
Assert.isTrue(applicationContext.getBean("messageSource") instanceof StaticMessageSource);
Assert.state(applicationContext.getBean("messageSource") instanceof StaticMessageSource,
"Invalid MessageSource bean");
try {
applicationContext.getBean("service2");
// Should have thrown BeanCreationNotAllowedException

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.
@@ -355,6 +355,7 @@ public class DateTimeFormattingTests {
}
@Test
@SuppressWarnings("deprecation")
public void testBindInstantFromJavaUtilDate() throws Exception {
MutablePropertyValues propertyValues = new MutablePropertyValues();
propertyValues.add("instant", new Date(109, 9, 31, 12, 0));

View File

@@ -240,7 +240,7 @@ public class SpringValidatorAdapterTests {
else {
context.disableDefaultConstraintViolation();
context.buildConstraintViolationWithTemplate(message)
.addNode(field)
.addPropertyNode(field)
.addConstraintViolation();
return false;
}