|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2020 the original author or authors. |
|
|
|
* Copyright 2002-2022 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -64,23 +64,26 @@ import org.springframework.format.support.DefaultFormattingConversionService; |
|
|
|
import org.springframework.format.support.FormattingConversionService; |
|
|
|
import org.springframework.format.support.FormattingConversionService; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.lang.Nullable; |
|
|
|
import org.springframework.tests.sample.beans.BeanWithObjectProperty; |
|
|
|
import org.springframework.tests.sample.beans.BeanWithObjectProperty; |
|
|
|
import org.springframework.util.ObjectUtils; |
|
|
|
|
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
import org.springframework.util.StringUtils; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.entry; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
|
|
|
|
* Unit tests for {@link DataBinder}. |
|
|
|
|
|
|
|
* |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Rod Johnson |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Juergen Hoeller |
|
|
|
* @author Rob Harrop |
|
|
|
* @author Rob Harrop |
|
|
|
* @author Kazuki Shimizu |
|
|
|
* @author Kazuki Shimizu |
|
|
|
|
|
|
|
* @author Sam Brannen |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class DataBinderTests { |
|
|
|
class DataBinderTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingNoErrors() throws BindException { |
|
|
|
void bindingNoErrors() throws BindException { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
assertThat(binder.isIgnoreUnknownFields()).isTrue(); |
|
|
|
assertThat(binder.isIgnoreUnknownFields()).isTrue(); |
|
|
|
@ -110,12 +113,11 @@ public class DataBinderTests { |
|
|
|
assertThat(ex).isEqualTo(binder.getBindingResult()); |
|
|
|
assertThat(ex).isEqualTo(binder.getBindingResult()); |
|
|
|
|
|
|
|
|
|
|
|
other.reject("xxx"); |
|
|
|
other.reject("xxx"); |
|
|
|
boolean condition = !other.equals(binder.getBindingResult()); |
|
|
|
assertThat(other).isNotEqualTo(binder.getBindingResult()); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithDefaultConversionNoErrors() throws BindException { |
|
|
|
void bindingWithDefaultConversionNoErrors() throws BindException { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
assertThat(binder.isIgnoreUnknownFields()).isTrue(); |
|
|
|
assertThat(binder.isIgnoreUnknownFields()).isTrue(); |
|
|
|
@ -131,7 +133,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNestedBindingWithDefaultConversionNoErrors() throws BindException { |
|
|
|
void nestedBindingWithDefaultConversionNoErrors() throws BindException { |
|
|
|
TestBean rod = new TestBean(new TestBean()); |
|
|
|
TestBean rod = new TestBean(new TestBean()); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
assertThat(binder.isIgnoreUnknownFields()).isTrue(); |
|
|
|
assertThat(binder.isIgnoreUnknownFields()).isTrue(); |
|
|
|
@ -147,7 +149,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingNoErrorsNotIgnoreUnknown() { |
|
|
|
void bindingNoErrorsNotIgnoreUnknown() { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
binder.setIgnoreUnknownFields(false); |
|
|
|
binder.setIgnoreUnknownFields(false); |
|
|
|
@ -160,7 +162,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingNoErrorsWithInvalidField() { |
|
|
|
void bindingNoErrorsWithInvalidField() { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
@ -171,7 +173,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingNoErrorsWithIgnoreInvalid() { |
|
|
|
void bindingNoErrorsWithIgnoreInvalid() throws BindException { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
binder.setIgnoreInvalidFields(true); |
|
|
|
binder.setIgnoreInvalidFields(true); |
|
|
|
@ -180,10 +182,14 @@ public class DataBinderTests { |
|
|
|
pvs.add("spouse.age", 32); |
|
|
|
pvs.add("spouse.age", 32); |
|
|
|
|
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
|
|
|
|
binder.close(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
assertThat(rod.getName()).isEqualTo("Rod"); |
|
|
|
|
|
|
|
assertThat(rod.getSpouse()).isNull(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithErrors() { |
|
|
|
void bindingWithErrors() { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
@ -245,7 +251,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithSystemFieldError() { |
|
|
|
void bindingWithSystemFieldError() { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
@ -257,7 +263,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithErrorsAndCustomEditors() { |
|
|
|
void bindingWithErrorsAndCustomEditors() { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
binder.registerCustomEditor(String.class, "touchy", new PropertyEditorSupport() { |
|
|
|
binder.registerCustomEditor(String.class, "touchy", new PropertyEditorSupport() { |
|
|
|
@ -325,7 +331,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithCustomEditorOnObjectField() { |
|
|
|
void bindingWithCustomEditorOnObjectField() { |
|
|
|
BeanWithObjectProperty tb = new BeanWithObjectProperty(); |
|
|
|
BeanWithObjectProperty tb = new BeanWithObjectProperty(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
binder.registerCustomEditor(Integer.class, "object", new CustomNumberEditor(Integer.class, true)); |
|
|
|
binder.registerCustomEditor(Integer.class, "object", new CustomNumberEditor(Integer.class, true)); |
|
|
|
@ -336,7 +342,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithFormatter() { |
|
|
|
void bindingWithFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
@ -368,7 +374,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingErrorWithFormatter() { |
|
|
|
void bindingErrorWithFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
@ -391,7 +397,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingErrorWithParseExceptionFromFormatter() { |
|
|
|
void bindingErrorWithParseExceptionFromFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
@ -419,7 +425,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingErrorWithRuntimeExceptionFromFormatter() { |
|
|
|
void bindingErrorWithRuntimeExceptionFromFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
@ -447,7 +453,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithFormatterAgainstList() { |
|
|
|
void bindingWithFormatterAgainstList() { |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
@ -469,7 +475,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingErrorWithFormatterAgainstList() { |
|
|
|
void bindingErrorWithFormatterAgainstList() { |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
@ -492,7 +498,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithFormatterAgainstFields() { |
|
|
|
void bindingWithFormatterAgainstFields() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
FormattingConversionService conversionService = new FormattingConversionService(); |
|
|
|
@ -525,7 +531,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingErrorWithFormatterAgainstFields() { |
|
|
|
void bindingErrorWithFormatterAgainstFields() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
binder.initDirectFieldAccess(); |
|
|
|
binder.initDirectFieldAccess(); |
|
|
|
@ -549,7 +555,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithCustomFormatter() { |
|
|
|
void bindingWithCustomFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
binder.addCustomFormatter(new NumberStyleFormatter(), Float.class); |
|
|
|
binder.addCustomFormatter(new NumberStyleFormatter(), Float.class); |
|
|
|
@ -578,7 +584,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingErrorWithCustomFormatter() { |
|
|
|
void bindingErrorWithCustomFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
binder.addCustomFormatter(new NumberStyleFormatter()); |
|
|
|
binder.addCustomFormatter(new NumberStyleFormatter()); |
|
|
|
@ -599,7 +605,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingErrorWithParseExceptionFromCustomFormatter() { |
|
|
|
void bindingErrorWithParseExceptionFromCustomFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
|
|
|
|
|
|
|
|
@ -624,7 +630,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingErrorWithRuntimeExceptionFromCustomFormatter() { |
|
|
|
void bindingErrorWithRuntimeExceptionFromCustomFormatter() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
|
|
|
|
|
|
|
|
@ -649,7 +655,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testConversionWithInappropriateStringEditor() { |
|
|
|
void conversionWithInappropriateStringEditor() { |
|
|
|
DataBinder dataBinder = new DataBinder(null); |
|
|
|
DataBinder dataBinder = new DataBinder(null); |
|
|
|
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(); |
|
|
|
DefaultFormattingConversionService conversionService = new DefaultFormattingConversionService(); |
|
|
|
dataBinder.setConversionService(conversionService); |
|
|
|
dataBinder.setConversionService(conversionService); |
|
|
|
@ -662,7 +668,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithAllowedFields() throws BindException { |
|
|
|
void bindingWithAllowedFields() throws BindException { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
binder.setAllowedFields("name", "myparam"); |
|
|
|
binder.setAllowedFields("name", "myparam"); |
|
|
|
@ -672,30 +678,32 @@ public class DataBinderTests { |
|
|
|
|
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.close(); |
|
|
|
binder.close(); |
|
|
|
assertThat(rod.getName().equals("Rod")).as("changed name correctly").isTrue(); |
|
|
|
|
|
|
|
assertThat(rod.getAge() == 0).as("did not change age").isTrue(); |
|
|
|
assertThat(rod.getName()).as("changed name correctly").isEqualTo("Rod"); |
|
|
|
|
|
|
|
assertThat(rod.getAge()).as("did not change age").isZero(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithDisallowedFields() throws BindException { |
|
|
|
void bindingWithDisallowedFields() throws BindException { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
binder.setDisallowedFields("age"); |
|
|
|
binder.setDisallowedFields(" ", "\t", "favouriteColour", null, "age"); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
pvs.add("name", "Rod"); |
|
|
|
pvs.add("name", "Rod"); |
|
|
|
pvs.add("age", "32x"); |
|
|
|
pvs.add("age", "32x"); |
|
|
|
|
|
|
|
pvs.add("favouriteColour", "BLUE"); |
|
|
|
|
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.close(); |
|
|
|
binder.close(); |
|
|
|
assertThat(rod.getName().equals("Rod")).as("changed name correctly").isTrue(); |
|
|
|
|
|
|
|
assertThat(rod.getAge() == 0).as("did not change age").isTrue(); |
|
|
|
assertThat(rod.getName()).as("changed name correctly").isEqualTo("Rod"); |
|
|
|
String[] disallowedFields = binder.getBindingResult().getSuppressedFields(); |
|
|
|
assertThat(rod.getAge()).as("did not change age").isZero(); |
|
|
|
assertThat(disallowedFields.length).isEqualTo(1); |
|
|
|
assertThat(rod.getFavouriteColour()).as("did not change favourite colour").isNull(); |
|
|
|
assertThat(disallowedFields[0]).isEqualTo("age"); |
|
|
|
assertThat(binder.getBindingResult().getSuppressedFields()).containsExactlyInAnyOrder("age", "favouriteColour"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithAllowedAndDisallowedFields() throws BindException { |
|
|
|
void bindingWithAllowedAndDisallowedFields() throws BindException { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
binder.setAllowedFields("name", "myparam"); |
|
|
|
binder.setAllowedFields("name", "myparam"); |
|
|
|
@ -706,34 +714,32 @@ public class DataBinderTests { |
|
|
|
|
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.close(); |
|
|
|
binder.close(); |
|
|
|
assertThat(rod.getName().equals("Rod")).as("changed name correctly").isTrue(); |
|
|
|
|
|
|
|
assertThat(rod.getAge() == 0).as("did not change age").isTrue(); |
|
|
|
assertThat(rod.getName()).as("changed name correctly").isEqualTo("Rod"); |
|
|
|
String[] disallowedFields = binder.getBindingResult().getSuppressedFields(); |
|
|
|
assertThat(rod.getAge()).as("did not change age").isZero(); |
|
|
|
assertThat(disallowedFields.length).isEqualTo(1); |
|
|
|
assertThat(binder.getBindingResult().getSuppressedFields()).containsExactly("age"); |
|
|
|
assertThat(disallowedFields[0]).isEqualTo("age"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithOverlappingAllowedAndDisallowedFields() throws BindException { |
|
|
|
void bindingWithOverlappingAllowedAndDisallowedFields() throws BindException { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
binder.setAllowedFields("name", "age"); |
|
|
|
binder.setAllowedFields("name", "age"); |
|
|
|
binder.setDisallowedFields("age"); |
|
|
|
binder.setDisallowedFields("AGE"); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
pvs.add("name", "Rod"); |
|
|
|
pvs.add("name", "Rod"); |
|
|
|
pvs.add("age", "32x"); |
|
|
|
pvs.add("age", "32x"); |
|
|
|
|
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.close(); |
|
|
|
binder.close(); |
|
|
|
assertThat(rod.getName().equals("Rod")).as("changed name correctly").isTrue(); |
|
|
|
|
|
|
|
assertThat(rod.getAge() == 0).as("did not change age").isTrue(); |
|
|
|
assertThat(rod.getName()).as("changed name correctly").isEqualTo("Rod"); |
|
|
|
String[] disallowedFields = binder.getBindingResult().getSuppressedFields(); |
|
|
|
assertThat(rod.getAge()).as("did not change age").isZero(); |
|
|
|
assertThat(disallowedFields.length).isEqualTo(1); |
|
|
|
assertThat(binder.getBindingResult().getSuppressedFields()).containsExactly("age"); |
|
|
|
assertThat(disallowedFields[0]).isEqualTo("age"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithAllowedFieldsUsingAsterisks() throws BindException { |
|
|
|
void bindingWithAllowedFieldsUsingAsterisks() throws BindException { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
binder.setAllowedFields("nam*", "*ouchy"); |
|
|
|
binder.setAllowedFields("nam*", "*ouchy"); |
|
|
|
@ -760,11 +766,11 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithAllowedAndDisallowedMapFields() throws BindException { |
|
|
|
void bindingWithAllowedAndDisallowedMapFields() throws BindException { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
DataBinder binder = new DataBinder(rod); |
|
|
|
binder.setAllowedFields("someMap[key1]", "someMap[key2]"); |
|
|
|
binder.setAllowedFields("someMap[key1]", "someMap[key2]"); |
|
|
|
binder.setDisallowedFields("someMap['key3']", "someMap[key4]"); |
|
|
|
binder.setDisallowedFields("someMap['KEY3']", "SomeMap[key4]"); |
|
|
|
|
|
|
|
|
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
pvs.add("someMap[key1]", "value1"); |
|
|
|
pvs.add("someMap[key1]", "value1"); |
|
|
|
@ -774,21 +780,18 @@ public class DataBinderTests { |
|
|
|
|
|
|
|
|
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.close(); |
|
|
|
binder.close(); |
|
|
|
assertThat(rod.getSomeMap().get("key1")).isEqualTo("value1"); |
|
|
|
|
|
|
|
assertThat(rod.getSomeMap().get("key2")).isEqualTo("value2"); |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
assertThat(rod.getSomeMap().get("key3")).isNull(); |
|
|
|
Map<String, String> someMap = (Map<String, String>) rod.getSomeMap(); |
|
|
|
assertThat(rod.getSomeMap().get("key4")).isNull(); |
|
|
|
assertThat(someMap).containsOnly(entry("key1", "value1"), entry("key2", "value2")); |
|
|
|
String[] disallowedFields = binder.getBindingResult().getSuppressedFields(); |
|
|
|
assertThat(binder.getBindingResult().getSuppressedFields()).containsExactly("someMap[key3]", "someMap[key4]"); |
|
|
|
assertThat(disallowedFields.length).isEqualTo(2); |
|
|
|
|
|
|
|
assertThat(ObjectUtils.containsElement(disallowedFields, "someMap[key3]")).isTrue(); |
|
|
|
|
|
|
|
assertThat(ObjectUtils.containsElement(disallowedFields, "someMap[key4]")).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Tests for required field, both null, non-existing and empty strings. |
|
|
|
* Tests for required field, both null, non-existing and empty strings. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithRequiredFields() { |
|
|
|
void bindingWithRequiredFields() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
|
|
|
|
|
|
|
|
@ -819,7 +822,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithRequiredMapFields() { |
|
|
|
void bindingWithRequiredMapFields() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
|
|
|
|
|
|
|
|
@ -839,7 +842,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingWithNestedObjectCreation() { |
|
|
|
void bindingWithNestedObjectCreation() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
|
|
|
|
|
|
|
|
DataBinder binder = new DataBinder(tb, "person"); |
|
|
|
DataBinder binder = new DataBinder(tb, "person"); |
|
|
|
@ -860,7 +863,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCustomEditorWithOldValueAccess() { |
|
|
|
void customEditorWithOldValueAccess() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
|
|
|
|
|
|
|
|
@ -885,7 +888,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCustomEditorForSingleProperty() { |
|
|
|
void customEditorForSingleProperty() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
@ -925,7 +928,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCustomEditorForPrimitiveProperty() { |
|
|
|
void customEditorForPrimitiveProperty() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
|
|
|
|
|
|
|
|
@ -949,7 +952,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCustomEditorForAllStringProperties() { |
|
|
|
void customEditorForAllStringProperties() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
|
|
|
|
|
|
|
|
@ -981,7 +984,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCustomFormatterForSingleProperty() { |
|
|
|
void customFormatterForSingleProperty() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
@ -1021,7 +1024,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCustomFormatterForPrimitiveProperty() { |
|
|
|
void customFormatterForPrimitiveProperty() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
|
|
|
|
|
|
|
|
@ -1045,7 +1048,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCustomFormatterForAllStringProperties() { |
|
|
|
void customFormatterForAllStringProperties() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
|
|
|
|
|
|
|
|
@ -1077,7 +1080,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testJavaBeanPropertyConventions() { |
|
|
|
void javaBeanPropertyConventions() { |
|
|
|
Book book = new Book(); |
|
|
|
Book book = new Book(); |
|
|
|
DataBinder binder = new DataBinder(book); |
|
|
|
DataBinder binder = new DataBinder(book); |
|
|
|
|
|
|
|
|
|
|
|
@ -1101,7 +1104,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testOptionalProperty() { |
|
|
|
void optionalProperty() { |
|
|
|
OptionalHolder bean = new OptionalHolder(); |
|
|
|
OptionalHolder bean = new OptionalHolder(); |
|
|
|
DataBinder binder = new DataBinder(bean); |
|
|
|
DataBinder binder = new DataBinder(bean); |
|
|
|
binder.setConversionService(new DefaultConversionService()); |
|
|
|
binder.setConversionService(new DefaultConversionService()); |
|
|
|
@ -1122,7 +1125,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testValidatorNoErrors() throws Exception { |
|
|
|
void validatorNoErrors() throws Exception { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setAge(33); |
|
|
|
tb.setAge(33); |
|
|
|
tb.setName("Rod"); |
|
|
|
tb.setName("Rod"); |
|
|
|
@ -1175,15 +1178,13 @@ public class DataBinderTests { |
|
|
|
assertThat(errors.getNestedPath()).isEqualTo("spouse."); |
|
|
|
assertThat(errors.getNestedPath()).isEqualTo("spouse."); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(errors.getErrorCount()).isEqualTo(1); |
|
|
|
assertThat(errors.getErrorCount()).isEqualTo(1); |
|
|
|
boolean condition1 = !errors.hasGlobalErrors(); |
|
|
|
assertThat(errors.hasGlobalErrors()).isFalse(); |
|
|
|
assertThat(condition1).isTrue(); |
|
|
|
|
|
|
|
assertThat(errors.getFieldErrorCount("age")).isEqualTo(1); |
|
|
|
assertThat(errors.getFieldErrorCount("age")).isEqualTo(1); |
|
|
|
boolean condition = !errors.hasFieldErrors("name"); |
|
|
|
assertThat(errors.hasFieldErrors("name")).isFalse(); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testValidatorWithErrors() { |
|
|
|
void validatorWithErrors() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
|
|
|
|
|
|
|
|
@ -1252,7 +1253,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testValidatorWithErrorsAndCodesPrefix() { |
|
|
|
void validatorWithErrorsAndCodesPrefix() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
tb.setSpouse(new TestBean()); |
|
|
|
|
|
|
|
|
|
|
|
@ -1324,7 +1325,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testValidatorWithNestedObjectNull() { |
|
|
|
void validatorWithNestedObjectNull() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
Errors errors = new BeanPropertyBindingResult(tb, "tb"); |
|
|
|
Errors errors = new BeanPropertyBindingResult(tb, "tb"); |
|
|
|
Validator testValidator = new TestBeanValidator(); |
|
|
|
Validator testValidator = new TestBeanValidator(); |
|
|
|
@ -1343,7 +1344,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNestedValidatorWithoutNestedPath() { |
|
|
|
void nestedValidatorWithoutNestedPath() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setName("XXX"); |
|
|
|
tb.setName("XXX"); |
|
|
|
Errors errors = new BeanPropertyBindingResult(tb, "tb"); |
|
|
|
Errors errors = new BeanPropertyBindingResult(tb, "tb"); |
|
|
|
@ -1357,7 +1358,8 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingStringArrayToIntegerSet() { |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
|
|
|
|
void bindingStringArrayToIntegerSet() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
binder.registerCustomEditor(Set.class, new CustomCollectionEditor(TreeSet.class) { |
|
|
|
binder.registerCustomEditor(Set.class, new CustomCollectionEditor(TreeSet.class) { |
|
|
|
@ -1371,12 +1373,8 @@ public class DataBinderTests { |
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(binder.getBindingResult().getFieldValue("set")).isEqualTo(tb.getSet()); |
|
|
|
assertThat(binder.getBindingResult().getFieldValue("set")).isEqualTo(tb.getSet()); |
|
|
|
boolean condition = tb.getSet() instanceof TreeSet; |
|
|
|
assertThat(tb.getSet()).isInstanceOf(TreeSet.class); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
assertThat((Set<Integer>) tb.getSet()).containsExactly(10, 20, 30); |
|
|
|
assertThat(tb.getSet().size()).isEqualTo(3); |
|
|
|
|
|
|
|
assertThat(tb.getSet().contains(10)).isTrue(); |
|
|
|
|
|
|
|
assertThat(tb.getSet().contains(20)).isTrue(); |
|
|
|
|
|
|
|
assertThat(tb.getSet().contains(30)).isTrue(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
pvs = new MutablePropertyValues(); |
|
|
|
pvs = new MutablePropertyValues(); |
|
|
|
pvs.add("set", null); |
|
|
|
pvs.add("set", null); |
|
|
|
@ -1386,7 +1384,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingNullToEmptyCollection() { |
|
|
|
void bindingNullToEmptyCollection() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
binder.registerCustomEditor(Set.class, new CustomCollectionEditor(TreeSet.class, true)); |
|
|
|
binder.registerCustomEditor(Set.class, new CustomCollectionEditor(TreeSet.class, true)); |
|
|
|
@ -1394,13 +1392,12 @@ public class DataBinderTests { |
|
|
|
pvs.add("set", null); |
|
|
|
pvs.add("set", null); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
|
|
|
|
|
|
|
|
boolean condition = tb.getSet() instanceof TreeSet; |
|
|
|
assertThat(tb.getSet()).isInstanceOf(TreeSet.class); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
assertThat(tb.getSet()).isEmpty(); |
|
|
|
assertThat(tb.getSet().isEmpty()).isTrue(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingToIndexedField() { |
|
|
|
void bindingToIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
binder.registerCustomEditor(String.class, "array.name", new PropertyEditorSupport() { |
|
|
|
binder.registerCustomEditor(String.class, "array.name", new PropertyEditorSupport() { |
|
|
|
@ -1439,7 +1436,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingToNestedIndexedField() { |
|
|
|
void bindingToNestedIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
@ -1470,7 +1467,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testEditorForNestedIndexedField() { |
|
|
|
void editorForNestedIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
@ -1496,7 +1493,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSpecificEditorForNestedIndexedField() { |
|
|
|
void specificEditorForNestedIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
@ -1522,7 +1519,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInnerSpecificEditorForNestedIndexedField() { |
|
|
|
void innerSpecificEditorForNestedIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[0].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
tb.getArray()[1].setNestedIndexedBean(new IndexedTestBean()); |
|
|
|
@ -1548,7 +1545,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDirectBindingToIndexedField() { |
|
|
|
void directBindingToIndexedField() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
binder.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() { |
|
|
|
binder.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() { |
|
|
|
@ -1601,7 +1598,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDirectBindingToEmptyIndexedFieldWithRegisteredSpecificEditor() { |
|
|
|
void directBindingToEmptyIndexedFieldWithRegisteredSpecificEditor() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
binder.registerCustomEditor(TestBean.class, "map[key0]", new PropertyEditorSupport() { |
|
|
|
binder.registerCustomEditor(TestBean.class, "map[key0]", new PropertyEditorSupport() { |
|
|
|
@ -1632,7 +1629,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDirectBindingToEmptyIndexedFieldWithRegisteredGenericEditor() { |
|
|
|
void directBindingToEmptyIndexedFieldWithRegisteredGenericEditor() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
binder.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() { |
|
|
|
binder.registerCustomEditor(TestBean.class, "map", new PropertyEditorSupport() { |
|
|
|
@ -1663,7 +1660,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testCustomEditorWithSubclass() { |
|
|
|
void customEditorWithSubclass() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
binder.registerCustomEditor(TestBean.class, new PropertyEditorSupport() { |
|
|
|
binder.registerCustomEditor(TestBean.class, new PropertyEditorSupport() { |
|
|
|
@ -1697,7 +1694,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindToStringArrayWithArrayEditor() { |
|
|
|
void bindToStringArrayWithArrayEditor() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
binder.registerCustomEditor(String[].class, "stringArray", new PropertyEditorSupport() { |
|
|
|
binder.registerCustomEditor(String[].class, "stringArray", new PropertyEditorSupport() { |
|
|
|
@ -1709,15 +1706,12 @@ public class DataBinderTests { |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
pvs.add("stringArray", "a1-b2"); |
|
|
|
pvs.add("stringArray", "a1-b2"); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
boolean condition = !binder.getBindingResult().hasErrors(); |
|
|
|
assertThat(binder.getBindingResult().hasErrors()).isFalse(); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
assertThat(tb.getStringArray()).containsExactly("a1", "b2"); |
|
|
|
assertThat(tb.getStringArray().length).isEqualTo(2); |
|
|
|
|
|
|
|
assertThat(tb.getStringArray()[0]).isEqualTo("a1"); |
|
|
|
|
|
|
|
assertThat(tb.getStringArray()[1]).isEqualTo("b2"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindToStringArrayWithComponentEditor() { |
|
|
|
void bindToStringArrayWithComponentEditor() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
binder.registerCustomEditor(String.class, "stringArray", new PropertyEditorSupport() { |
|
|
|
binder.registerCustomEditor(String.class, "stringArray", new PropertyEditorSupport() { |
|
|
|
@ -1729,15 +1723,14 @@ public class DataBinderTests { |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
pvs.add("stringArray", new String[] {"a1", "b2"}); |
|
|
|
pvs.add("stringArray", new String[] {"a1", "b2"}); |
|
|
|
binder.bind(pvs); |
|
|
|
binder.bind(pvs); |
|
|
|
boolean condition = !binder.getBindingResult().hasErrors(); |
|
|
|
assertThat(binder.getBindingResult().hasErrors()).isFalse(); |
|
|
|
assertThat(condition).isTrue(); |
|
|
|
|
|
|
|
assertThat(tb.getStringArray().length).isEqualTo(2); |
|
|
|
assertThat(tb.getStringArray().length).isEqualTo(2); |
|
|
|
assertThat(tb.getStringArray()[0]).isEqualTo("Xa1"); |
|
|
|
assertThat(tb.getStringArray()[0]).isEqualTo("Xa1"); |
|
|
|
assertThat(tb.getStringArray()[1]).isEqualTo("Xb2"); |
|
|
|
assertThat(tb.getStringArray()[1]).isEqualTo("Xb2"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindingErrors() { |
|
|
|
void bindingErrors() { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
@ -1764,7 +1757,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAddAllErrors() { |
|
|
|
void addAllErrors() { |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
TestBean rod = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
DataBinder binder = new DataBinder(rod, "person"); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
@ -1784,7 +1777,7 @@ public class DataBinderTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
@SuppressWarnings("unchecked") |
|
|
|
public void testBindingWithResortedList() { |
|
|
|
void bindingWithResortedList() { |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
IndexedTestBean tb = new IndexedTestBean(); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
DataBinder binder = new DataBinder(tb, "tb"); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues pvs = new MutablePropertyValues(); |
|
|
|
@ -1802,7 +1795,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testRejectWithoutDefaultMessage() { |
|
|
|
void rejectWithoutDefaultMessage() { |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
TestBean tb = new TestBean(); |
|
|
|
tb.setName("myName"); |
|
|
|
tb.setName("myName"); |
|
|
|
tb.setAge(99); |
|
|
|
tb.setAge(99); |
|
|
|
@ -1820,7 +1813,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testBindExceptionSerializable() throws Exception { |
|
|
|
void bindExceptionSerializable() throws Exception { |
|
|
|
SerializablePerson tb = new SerializablePerson(); |
|
|
|
SerializablePerson tb = new SerializablePerson(); |
|
|
|
tb.setName("myName"); |
|
|
|
tb.setName("myName"); |
|
|
|
tb.setAge(99); |
|
|
|
tb.setAge(99); |
|
|
|
@ -1849,27 +1842,27 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testTrackDisallowedFields() { |
|
|
|
void trackDisallowedFields() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
binder.setAllowedFields("name", "age"); |
|
|
|
binder.setAllowedFields("name", "age"); |
|
|
|
|
|
|
|
|
|
|
|
String name = "Rob Harrop"; |
|
|
|
String name = "Rob Harrop"; |
|
|
|
String beanName = "foobar"; |
|
|
|
int age = 42; |
|
|
|
|
|
|
|
|
|
|
|
MutablePropertyValues mpvs = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues mpvs = new MutablePropertyValues(); |
|
|
|
mpvs.add("name", name); |
|
|
|
mpvs.add("name", name); |
|
|
|
mpvs.add("beanName", beanName); |
|
|
|
mpvs.add("age", age); |
|
|
|
|
|
|
|
mpvs.add("beanName", "foobar"); |
|
|
|
binder.bind(mpvs); |
|
|
|
binder.bind(mpvs); |
|
|
|
|
|
|
|
|
|
|
|
assertThat(testBean.getName()).isEqualTo(name); |
|
|
|
assertThat(testBean.getName()).isEqualTo(name); |
|
|
|
String[] disallowedFields = binder.getBindingResult().getSuppressedFields(); |
|
|
|
assertThat(testBean.getAge()).isEqualTo(age); |
|
|
|
assertThat(disallowedFields.length).isEqualTo(1); |
|
|
|
assertThat(binder.getBindingResult().getSuppressedFields()).containsExactly("beanName"); |
|
|
|
assertThat(disallowedFields[0]).isEqualTo("beanName"); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAutoGrowWithinDefaultLimit() { |
|
|
|
void autoGrowWithinDefaultLimit() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
|
|
|
|
|
|
|
|
@ -1881,7 +1874,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAutoGrowBeyondDefaultLimit() { |
|
|
|
void autoGrowBeyondDefaultLimit() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
|
|
|
|
|
|
|
|
@ -1893,7 +1886,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAutoGrowWithinCustomLimit() { |
|
|
|
void autoGrowWithinCustomLimit() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
binder.setAutoGrowCollectionLimit(10); |
|
|
|
binder.setAutoGrowCollectionLimit(10); |
|
|
|
@ -1906,7 +1899,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAutoGrowBeyondCustomLimit() { |
|
|
|
void autoGrowBeyondCustomLimit() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
binder.setAutoGrowCollectionLimit(10); |
|
|
|
binder.setAutoGrowCollectionLimit(10); |
|
|
|
@ -1919,7 +1912,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNestedGrowingList() { |
|
|
|
void nestedGrowingList() { |
|
|
|
Form form = new Form(); |
|
|
|
Form form = new Form(); |
|
|
|
DataBinder binder = new DataBinder(form, "form"); |
|
|
|
DataBinder binder = new DataBinder(form, "form"); |
|
|
|
MutablePropertyValues mpv = new MutablePropertyValues(); |
|
|
|
MutablePropertyValues mpv = new MutablePropertyValues(); |
|
|
|
@ -1935,7 +1928,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testFieldErrorAccessVariations() { |
|
|
|
void fieldErrorAccessVariations() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
assertThat(binder.getBindingResult().getGlobalError()).isNull(); |
|
|
|
assertThat(binder.getBindingResult().getGlobalError()).isNull(); |
|
|
|
@ -1956,7 +1949,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-14888
|
|
|
|
@Test // SPR-14888
|
|
|
|
public void testSetAutoGrowCollectionLimit() { |
|
|
|
void setAutoGrowCollectionLimit() { |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
BeanWithIntegerList tb = new BeanWithIntegerList(); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
DataBinder binder = new DataBinder(tb); |
|
|
|
binder.setAutoGrowCollectionLimit(257); |
|
|
|
binder.setAutoGrowCollectionLimit(257); |
|
|
|
@ -1970,7 +1963,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-14888
|
|
|
|
@Test // SPR-14888
|
|
|
|
public void testSetAutoGrowCollectionLimitAfterInitialization() { |
|
|
|
void setAutoGrowCollectionLimitAfterInitialization() { |
|
|
|
DataBinder binder = new DataBinder(new BeanWithIntegerList()); |
|
|
|
DataBinder binder = new DataBinder(new BeanWithIntegerList()); |
|
|
|
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); |
|
|
|
binder.registerCustomEditor(String.class, new StringTrimmerEditor(true)); |
|
|
|
assertThatIllegalStateException().isThrownBy(() -> |
|
|
|
assertThatIllegalStateException().isThrownBy(() -> |
|
|
|
@ -1979,7 +1972,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-15009
|
|
|
|
@Test // SPR-15009
|
|
|
|
public void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() { |
|
|
|
void setCustomMessageCodesResolverBeforeInitializeBindingResultForBeanPropertyAccess() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DefaultMessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver(); |
|
|
|
DefaultMessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver(); |
|
|
|
@ -1996,7 +1989,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-15009
|
|
|
|
@Test // SPR-15009
|
|
|
|
public void testSetCustomMessageCodesResolverBeforeInitializeBindingResultForDirectFieldAccess() { |
|
|
|
void setCustomMessageCodesResolverBeforeInitializeBindingResultForDirectFieldAccess() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DefaultMessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver(); |
|
|
|
DefaultMessageCodesResolver messageCodesResolver = new DefaultMessageCodesResolver(); |
|
|
|
@ -2011,7 +2004,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-15009
|
|
|
|
@Test // SPR-15009
|
|
|
|
public void testSetCustomMessageCodesResolverAfterInitializeBindingResult() { |
|
|
|
void setCustomMessageCodesResolverAfterInitializeBindingResult() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
binder.initBeanPropertyAccess(); |
|
|
|
binder.initBeanPropertyAccess(); |
|
|
|
@ -2026,7 +2019,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-15009
|
|
|
|
@Test // SPR-15009
|
|
|
|
public void testSetMessageCodesResolverIsNullAfterInitializeBindingResult() { |
|
|
|
void setMessageCodesResolverIsNullAfterInitializeBindingResult() { |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
binder.initBeanPropertyAccess(); |
|
|
|
binder.initBeanPropertyAccess(); |
|
|
|
@ -2040,8 +2033,7 @@ public class DataBinderTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test // SPR-15009
|
|
|
|
@Test // SPR-15009
|
|
|
|
public void testCallSetMessageCodesResolverTwice() { |
|
|
|
void callSetMessageCodesResolverTwice() { |
|
|
|
|
|
|
|
|
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
TestBean testBean = new TestBean(); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
DataBinder binder = new DataBinder(testBean, "testBean"); |
|
|
|
binder.setMessageCodesResolver(new DefaultMessageCodesResolver()); |
|
|
|
binder.setMessageCodesResolver(new DefaultMessageCodesResolver()); |
|
|
|
|