org.springframework.validation.DataBinder.bind()

Here are the examples of the java api org.springframework.validation.DataBinder.bind() taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

205 Examples 7

19 Source : MoneyFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testAmountAndUnit() {
    MoneyHolder bean = new MoneyHolder();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "USD 10.50");
    propertyValues.add("unit", "USD");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("USD10.50", binder.getBindingResult().getFieldValue("amount"));
    replacedertEquals("USD", binder.getBindingResult().getFieldValue("unit"));
    replacedertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    replacedertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
    LocaleContextHolder.setLocale(Locale.CANADA);
    binder.bind(propertyValues);
    LocaleContextHolder.setLocale(Locale.US);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("USD10.50", binder.getBindingResult().getFieldValue("amount"));
    replacedertEquals("USD", binder.getBindingResult().getFieldValue("unit"));
    replacedertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    replacedertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}

19 Source : MoneyFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testAmountWithNumberFormat5() {
    FormattedMoneyHolder5 bean = new FormattedMoneyHolder5();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "USD 10.50");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("USD 010.500", binder.getBindingResult().getFieldValue("amount"));
    replacedertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    replacedertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
    LocaleContextHolder.setLocale(Locale.CANADA);
    binder.bind(propertyValues);
    LocaleContextHolder.setLocale(Locale.US);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("USD 010.500", binder.getBindingResult().getFieldValue("amount"));
    replacedertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    replacedertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}

19 Source : MoneyFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testAmountWithNumberFormat2() {
    FormattedMoneyHolder2 bean = new FormattedMoneyHolder2();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "10.50");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("10.5", binder.getBindingResult().getFieldValue("amount"));
    replacedertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    replacedertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}

19 Source : MoneyFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testAmountWithNumberFormat1() {
    FormattedMoneyHolder1 bean = new FormattedMoneyHolder1();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "$10.50");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("$10.50", binder.getBindingResult().getFieldValue("amount"));
    replacedertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    replacedertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
    LocaleContextHolder.setLocale(Locale.CANADA);
    binder.bind(propertyValues);
    LocaleContextHolder.setLocale(Locale.US);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("$10.50", binder.getBindingResult().getFieldValue("amount"));
    replacedertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    replacedertEquals("CAD", bean.getAmount().getCurrency().getCurrencyCode());
}

19 Source : MoneyFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testAmountWithNumberFormat3() {
    FormattedMoneyHolder3 bean = new FormattedMoneyHolder3();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "10%");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("10%", binder.getBindingResult().getFieldValue("amount"));
    replacedertTrue(bean.getAmount().getNumber().doubleValue() == 0.1d);
    replacedertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}

19 Source : MoneyFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testAmountWithNumberFormat4() {
    FormattedMoneyHolder4 bean = new FormattedMoneyHolder4();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "010.500");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("010.500", binder.getBindingResult().getFieldValue("amount"));
    replacedertTrue(bean.getAmount().getNumber().doubleValue() == 10.5d);
    replacedertEquals("USD", bean.getAmount().getCurrency().getCurrencyCode());
}

18 Source : MoneyFormattingTests.java
with Apache License 2.0
from SourceHot

@Test
public void testAmountWithNumberFormat4() {
    FormattedMoneyHolder4 bean = new FormattedMoneyHolder4();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "010.500");
    binder.bind(propertyValues);
    replacedertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
    replacedertThat(binder.getBindingResult().getFieldValue("amount")).isEqualTo("010.500");
    replacedertThat(bean.getAmount().getNumber().doubleValue() == 10.5d).isTrue();
    replacedertThat(bean.getAmount().getCurrency().getCurrencyCode()).isEqualTo("USD");
}

18 Source : MoneyFormattingTests.java
with Apache License 2.0
from SourceHot

@Test
public void testAmountWithNumberFormat1() {
    FormattedMoneyHolder1 bean = new FormattedMoneyHolder1();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "$10.50");
    binder.bind(propertyValues);
    replacedertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
    replacedertThat(binder.getBindingResult().getFieldValue("amount")).isEqualTo("$10.50");
    replacedertThat(bean.getAmount().getNumber().doubleValue() == 10.5d).isTrue();
    replacedertThat(bean.getAmount().getCurrency().getCurrencyCode()).isEqualTo("USD");
    LocaleContextHolder.setLocale(Locale.CANADA);
    binder.bind(propertyValues);
    LocaleContextHolder.setLocale(Locale.US);
    replacedertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
    replacedertThat(binder.getBindingResult().getFieldValue("amount")).isEqualTo("$10.50");
    replacedertThat(bean.getAmount().getNumber().doubleValue() == 10.5d).isTrue();
    replacedertThat(bean.getAmount().getCurrency().getCurrencyCode()).isEqualTo("CAD");
}

18 Source : MoneyFormattingTests.java
with Apache License 2.0
from SourceHot

@Test
public void testAmountAndUnit() {
    MoneyHolder bean = new MoneyHolder();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "USD 10.50");
    propertyValues.add("unit", "USD");
    binder.bind(propertyValues);
    replacedertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
    replacedertThat(binder.getBindingResult().getFieldValue("amount")).isEqualTo("USD10.50");
    replacedertThat(binder.getBindingResult().getFieldValue("unit")).isEqualTo("USD");
    replacedertThat(bean.getAmount().getNumber().doubleValue() == 10.5d).isTrue();
    replacedertThat(bean.getAmount().getCurrency().getCurrencyCode()).isEqualTo("USD");
    LocaleContextHolder.setLocale(Locale.CANADA);
    binder.bind(propertyValues);
    LocaleContextHolder.setLocale(Locale.US);
    replacedertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
    replacedertThat(binder.getBindingResult().getFieldValue("amount")).isEqualTo("USD10.50");
    replacedertThat(binder.getBindingResult().getFieldValue("unit")).isEqualTo("USD");
    replacedertThat(bean.getAmount().getNumber().doubleValue() == 10.5d).isTrue();
    replacedertThat(bean.getAmount().getCurrency().getCurrencyCode()).isEqualTo("USD");
}

18 Source : MoneyFormattingTests.java
with Apache License 2.0
from SourceHot

@Test
public void testAmountWithNumberFormat2() {
    FormattedMoneyHolder2 bean = new FormattedMoneyHolder2();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "10.50");
    binder.bind(propertyValues);
    replacedertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
    replacedertThat(binder.getBindingResult().getFieldValue("amount")).isEqualTo("10.5");
    replacedertThat(bean.getAmount().getNumber().doubleValue() == 10.5d).isTrue();
    replacedertThat(bean.getAmount().getCurrency().getCurrencyCode()).isEqualTo("USD");
}

18 Source : MoneyFormattingTests.java
with Apache License 2.0
from SourceHot

@Test
public void testAmountWithNumberFormat5() {
    FormattedMoneyHolder5 bean = new FormattedMoneyHolder5();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "USD 10.50");
    binder.bind(propertyValues);
    replacedertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
    replacedertThat(binder.getBindingResult().getFieldValue("amount")).isEqualTo("USD 010.500");
    replacedertThat(bean.getAmount().getNumber().doubleValue() == 10.5d).isTrue();
    replacedertThat(bean.getAmount().getCurrency().getCurrencyCode()).isEqualTo("USD");
    LocaleContextHolder.setLocale(Locale.CANADA);
    binder.bind(propertyValues);
    LocaleContextHolder.setLocale(Locale.US);
    replacedertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
    replacedertThat(binder.getBindingResult().getFieldValue("amount")).isEqualTo("USD 010.500");
    replacedertThat(bean.getAmount().getNumber().doubleValue() == 10.5d).isTrue();
    replacedertThat(bean.getAmount().getCurrency().getCurrencyCode()).isEqualTo("USD");
}

18 Source : MoneyFormattingTests.java
with Apache License 2.0
from SourceHot

@Test
public void testAmountWithNumberFormat3() {
    FormattedMoneyHolder3 bean = new FormattedMoneyHolder3();
    DataBinder binder = new DataBinder(bean);
    binder.setConversionService(conversionService);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("amount", "10%");
    binder.bind(propertyValues);
    replacedertThat(binder.getBindingResult().getErrorCount()).isEqualTo(0);
    replacedertThat(binder.getBindingResult().getFieldValue("amount")).isEqualTo("10%");
    replacedertThat(bean.getAmount().getNumber().doubleValue() == 0.1d).isTrue();
    replacedertThat(bean.getAmount().getCurrency().getCurrencyCode()).isEqualTo("USD");
}

18 Source : DefaultDubboConfigBinder.java
with Apache License 2.0
from smallFive55

@Override
public <C extends AbstractConfig> void bind(String prefix, C dubboConfig) {
    DataBinder dataBinder = new DataBinder(dubboConfig);
    // Set ignored*
    dataBinder.setIgnoreInvalidFields(isIgnoreInvalidFields());
    dataBinder.setIgnoreUnknownFields(isIgnoreUnknownFields());
    // Get properties under specified prefix from PropertySources
    Map<String, Object> properties = getSubProperties(getPropertySources(), prefix);
    // Convert Map to MutablePropertyValues
    MutablePropertyValues propertyValues = new MutablePropertyValues(properties);
    // Bind
    dataBinder.bind(propertyValues);
}

18 Source : DataBinderBootstrap.java
with Apache License 2.0
from mercyblitz

public static void main(String[] args) {
    Integer integer = new Integer(0);
    DataBinder dataBinder = new DataBinder(integer);
    dataBinder.setIgnoreUnknownFields(false);
    dataBinder.setIgnoreInvalidFields(false);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.addPropertyValue("value", 2);
    dataBinder.bind(propertyValues);
    System.out.println(integer);
}

18 Source : DefaultDubboConfigBinder.java
with Apache License 2.0
from boomblog

@Override
public <C extends AbstractConfig> void bind(String prefix, C dubboConfig) {
    DataBinder dataBinder = new DataBinder(dubboConfig);
    // Set ignored*
    dataBinder.setIgnoreInvalidFields(isIgnoreInvalidFields());
    dataBinder.setIgnoreUnknownFields(isIgnoreUnknownFields());
    // Get properties under specified prefix from PropertySources
    Map<String, String> properties = getSubProperties(getPropertySources(), prefix);
    // Convert Map to MutablePropertyValues
    MutablePropertyValues propertyValues = new MutablePropertyValues(properties);
    // Bind
    dataBinder.bind(propertyValues);
}

18 Source : DefaultConfigurationBeanBinder.java
with Apache License 2.0
from alibaba

@Override
public void bind(Map<String, Object> configurationProperties, boolean ignoreUnknownFields, boolean ignoreInvalidFields, Object configurationBean) {
    DataBinder dataBinder = new DataBinder(configurationBean);
    // Set ignored*
    dataBinder.setIgnoreInvalidFields(ignoreUnknownFields);
    dataBinder.setIgnoreUnknownFields(ignoreInvalidFields);
    // Get properties under specified prefix from PropertySources
    // Convert Map to MutablePropertyValues
    MutablePropertyValues propertyValues = new MutablePropertyValues(configurationProperties);
    // Bind
    dataBinder.bind(propertyValues);
}

17 Source : NumberFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testPatternArrayFormatting() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("patternArray", new String[] { "1,25.00", "2,35.00" });
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternArray[0]"));
    replacedertEquals("2,35.00", binder.getBindingResult().getFieldValue("patternArray[1]"));
    propertyValues = new MutablePropertyValues();
    propertyValues.add("patternArray[0]", "1,25.00");
    propertyValues.add("patternArray[1]", "2,35.00");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternArray[0]"));
    replacedertEquals("2,35.00", binder.getBindingResult().getFieldValue("patternArray[1]"));
}

17 Source : NumberFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testPatternFormatting() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("pattern", "1,25.00");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("1,25.00", binder.getBindingResult().getFieldValue("pattern"));
}

17 Source : NumberFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testPercentFormatting() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("percent", "53%");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("53%", binder.getBindingResult().getFieldValue("percent"));
}

17 Source : NumberFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testPatternList2FormattingListElement() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("patternList2[0]", "1,25.00");
    propertyValues.add("patternList2[1]", "2,35.00");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternList2[0]"));
    replacedertEquals("2,35.00", binder.getBindingResult().getFieldValue("patternList2[1]"));
}

17 Source : NumberFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testDefaultNumberFormatting() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("numberDefault", "3,339.12");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("3,339", binder.getBindingResult().getFieldValue("numberDefault"));
}

17 Source : NumberFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testPatternList2FormattingList() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("patternList2[0]", "1,25.00");
    propertyValues.add("patternList2[1]", "2,35.00");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("1,25.00,2,35.00", binder.getBindingResult().getFieldValue("patternList2"));
}

17 Source : NumberFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testCurrencyFormatting() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("currency", "$3,339.12");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("$3,339.12", binder.getBindingResult().getFieldValue("currency"));
}

17 Source : NumberFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testDefaultNumberFormattingAnnotated() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("numberDefaultAnnotated", "3,339.12");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("3,339.12", binder.getBindingResult().getFieldValue("numberDefaultAnnotated"));
}

17 Source : NumberFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testPatternListFormatting() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("patternList", new String[] { "1,25.00", "2,35.00" });
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternList[0]"));
    replacedertEquals("2,35.00", binder.getBindingResult().getFieldValue("patternList[1]"));
    propertyValues = new MutablePropertyValues();
    propertyValues.add("patternList[0]", "1,25.00");
    propertyValues.add("patternList[1]", "2,35.00");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("1,25.00", binder.getBindingResult().getFieldValue("patternList[0]"));
    replacedertEquals("2,35.00", binder.getBindingResult().getFieldValue("patternList[1]"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindInstant() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("instant", "2009-10-31T12:00:00.000Z");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertTrue(binder.getBindingResult().getFieldValue("instant").toString().startsWith("2009-10-31T12:00"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindDateTimeAnnotatedPattern() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("dateTimeAnnotatedPattern", "10/31/09 12:00 PM");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("10/31/09 12:00 PM", binder.getBindingResult().getFieldValue("dateTimeAnnotatedPattern"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindYear() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("year", "2007");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertTrue(binder.getBindingResult().getFieldValue("year").toString().equals("2007"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalDateWithSpecificStyle() {
    DateTimeFormatterRegistrar registrar = new DateTimeFormatterRegistrar();
    registrar.setDateStyle(FormatStyle.LONG);
    setup(registrar);
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDate", "October 31, 2009");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("October 31, 2009", binder.getBindingResult().getFieldValue("localDate"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindISODate() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("isoDate", "2009-10-31");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("2009-10-31", binder.getBindingResult().getFieldValue("isoDate"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindMonthInAnyCase() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("month", "July");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertTrue(binder.getBindingResult().getFieldValue("month").toString().equals("JULY"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalDateAnnotatedWithError() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDateAnnotated", "Oct -31, 2009");
    binder.bind(propertyValues);
    replacedertEquals(1, binder.getBindingResult().getFieldErrorCount("localDateAnnotated"));
    replacedertEquals("Oct -31, 2009", binder.getBindingResult().getFieldValue("localDateAnnotated"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindDuration() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("duration", "PT8H6M12.345S");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertTrue(binder.getBindingResult().getFieldValue("duration").toString().equals("PT8H6M12.345S"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindNestedLocalDateAnnotated() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("children[0].localDateAnnotated", "Oct 31, 2009");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("Oct 31, 2009", binder.getBindingResult().getFieldValue("children[0].localDateAnnotated"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalDateTimeFromJavaUtilCalendar() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDateTime", new GregorianCalendar(2009, 9, 31, 12, 0));
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    String value = binder.getBindingResult().getFieldValue("localDateTime").toString();
    replacedertTrue(value.startsWith("10/31/09"));
    replacedertTrue(value.endsWith("12:00 PM"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalDateArray() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDate", new String[] { "10/31/09" });
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalDateAnnotated() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDateAnnotated", "Oct 31, 2009");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("Oct 31, 2009", binder.getBindingResult().getFieldValue("localDateAnnotated"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindISOTime() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("isoTime", "12:00:00");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("12:00:00", binder.getBindingResult().getFieldValue("isoTime"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindMonthDay() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("monthDay", "--12-03");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertTrue(binder.getBindingResult().getFieldValue("monthDay").toString().equals("--12-03"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalDate() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDate", "10/31/09");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("10/31/09", binder.getBindingResult().getFieldValue("localDate"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindMonth() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("month", "JULY");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertTrue(binder.getBindingResult().getFieldValue("month").toString().equals("JULY"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindISODateTime() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("isoDateTime", "2009-10-31T12:00:00");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("2009-10-31T12:00:00", binder.getBindingResult().getFieldValue("isoDateTime"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindISOTimeWithZone() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("isoTime", "12:00:00.000-05:00");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("12:00:00", binder.getBindingResult().getFieldValue("isoTime"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindDateTimeOverflow() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("dateTimeAnnotatedPattern", "02/29/09 12:00 PM");
    binder.bind(propertyValues);
    replacedertEquals(1, binder.getBindingResult().getErrorCount());
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalDateTime() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDateTime", LocalDateTime.of(2009, 10, 31, 12, 0));
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    String value = binder.getBindingResult().getFieldValue("localDateTime").toString();
    replacedertTrue(value.startsWith("10/31/09"));
    replacedertTrue(value.endsWith("12:00 PM"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindPeriod() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("period", "P6Y3M1D");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertTrue(binder.getBindingResult().getFieldValue("period").toString().equals("P6Y3M1D"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalDateTimeAnnotated() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localDateTimeAnnotated", LocalDateTime.of(2009, 10, 31, 12, 0));
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    String value = binder.getBindingResult().getFieldValue("localDateTimeAnnotated").toString();
    replacedertTrue(value.startsWith("Oct 31, 2009"));
    replacedertTrue(value.endsWith("12:00:00 PM"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindYearMonth() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("yearMonth", "2007-12");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertTrue(binder.getBindingResult().getFieldValue("yearMonth").toString().equals("2007-12"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalTime() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localTime", "12:00 PM");
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("12:00 PM", binder.getBindingResult().getFieldValue("localTime"));
}

17 Source : DateTimeFormattingTests.java
with MIT License
from Vip-Augus

@Test
public void testBindLocalTimeFromJavaUtilCalendar() {
    MutablePropertyValues propertyValues = new MutablePropertyValues();
    propertyValues.add("localTime", new GregorianCalendar(1970, 0, 0, 12, 0));
    binder.bind(propertyValues);
    replacedertEquals(0, binder.getBindingResult().getErrorCount());
    replacedertEquals("12:00 PM", binder.getBindingResult().getFieldValue("localTime"));
}

See More Examples