Polish tests

See gh-27248
This commit is contained in:
Syuziko
2021-08-07 16:10:08 +04:00
committed by Stephane Nicoll
parent ce6217be85
commit eaf9deedfd
36 changed files with 1115 additions and 1121 deletions

View File

@@ -162,13 +162,13 @@ class ProceedTestingAspect implements Ordered {
public Object doubleOrQuits(ProceedingJoinPoint pjp) throws Throwable {
int value = ((Integer) pjp.getArgs()[0]).intValue();
pjp.getArgs()[0] = new Integer(value * 2);
pjp.getArgs()[0] = Integer.valueOf(value * 2);
return pjp.proceed();
}
public Object addOne(ProceedingJoinPoint pjp, Float value) throws Throwable {
float fv = value.floatValue();
return pjp.proceed(new Object[] {new Float(fv + 1.0F)});
return pjp.proceed(new Object[] {Float.valueOf(fv + 1.0F)});
}
public void captureStringArgument(JoinPoint tjp, String arg) {

View File

@@ -79,7 +79,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Stephane Nicoll
* @author Juergen Hoeller
*/
public class AnnotationDrivenEventListenerTests {
class AnnotationDrivenEventListenerTests {
private ConfigurableApplicationContext context;
@@ -97,7 +97,7 @@ public class AnnotationDrivenEventListenerTests {
@Test
public void simpleEventJavaConfig() {
void simpleEventJavaConfig() {
load(TestEventListener.class);
TestEvent event = new TestEvent(this, "test");
TestEventListener listener = this.context.getBean(TestEventListener.class);
@@ -120,7 +120,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void simpleEventXmlConfig() {
void simpleEventXmlConfig() {
this.context = new ClassPathXmlApplicationContext(
"org/springframework/context/event/simple-event-configuration.xml");
@@ -141,7 +141,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void metaAnnotationIsDiscovered() {
void metaAnnotationIsDiscovered() {
load(MetaAnnotationListenerTestBean.class);
MetaAnnotationListenerTestBean bean = this.context.getBean(MetaAnnotationListenerTestBean.class);
this.eventCollector.assertNoEventReceived(bean);
@@ -159,7 +159,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void contextEventsAreReceived() {
void contextEventsAreReceived() {
load(ContextEventListener.class);
ContextEventListener listener = this.context.getBean(ContextEventListener.class);
@@ -175,7 +175,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void methodSignatureNoEvent() {
void methodSignatureNoEvent() {
@SuppressWarnings("resource")
AnnotationConfigApplicationContext failingContext =
new AnnotationConfigApplicationContext();
@@ -189,7 +189,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void simpleReply() {
void simpleReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, "dummy");
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@@ -204,7 +204,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void nullReplyIgnored() {
void nullReplyIgnored() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, null); // No response
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@@ -219,7 +219,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void arrayReply() {
void arrayReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, new String[]{"first", "second"});
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@@ -234,7 +234,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void collectionReply() {
void collectionReply() {
load(TestEventListener.class, ReplyEventListener.class);
Set<Object> replies = new LinkedHashSet<>();
replies.add("first");
@@ -253,7 +253,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void collectionReplyNullValue() {
void collectionReplyNullValue() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, Arrays.asList(null, "test"));
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@@ -268,7 +268,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenableFutureReply() {
void listenableFutureReply() {
load(TestEventListener.class, ReplyEventListener.class);
SettableListenableFuture<String> future = new SettableListenableFuture<>();
future.set("dummy");
@@ -285,7 +285,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void completableFutureReply() {
void completableFutureReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, CompletableFuture.completedFuture("dummy"));
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@@ -300,7 +300,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void monoReply() {
void monoReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, Mono.just("dummy"));
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@@ -315,7 +315,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void fluxReply() {
void fluxReply() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, Flux.just("dummy1", "dummy2"));
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@@ -330,7 +330,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void eventListenerWorksWithSimpleInterfaceProxy() {
void eventListenerWorksWithSimpleInterfaceProxy() {
load(ScopedProxyTestBean.class);
SimpleService proxy = this.context.getBean(SimpleService.class);
@@ -347,7 +347,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void eventListenerWorksWithAnnotatedInterfaceProxy() {
void eventListenerWorksWithAnnotatedInterfaceProxy() {
load(AnnotatedProxyTestBean.class);
AnnotatedSimpleService proxy = this.context.getBean(AnnotatedSimpleService.class);
@@ -364,7 +364,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void eventListenerWorksWithCglibProxy() {
void eventListenerWorksWithCglibProxy() {
load(CglibProxyTestBean.class);
CglibProxyTestBean proxy = this.context.getBean(CglibProxyTestBean.class);
@@ -381,14 +381,14 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void privateMethodOnCglibProxyFails() {
void privateMethodOnCglibProxyFails() {
assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(() ->
load(CglibProxyWithPrivateMethod.class))
.withCauseInstanceOf(IllegalStateException.class);
}
@Test
public void eventListenerWorksWithCustomScope() {
void eventListenerWorksWithCustomScope() {
load(CustomScopeTestBean.class);
CustomScope customScope = new CustomScope();
this.context.getBeanFactory().registerScope("custom", customScope);
@@ -417,7 +417,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void asyncProcessingApplied() throws InterruptedException {
void asyncProcessingApplied() throws InterruptedException {
loadAsync(AsyncEventListener.class);
String threadName = Thread.currentThread().getName();
@@ -432,7 +432,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void asyncProcessingAppliedWithInterfaceProxy() throws InterruptedException {
void asyncProcessingAppliedWithInterfaceProxy() throws InterruptedException {
doLoad(AsyncConfigurationWithInterfaces.class, SimpleProxyTestBean.class);
String threadName = Thread.currentThread().getName();
@@ -447,7 +447,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void asyncProcessingAppliedWithScopedProxy() throws InterruptedException {
void asyncProcessingAppliedWithScopedProxy() throws InterruptedException {
doLoad(AsyncConfigurationWithInterfaces.class, ScopedProxyTestBean.class);
String threadName = Thread.currentThread().getName();
@@ -462,7 +462,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void exceptionPropagated() {
void exceptionPropagated() {
load(ExceptionEventListener.class);
TestEvent event = new TestEvent(this, "fail");
ExceptionEventListener listener = this.context.getBean(ExceptionEventListener.class);
@@ -475,7 +475,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void exceptionNotPropagatedWithAsync() throws InterruptedException {
void exceptionNotPropagatedWithAsync() throws InterruptedException {
loadAsync(ExceptionEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, "fail");
ExceptionEventListener listener = this.context.getBean(ExceptionEventListener.class);
@@ -489,7 +489,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithSimplePayload() {
void listenerWithSimplePayload() {
load(TestEventListener.class);
TestEventListener listener = this.context.getBean(TestEventListener.class);
@@ -500,7 +500,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithNonMatchingPayload() {
void listenerWithNonMatchingPayload() {
load(TestEventListener.class);
TestEventListener listener = this.context.getBean(TestEventListener.class);
@@ -511,7 +511,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void replyWithPayload() {
void replyWithPayload() {
load(TestEventListener.class, ReplyEventListener.class);
AnotherTestEvent event = new AnotherTestEvent(this, "String");
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
@@ -527,7 +527,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithGenericApplicationEvent() {
void listenerWithGenericApplicationEvent() {
load(GenericEventListener.class);
GenericEventListener listener = this.context.getBean(GenericEventListener.class);
@@ -538,7 +538,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithResolvableTypeEvent() {
void listenerWithResolvableTypeEvent() {
load(ResolvableTypeEventListener.class);
ResolvableTypeEventListener listener = this.context.getBean(ResolvableTypeEventListener.class);
@@ -550,7 +550,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void listenerWithResolvableTypeEventWrongGeneric() {
void listenerWithResolvableTypeEventWrongGeneric() {
load(ResolvableTypeEventListener.class);
ResolvableTypeEventListener listener = this.context.getBean(ResolvableTypeEventListener.class);
@@ -562,12 +562,12 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void conditionMatch() {
void conditionMatch() {
validateConditionMatch(ConditionalEventListener.class);
}
@Test
public void conditionMatchWithProxy() {
void conditionMatchWithProxy() {
validateConditionMatch(ConditionalEventListener.class, MethodValidationPostProcessor.class);
}
@@ -600,7 +600,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void conditionDoesNotMatch() {
void conditionDoesNotMatch() {
long maxLong = Long.MAX_VALUE;
load(ConditionalEventListener.class);
TestEvent event = new TestEvent(this, "KO");
@@ -625,7 +625,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void orderedListeners() {
void orderedListeners() {
load(OrderedTestListener.class);
OrderedTestListener listener = this.context.getBean(OrderedTestListener.class);
@@ -635,7 +635,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test @Disabled // SPR-15122
public void listenersReceiveEarlyEvents() {
void listenersReceiveEarlyEvents() {
load(EventOnPostConstruct.class, OrderedTestListener.class);
OrderedTestListener listener = this.context.getBean(OrderedTestListener.class);
@@ -643,7 +643,7 @@ public class AnnotationDrivenEventListenerTests {
}
@Test
public void missingListenerBeanIgnored() {
void missingListenerBeanIgnored() {
load(MissingEventListener.class);
context.getBean(UseMissingEventListener.class);
context.getBean(ApplicationEventMulticaster.class).multicastEvent(new TestEvent(this));
@@ -697,7 +697,7 @@ public class AnnotationDrivenEventListenerTests {
static class TestConditionEvaluator {
public boolean valid(Double ratio) {
return new Double(42).equals(ratio);
return Double.valueOf(42).equals(ratio);
}
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@@ -341,10 +341,10 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
assertIsRegistered("Bean instance not registered", objectName);
Object result = server.invoke(objectName, "add", new Object[] {new Integer(2), new Integer(3)}, new String[] {
Object result = server.invoke(objectName, "add", new Object[] {2, 3}, new String[] {
int.class.getName(), int.class.getName()});
assertThat(new Integer(5)).as("Incorrect result return from add").isEqualTo(result);
assertThat(Integer.valueOf(5)).as("Incorrect result return from add").isEqualTo(result);
assertThat(server.getAttribute(objectName, "Name")).as("Incorrect attribute value").isEqualTo(name);
server.setAttribute(objectName, new Attribute("Name", otherName));
@@ -352,7 +352,7 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
}
@Test
void testBonaFideMBeanIsNotExportedWhenAutodetectIsTotallyTurnedOff() throws Exception {
void testBonaFideMBeanIsNotExportedWhenAutodetectIsTotallyTurnedOff() {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
factory.registerBeanDefinition("^&_invalidObjectName_(*", builder.getBeanDefinition());

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@@ -60,7 +60,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
IJmxTestBean bean = getBean();
assertThat(bean).isNotNull();
MBeanInfo inf = getMBeanInfo();
assertThat(inf.getOperations().length).as("Incorrect number of operations registered").isEqualTo(getExpectedOperationCount());
assertThat(inf.getOperations()).as("Incorrect number of operations registered").hasSize(getExpectedOperationCount());
}
@Test
@@ -68,7 +68,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
IJmxTestBean bean = getBean();
assertThat(bean).isNotNull();
MBeanInfo inf = getMBeanInfo();
assertThat(inf.getAttributes().length).as("Incorrect number of attributes registered").isEqualTo(getExpectedAttributeCount());
assertThat(inf.getAttributes()).as("Incorrect number of attributes registered").hasSize(getExpectedAttributeCount());
}
@Test
@@ -81,7 +81,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
public void testGetMBeanAttributeInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanAttributeInfo[] inf = info.getAttributes();
assertThat(inf.length).as("Invalid number of Attributes returned").isEqualTo(getExpectedAttributeCount());
assertThat(inf).as("Invalid number of Attributes returned").hasSize(getExpectedAttributeCount());
for (int x = 0; x < inf.length; x++) {
assertThat(inf[x]).as("MBeanAttributeInfo should not be null").isNotNull();
@@ -93,7 +93,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
public void testGetMBeanOperationInfo() throws Exception {
ModelMBeanInfo info = getMBeanInfoFromAssembler();
MBeanOperationInfo[] inf = info.getOperations();
assertThat(inf.length).as("Invalid number of Operations returned").isEqualTo(getExpectedOperationCount());
assertThat(inf).as("Invalid number of Operations returned").hasSize(getExpectedOperationCount());
for (int x = 0; x < inf.length; x++) {
assertThat(inf[x]).as("MBeanOperationInfo should not be null").isNotNull();
@@ -128,8 +128,8 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
public void testOperationInvocation() throws Exception{
ObjectName objectName = ObjectNameManager.getInstance(getObjectName());
Object result = getServer().invoke(objectName, "add",
new Object[] {new Integer(20), new Integer(30)}, new String[] {"int", "int"});
assertThat(result).as("Incorrect result").isEqualTo(new Integer(50));
new Object[] {20, 30}, new String[] {"int", "int"});
assertThat(result).as("Incorrect result").isEqualTo(50);
}
@Test
@@ -150,12 +150,12 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
ModelMBeanOperationInfo get = info.getOperation("getName");
assertThat(get).as("get operation should not be null").isNotNull();
assertThat(new Integer(4)).as("get operation should have visibility of four").isEqualTo(get.getDescriptor().getFieldValue("visibility"));
assertThat(Integer.valueOf(4)).as("get operation should have visibility of four").isEqualTo(get.getDescriptor().getFieldValue("visibility"));
assertThat(get.getDescriptor().getFieldValue("role")).as("get operation should have role \"getter\"").isEqualTo("getter");
ModelMBeanOperationInfo set = info.getOperation("setName");
assertThat(set).as("set operation should not be null").isNotNull();
assertThat(new Integer(4)).as("set operation should have visibility of four").isEqualTo(set.getDescriptor().getFieldValue("visibility"));
assertThat(Integer.valueOf(4)).as("set operation should have visibility of four").isEqualTo(set.getDescriptor().getFieldValue("visibility"));
assertThat(set.getDescriptor().getFieldValue("role")).as("set operation should have role \"setter\"").isEqualTo("setter");
}
@@ -163,12 +163,12 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
public void testNotificationMetadata() throws Exception {
ModelMBeanInfo info = (ModelMBeanInfo) getMBeanInfo();
MBeanNotificationInfo[] notifications = info.getNotifications();
assertThat(notifications.length).as("Incorrect number of notifications").isEqualTo(1);
assertThat(notifications).as("Incorrect number of notifications").hasSize(1);
assertThat(notifications[0].getName()).as("Incorrect notification name").isEqualTo("My Notification");
String[] notifTypes = notifications[0].getNotifTypes();
assertThat(notifTypes.length).as("Incorrect number of notification types").isEqualTo(2);
assertThat(notifTypes).as("Incorrect number of notification types").hasSize(2);
assertThat(notifTypes[0]).as("Notification type.foo not found").isEqualTo("type.foo");
assertThat(notifTypes[1]).as("Notification type.bar not found").isEqualTo("type.bar");
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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,7 +41,7 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
* @author Chris Beams
*/
@EnabledForTestGroups(LONG_RUNNING)
public class ScriptFactoryPostProcessorTests {
class ScriptFactoryPostProcessorTests {
private static final String MESSAGE_TEXT = "Bingo";
@@ -79,18 +79,18 @@ public class ScriptFactoryPostProcessorTests {
@Test
public void testDoesNothingWhenPostProcessingNonScriptFactoryTypeBeforeInstantiation() throws Exception {
void testDoesNothingWhenPostProcessingNonScriptFactoryTypeBeforeInstantiation() {
assertThat(new ScriptFactoryPostProcessor().postProcessBeforeInstantiation(getClass(), "a.bean")).isNull();
}
@Test
public void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() throws Exception {
void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() {
assertThatIllegalStateException().isThrownBy(() ->
new ScriptFactoryPostProcessor().setBeanFactory(mock(BeanFactory.class)));
}
@Test
public void testChangeScriptWithRefreshableBeanFunctionality() throws Exception {
void testChangeScriptWithRefreshableBeanFunctionality() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
@@ -111,7 +111,7 @@ public class ScriptFactoryPostProcessorTests {
}
@Test
public void testChangeScriptWithNoRefreshableBeanFunctionality() throws Exception {
void testChangeScriptWithNoRefreshableBeanFunctionality() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(false);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
@@ -131,7 +131,7 @@ public class ScriptFactoryPostProcessorTests {
}
@Test
public void testRefreshedScriptReferencePropagatesToCollaborators() throws Exception {
void testRefreshedScriptReferencePropagatesToCollaborators() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class);
@@ -159,7 +159,7 @@ public class ScriptFactoryPostProcessorTests {
}
@Test
public void testReferencesAcrossAContainerHierarchy() throws Exception {
void testReferencesAcrossAContainerHierarchy() throws Exception {
GenericApplicationContext businessContext = new GenericApplicationContext();
businessContext.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition());
businessContext.refresh();
@@ -175,13 +175,13 @@ public class ScriptFactoryPostProcessorTests {
}
@Test
public void testScriptHavingAReferenceToAnotherBean() throws Exception {
void testScriptHavingAReferenceToAnotherBean() throws Exception {
// just tests that the (singleton) script-backed bean is able to be instantiated with references to its collaborators
new ClassPathXmlApplicationContext("org/springframework/scripting/support/groovyReferences.xml");
}
@Test
public void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception {
void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception {
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class);
@@ -202,13 +202,12 @@ public class ScriptFactoryPostProcessorTests {
// needs The Sundays compiler; must NOT throw any exception here...
source.setScript("I keep hoping you are the same as me, and I'll send you letters and come to your house for tea");
Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() ->
refreshedMessenger.getMessage())
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(refreshedMessenger::getMessage)
.matches(ex -> ex.contains(ScriptCompilationException.class));
}
@Test
public void testPrototypeScriptedBean() throws Exception {
void testPrototypeScriptedBean() throws Exception {
GenericApplicationContext ctx = new GenericApplicationContext();
ctx.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition());
@@ -236,7 +235,7 @@ public class ScriptFactoryPostProcessorTests {
private static BeanDefinition createScriptFactoryPostProcessor(boolean isRefreshable) {
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ScriptFactoryPostProcessor.class);
if (isRefreshable) {
builder.addPropertyValue("defaultRefreshCheckDelay", new Long(1));
builder.addPropertyValue("defaultRefreshCheckDelay", 1L);
}
return builder.getBeanDefinition();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2019 the original author or authors.
* Copyright 2002-2021 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.
@@ -36,17 +36,17 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* @author Stephane Nicoll
* @since 07.03.2006
*/
public class DataBinderFieldAccessTests {
class DataBinderFieldAccessTests {
@Test
public void bindingNoErrors() throws Exception {
void bindingNoErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
binder.initDirectFieldAccess();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
pvs.addPropertyValue(new PropertyValue("age", new Integer(32)));
pvs.addPropertyValue(new PropertyValue("age", 32));
pvs.addPropertyValue(new PropertyValue("nonExisting", "someValue"));
binder.bind(pvs);
@@ -62,21 +62,21 @@ public class DataBinderFieldAccessTests {
}
@Test
public void bindingNoErrorsNotIgnoreUnknown() throws Exception {
void bindingNoErrorsNotIgnoreUnknown() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
binder.initDirectFieldAccess();
binder.setIgnoreUnknownFields(false);
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
pvs.addPropertyValue(new PropertyValue("age", new Integer(32)));
pvs.addPropertyValue(new PropertyValue("age", 32));
pvs.addPropertyValue(new PropertyValue("nonExisting", "someValue"));
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() ->
binder.bind(pvs));
}
@Test
public void bindingWithErrors() throws Exception {
void bindingWithErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
binder.initDirectFieldAccess();
@@ -105,7 +105,7 @@ public class DataBinderFieldAccessTests {
}
@Test
public void nestedBindingWithDefaultConversionNoErrors() throws Exception {
void nestedBindingWithDefaultConversionNoErrors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
@@ -122,7 +122,7 @@ public class DataBinderFieldAccessTests {
}
@Test
public void nestedBindingWithDisabledAutoGrow() throws Exception {
void nestedBindingWithDisabledAutoGrow() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
binder.setAutoGrowNestedPaths(false);
@@ -135,7 +135,7 @@ public class DataBinderFieldAccessTests {
}
@Test
public void bindingWithErrorsAndCustomEditors() throws Exception {
void bindingWithErrorsAndCustomEditors() throws Exception {
FieldAccessBean rod = new FieldAccessBean();
DataBinder binder = new DataBinder(rod, "person");
binder.initDirectFieldAccess();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2020 the original author or authors.
* Copyright 2002-2021 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.
@@ -77,10 +77,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
* @author Rob Harrop
* @author Kazuki Shimizu
*/
public class DataBinderTests {
class DataBinderTests {
@Test
public void testBindingNoErrors() throws BindException {
void testBindingNoErrors() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
@@ -115,7 +115,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithDefaultConversionNoErrors() throws BindException {
void testBindingWithDefaultConversionNoErrors() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
@@ -131,7 +131,7 @@ public class DataBinderTests {
}
@Test
public void testNestedBindingWithDefaultConversionNoErrors() throws BindException {
void testNestedBindingWithDefaultConversionNoErrors() throws BindException {
TestBean rod = new TestBean(new TestBean());
DataBinder binder = new DataBinder(rod, "person");
assertThat(binder.isIgnoreUnknownFields()).isTrue();
@@ -147,7 +147,7 @@ public class DataBinderTests {
}
@Test
public void testBindingNoErrorsNotIgnoreUnknown() {
void testBindingNoErrorsNotIgnoreUnknown() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
binder.setIgnoreUnknownFields(false);
@@ -160,7 +160,7 @@ public class DataBinderTests {
}
@Test
public void testBindingNoErrorsWithInvalidField() {
void testBindingNoErrorsWithInvalidField() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@@ -171,7 +171,7 @@ public class DataBinderTests {
}
@Test
public void testBindingNoErrorsWithIgnoreInvalid() {
void testBindingNoErrorsWithIgnoreInvalid() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
binder.setIgnoreInvalidFields(true);
@@ -183,7 +183,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithErrors() {
void testBindingWithErrors() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@@ -245,7 +245,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithSystemFieldError() {
void testBindingWithSystemFieldError() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@@ -257,7 +257,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithErrorsAndCustomEditors() {
void testBindingWithErrorsAndCustomEditors() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
binder.registerCustomEditor(String.class, "touchy", new PropertyEditorSupport() {
@@ -325,7 +325,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithCustomEditorOnObjectField() {
void testBindingWithCustomEditorOnObjectField() {
BeanWithObjectProperty tb = new BeanWithObjectProperty();
DataBinder binder = new DataBinder(tb);
binder.registerCustomEditor(Integer.class, "object", new CustomNumberEditor(Integer.class, true));
@@ -336,7 +336,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithFormatter() {
void testBindingWithFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@@ -349,18 +349,18 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(1.2));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(1.2f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1,2");
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertThat(editor).isNotNull();
editor.setValue(new Float(1.4));
editor.setValue(1.4f);
assertThat(editor.getAsText()).isEqualTo("1,4");
editor = binder.getBindingResult().findEditor("myFloat", null);
assertThat(editor).isNotNull();
editor.setAsText("1,6");
assertThat(editor.getValue()).isEqualTo(new Float(1.6));
assertThat(editor.getValue()).isEqualTo(1.6f);
}
finally {
LocaleContextHolder.resetLocaleContext();
@@ -368,7 +368,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithFormatter() {
void testBindingErrorWithFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@@ -381,7 +381,7 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(0.0));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(0.0f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1x2");
assertThat(binder.getBindingResult().hasFieldErrors("myFloat")).isTrue();
}
@@ -391,7 +391,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithParseExceptionFromFormatter() {
void testBindingErrorWithParseExceptionFromFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@@ -419,7 +419,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithRuntimeExceptionFromFormatter() {
void testBindingErrorWithRuntimeExceptionFromFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@@ -447,7 +447,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithFormatterAgainstList() {
void testBindingWithFormatterAgainstList() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@@ -469,7 +469,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithFormatterAgainstList() {
void testBindingErrorWithFormatterAgainstList() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@@ -492,7 +492,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithFormatterAgainstFields() {
void testBindingWithFormatterAgainstFields() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
FormattingConversionService conversionService = new FormattingConversionService();
@@ -506,18 +506,18 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(1.2));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(1.2f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1,2");
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertThat(editor).isNotNull();
editor.setValue(new Float(1.4));
editor.setValue(1.4f);
assertThat(editor.getAsText()).isEqualTo("1,4");
editor = binder.getBindingResult().findEditor("myFloat", null);
assertThat(editor).isNotNull();
editor.setAsText("1,6");
assertThat(editor.getValue()).isEqualTo(new Float(1.6));
assertThat(editor.getValue()).isEqualTo(1.6f);
}
finally {
LocaleContextHolder.resetLocaleContext();
@@ -525,7 +525,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithFormatterAgainstFields() {
void testBindingErrorWithFormatterAgainstFields() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.initDirectFieldAccess();
@@ -539,7 +539,7 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(0.0));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(0.0f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1x2");
assertThat(binder.getBindingResult().hasFieldErrors("myFloat")).isTrue();
}
@@ -549,7 +549,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithCustomFormatter() {
void testBindingWithCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.addCustomFormatter(new NumberStyleFormatter(), Float.class);
@@ -559,12 +559,12 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(1.2));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(1.2f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1,2");
PropertyEditor editor = binder.getBindingResult().findEditor("myFloat", Float.class);
assertThat(editor).isNotNull();
editor.setValue(new Float(1.4));
editor.setValue(1.4f);
assertThat(editor.getAsText()).isEqualTo("1,4");
editor = binder.getBindingResult().findEditor("myFloat", null);
@@ -578,7 +578,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithCustomFormatter() {
void testBindingErrorWithCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
binder.addCustomFormatter(new NumberStyleFormatter());
@@ -588,7 +588,7 @@ public class DataBinderTests {
LocaleContextHolder.setLocale(Locale.GERMAN);
try {
binder.bind(pvs);
assertThat(tb.getMyFloat()).isEqualTo(new Float(0.0));
assertThat(tb.getMyFloat()).isEqualTo(Float.valueOf(0.0f));
assertThat(binder.getBindingResult().getFieldValue("myFloat")).isEqualTo("1x2");
assertThat(binder.getBindingResult().hasFieldErrors("myFloat")).isTrue();
assertThat(binder.getBindingResult().getFieldError("myFloat").getCode()).isEqualTo("typeMismatch");
@@ -599,7 +599,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithParseExceptionFromCustomFormatter() {
void testBindingErrorWithParseExceptionFromCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
@@ -624,7 +624,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrorWithRuntimeExceptionFromCustomFormatter() {
void testBindingErrorWithRuntimeExceptionFromCustomFormatter() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb);
@@ -649,7 +649,7 @@ public class DataBinderTests {
}
@Test
public void testConversionWithInappropriateStringEditor() {
void testConversionWithInappropriateStringEditor() {
DataBinder dataBinder = new DataBinder(null);
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService();
dataBinder.setConversionService(conversionService);
@@ -662,7 +662,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithAllowedFields() throws BindException {
void testBindingWithAllowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setAllowedFields("name", "myparam");
@@ -677,7 +677,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithDisallowedFields() throws BindException {
void testBindingWithDisallowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setDisallowedFields("age");
@@ -695,7 +695,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithAllowedAndDisallowedFields() throws BindException {
void testBindingWithAllowedAndDisallowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setAllowedFields("name", "myparam");
@@ -709,12 +709,12 @@ public class DataBinderTests {
assertThat(rod.getName().equals("Rod")).as("changed name correctly").isTrue();
assertThat(rod.getAge() == 0).as("did not change age").isTrue();
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(1);
assertThat(disallowedFields).hasSize(1);
assertThat(disallowedFields[0]).isEqualTo("age");
}
@Test
public void testBindingWithOverlappingAllowedAndDisallowedFields() throws BindException {
void testBindingWithOverlappingAllowedAndDisallowedFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setAllowedFields("name", "age");
@@ -728,12 +728,12 @@ public class DataBinderTests {
assertThat(rod.getName().equals("Rod")).as("changed name correctly").isTrue();
assertThat(rod.getAge() == 0).as("did not change age").isTrue();
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(1);
assertThat(disallowedFields).hasSize(1);
assertThat(disallowedFields[0]).isEqualTo("age");
}
@Test
public void testBindingWithAllowedFieldsUsingAsterisks() throws BindException {
void testBindingWithAllowedFieldsUsingAsterisks() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
binder.setAllowedFields("nam*", "*ouchy");
@@ -750,7 +750,7 @@ public class DataBinderTests {
assertThat("Rod".equals(rod.getTouchy())).as("changed touchy correctly").isTrue();
assertThat(rod.getAge() == 0).as("did not change age").isTrue();
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(1);
assertThat(disallowedFields).hasSize(1);
assertThat(disallowedFields[0]).isEqualTo("age");
Map<?,?> m = binder.getBindingResult().getModel();
@@ -760,7 +760,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithAllowedAndDisallowedMapFields() throws BindException {
void testBindingWithAllowedAndDisallowedMapFields() throws BindException {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod);
binder.setAllowedFields("someMap[key1]", "someMap[key2]");
@@ -779,7 +779,7 @@ public class DataBinderTests {
assertThat(rod.getSomeMap().get("key3")).isNull();
assertThat(rod.getSomeMap().get("key4")).isNull();
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(2);
assertThat(disallowedFields).hasSize(2);
assertThat(ObjectUtils.containsElement(disallowedFields, "someMap[key3]")).isTrue();
assertThat(ObjectUtils.containsElement(disallowedFields, "someMap[key4]")).isTrue();
}
@@ -788,7 +788,7 @@ public class DataBinderTests {
* Tests for required field, both null, non-existing and empty strings.
*/
@Test
public void testBindingWithRequiredFields() {
void testBindingWithRequiredFields() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
@@ -819,7 +819,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithRequiredMapFields() {
void testBindingWithRequiredMapFields() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
@@ -839,7 +839,7 @@ public class DataBinderTests {
}
@Test
public void testBindingWithNestedObjectCreation() {
void testBindingWithNestedObjectCreation() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "person");
@@ -860,7 +860,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorWithOldValueAccess() {
void testCustomEditorWithOldValueAccess() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@@ -885,7 +885,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorForSingleProperty() {
void testCustomEditorForSingleProperty() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
DataBinder binder = new DataBinder(tb, "tb");
@@ -925,7 +925,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorForPrimitiveProperty() {
void testCustomEditorForPrimitiveProperty() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@@ -949,7 +949,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorForAllStringProperties() {
void testCustomEditorForAllStringProperties() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@@ -981,7 +981,7 @@ public class DataBinderTests {
}
@Test
public void testCustomFormatterForSingleProperty() {
void testCustomFormatterForSingleProperty() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
DataBinder binder = new DataBinder(tb, "tb");
@@ -1021,7 +1021,7 @@ public class DataBinderTests {
}
@Test
public void testCustomFormatterForPrimitiveProperty() {
void testCustomFormatterForPrimitiveProperty() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@@ -1045,7 +1045,7 @@ public class DataBinderTests {
}
@Test
public void testCustomFormatterForAllStringProperties() {
void testCustomFormatterForAllStringProperties() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
@@ -1077,7 +1077,7 @@ public class DataBinderTests {
}
@Test
public void testJavaBeanPropertyConventions() {
void testJavaBeanPropertyConventions() {
Book book = new Book();
DataBinder binder = new DataBinder(book);
@@ -1101,7 +1101,7 @@ public class DataBinderTests {
}
@Test
public void testOptionalProperty() {
void testOptionalProperty() {
OptionalHolder bean = new OptionalHolder();
DataBinder binder = new DataBinder(bean);
binder.setConversionService(new DefaultConversionService());
@@ -1111,7 +1111,7 @@ public class DataBinderTests {
pvs.add("name", null);
binder.bind(pvs);
assertThat(bean.getId()).isEqualTo("1");
assertThat(bean.getName().isPresent()).isFalse();
assertThat(bean.getName()).isEmpty();
pvs = new MutablePropertyValues();
pvs.add("id", "2");
@@ -1122,7 +1122,7 @@ public class DataBinderTests {
}
@Test
public void testValidatorNoErrors() throws Exception {
void testValidatorNoErrors() throws Exception {
TestBean tb = new TestBean();
tb.setAge(33);
tb.setName("Rod");
@@ -1183,7 +1183,7 @@ public class DataBinderTests {
}
@Test
public void testValidatorWithErrors() {
void testValidatorWithErrors() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
@@ -1252,7 +1252,7 @@ public class DataBinderTests {
}
@Test
public void testValidatorWithErrorsAndCodesPrefix() {
void testValidatorWithErrorsAndCodesPrefix() {
TestBean tb = new TestBean();
tb.setSpouse(new TestBean());
@@ -1324,7 +1324,7 @@ public class DataBinderTests {
}
@Test
public void testValidatorWithNestedObjectNull() {
void testValidatorWithNestedObjectNull() {
TestBean tb = new TestBean();
Errors errors = new BeanPropertyBindingResult(tb, "tb");
Validator testValidator = new TestBeanValidator();
@@ -1343,7 +1343,7 @@ public class DataBinderTests {
}
@Test
public void testNestedValidatorWithoutNestedPath() {
void testNestedValidatorWithoutNestedPath() {
TestBean tb = new TestBean();
tb.setName("XXX");
Errors errors = new BeanPropertyBindingResult(tb, "tb");
@@ -1357,13 +1357,13 @@ public class DataBinderTests {
}
@Test
public void testBindingStringArrayToIntegerSet() {
void testBindingStringArrayToIntegerSet() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(Set.class, new CustomCollectionEditor(TreeSet.class) {
@Override
protected Object convertElement(Object element) {
return new Integer(element.toString());
return Integer.valueOf(element.toString());
}
});
MutablePropertyValues pvs = new MutablePropertyValues();
@@ -1386,7 +1386,7 @@ public class DataBinderTests {
}
@Test
public void testBindingNullToEmptyCollection() {
void testBindingNullToEmptyCollection() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(Set.class, new CustomCollectionEditor(TreeSet.class, true));
@@ -1400,7 +1400,7 @@ public class DataBinderTests {
}
@Test
public void testBindingToIndexedField() {
void testBindingToIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(String.class, "array.name", new PropertyEditorSupport() {
@@ -1439,7 +1439,7 @@ public class DataBinderTests {
}
@Test
public void testBindingToNestedIndexedField() {
void testBindingToNestedIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
@@ -1470,7 +1470,7 @@ public class DataBinderTests {
}
@Test
public void testEditorForNestedIndexedField() {
void testEditorForNestedIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
@@ -1496,7 +1496,7 @@ public class DataBinderTests {
}
@Test
public void testSpecificEditorForNestedIndexedField() {
void testSpecificEditorForNestedIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
@@ -1522,7 +1522,7 @@ public class DataBinderTests {
}
@Test
public void testInnerSpecificEditorForNestedIndexedField() {
void testInnerSpecificEditorForNestedIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean());
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean());
@@ -1548,7 +1548,7 @@ public class DataBinderTests {
}
@Test
public void testDirectBindingToIndexedField() {
void testDirectBindingToIndexedField() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() {
@@ -1601,7 +1601,7 @@ public class DataBinderTests {
}
@Test
public void testDirectBindingToEmptyIndexedFieldWithRegisteredSpecificEditor() {
void testDirectBindingToEmptyIndexedFieldWithRegisteredSpecificEditor() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(TestBean.class, "map[key0]", new PropertyEditorSupport() {
@@ -1632,7 +1632,7 @@ public class DataBinderTests {
}
@Test
public void testDirectBindingToEmptyIndexedFieldWithRegisteredGenericEditor() {
void testDirectBindingToEmptyIndexedFieldWithRegisteredGenericEditor() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() {
@@ -1663,7 +1663,7 @@ public class DataBinderTests {
}
@Test
public void testCustomEditorWithSubclass() {
void testCustomEditorWithSubclass() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
@@ -1697,7 +1697,7 @@ public class DataBinderTests {
}
@Test
public void testBindToStringArrayWithArrayEditor() {
void testBindToStringArrayWithArrayEditor() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(String[].class, "stringArray", new PropertyEditorSupport() {
@@ -1717,7 +1717,7 @@ public class DataBinderTests {
}
@Test
public void testBindToStringArrayWithComponentEditor() {
void testBindToStringArrayWithComponentEditor() {
TestBean tb = new TestBean();
DataBinder binder = new DataBinder(tb, "tb");
binder.registerCustomEditor(String.class, "stringArray", new PropertyEditorSupport() {
@@ -1737,7 +1737,7 @@ public class DataBinderTests {
}
@Test
public void testBindingErrors() {
void testBindingErrors() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@@ -1764,7 +1764,7 @@ public class DataBinderTests {
}
@Test
public void testAddAllErrors() {
void testAddAllErrors() {
TestBean rod = new TestBean();
DataBinder binder = new DataBinder(rod, "person");
MutablePropertyValues pvs = new MutablePropertyValues();
@@ -1784,7 +1784,7 @@ public class DataBinderTests {
@Test
@SuppressWarnings("unchecked")
public void testBindingWithResortedList() {
void testBindingWithResortedList() {
IndexedTestBean tb = new IndexedTestBean();
DataBinder binder = new DataBinder(tb, "tb");
MutablePropertyValues pvs = new MutablePropertyValues();
@@ -1802,7 +1802,7 @@ public class DataBinderTests {
}
@Test
public void testRejectWithoutDefaultMessage() {
void testRejectWithoutDefaultMessage() {
TestBean tb = new TestBean();
tb.setName("myName");
tb.setAge(99);
@@ -1820,7 +1820,7 @@ public class DataBinderTests {
}
@Test
public void testBindExceptionSerializable() throws Exception {
void testBindExceptionSerializable() throws Exception {
SerializablePerson tb = new SerializablePerson();
tb.setName("myName");
tb.setAge(99);
@@ -1849,7 +1849,7 @@ public class DataBinderTests {
}
@Test
public void testTrackDisallowedFields() {
void testTrackDisallowedFields() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.setAllowedFields("name", "age");
@@ -1864,12 +1864,12 @@ public class DataBinderTests {
assertThat(testBean.getName()).isEqualTo(name);
String[] disallowedFields = binder.getBindingResult().getSuppressedFields();
assertThat(disallowedFields.length).isEqualTo(1);
assertThat(disallowedFields).hasSize(1);
assertThat(disallowedFields[0]).isEqualTo("beanName");
}
@Test
public void testAutoGrowWithinDefaultLimit() {
void testAutoGrowWithinDefaultLimit() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
@@ -1877,11 +1877,11 @@ public class DataBinderTests {
mpvs.add("friends[4]", "");
binder.bind(mpvs);
assertThat(testBean.getFriends().size()).isEqualTo(5);
assertThat(testBean.getFriends()).hasSize(5);
}
@Test
public void testAutoGrowBeyondDefaultLimit() {
void testAutoGrowBeyondDefaultLimit() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
@@ -1894,7 +1894,7 @@ public class DataBinderTests {
}
@Test
public void testAutoGrowWithinCustomLimit() {
void testAutoGrowWithinCustomLimit() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.setAutoGrowCollectionLimit(10);
@@ -1903,11 +1903,11 @@ public class DataBinderTests {
mpvs.add("friends[4]", "");
binder.bind(mpvs);
assertThat(testBean.getFriends().size()).isEqualTo(5);
assertThat(testBean.getFriends()).hasSize(5);
}
@Test
public void testAutoGrowBeyondCustomLimit() {
void testAutoGrowBeyondCustomLimit() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.setAutoGrowCollectionLimit(10);
@@ -1921,7 +1921,7 @@ public class DataBinderTests {
}
@Test
public void testNestedGrowingList() {
void testNestedGrowingList() {
Form form = new Form();
DataBinder binder = new DataBinder(form, "form");
MutablePropertyValues mpv = new MutablePropertyValues();
@@ -1937,7 +1937,7 @@ public class DataBinderTests {
}
@Test
public void testFieldErrorAccessVariations() {
void testFieldErrorAccessVariations() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
assertThat(binder.getBindingResult().getGlobalError()).isNull();
@@ -1958,7 +1958,7 @@ public class DataBinderTests {
}
@Test // SPR-14888
public void testSetAutoGrowCollectionLimit() {
void testSetAutoGrowCollectionLimit() {
BeanWithIntegerList tb = new BeanWithIntegerList();
DataBinder binder = new DataBinder(tb);
binder.setAutoGrowCollectionLimit(257);
@@ -1968,11 +1968,11 @@ public class DataBinderTests {
binder.bind(pvs);
assertThat(tb.getIntegerList().size()).isEqualTo(257);
assertThat(tb.getIntegerList().get(256)).isEqualTo(Integer.valueOf(1));
assertThat(binder.getBindingResult().getFieldValue("integerList[256]")).isEqualTo(Integer.valueOf(1));
assertThat(binder.getBindingResult().getFieldValue("integerList[256]")).isEqualTo(1);
}
@Test // SPR-14888
public void testSetAutoGrowCollectionLimitAfterInitialization() {
void testSetAutoGrowCollectionLimitAfterInitialization() {
DataBinder binder = new DataBinder(new BeanWithIntegerList());
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true));
assertThatIllegalStateException().isThrownBy(() ->
@@ -1981,7 +1981,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() {
void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
DefaultMessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver();
@@ -1998,7 +1998,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForDirectFieldAccess() {
void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForDirectFieldAccess() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
DefaultMessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver();
@@ -2013,7 +2013,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testSetCustomMessageCodesResolverAfterInitializeBindingResult() {
void testSetCustomMessageCodesResolverAfterInitializeBindingResult() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.initBeanPropertyAccess();
@@ -2028,7 +2028,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testSetMessageCodesResolverIsNullAfterInitializeBindingResult() {
void testSetMessageCodesResolverIsNullAfterInitializeBindingResult() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.initBeanPropertyAccess();
@@ -2042,7 +2042,7 @@ public class DataBinderTests {
}
@Test // SPR-15009
public void testCallSetMessageCodesResolverTwice() {
void testCallSetMessageCodesResolverTwice() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
@@ -2053,7 +2053,7 @@ public class DataBinderTests {
}
@Test // gh-24347
public void overrideBindingResultType() {
void overrideBindingResultType() {
TestBean testBean = new TestBean();
DataBinder binder = new DataBinder(testBean, "testBean");
binder.initDirectFieldAccess();