Assertions for error codes in case of formatting failures
Issue: SPR-14345
(cherry picked from commit c6f63bd
)
This commit is contained in:
parent
9ac661df82
commit
367e663730
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
|
@ -226,12 +226,14 @@ public class DataBinderTests {
|
|||
|
||||
assertTrue("Has age errors", br.hasFieldErrors("age"));
|
||||
assertTrue("Correct number of age errors", br.getFieldErrorCount("age") == 1);
|
||||
assertEquals("typeMismatch", binder.getBindingResult().getFieldError("age").getCode());
|
||||
assertEquals("32x", binder.getBindingResult().getFieldValue("age"));
|
||||
assertEquals("32x", binder.getBindingResult().getFieldError("age").getRejectedValue());
|
||||
assertEquals(0, tb.getAge());
|
||||
|
||||
assertTrue("Has touchy errors", br.hasFieldErrors("touchy"));
|
||||
assertTrue("Correct number of touchy errors", br.getFieldErrorCount("touchy") == 1);
|
||||
assertEquals("methodInvocation", binder.getBindingResult().getFieldError("touchy").getCode());
|
||||
assertEquals("m.y", binder.getBindingResult().getFieldValue("touchy"));
|
||||
assertEquals("m.y", binder.getBindingResult().getFieldError("touchy").getRejectedValue());
|
||||
assertNull(tb.getTouchy());
|
||||
|
@ -315,12 +317,14 @@ public class DataBinderTests {
|
|||
|
||||
assertTrue("Has age errors", br.hasFieldErrors("age"));
|
||||
assertTrue("Correct number of age errors", br.getFieldErrorCount("age") == 1);
|
||||
assertEquals("typeMismatch", binder.getBindingResult().getFieldError("age").getCode());
|
||||
assertEquals("32x", binder.getBindingResult().getFieldValue("age"));
|
||||
assertEquals("32x", binder.getBindingResult().getFieldError("age").getRejectedValue());
|
||||
assertEquals(0, tb.getAge());
|
||||
|
||||
assertTrue("Has touchy errors", br.hasFieldErrors("touchy"));
|
||||
assertTrue("Correct number of touchy errors", br.getFieldErrorCount("touchy") == 1);
|
||||
assertEquals("methodInvocation", binder.getBindingResult().getFieldError("touchy").getCode());
|
||||
assertEquals("m.y", binder.getBindingResult().getFieldValue("touchy"));
|
||||
assertEquals("m.y", binder.getBindingResult().getFieldError("touchy").getRejectedValue());
|
||||
assertNull(tb.getTouchy());
|
||||
|
@ -419,6 +423,7 @@ public class DataBinderTests {
|
|||
|
||||
binder.bind(pvs);
|
||||
assertTrue(binder.getBindingResult().hasFieldErrors("name"));
|
||||
assertEquals("typeMismatch", binder.getBindingResult().getFieldError("name").getCode());
|
||||
assertEquals("test", binder.getBindingResult().getFieldValue("name"));
|
||||
}
|
||||
|
||||
|
@ -567,6 +572,7 @@ public class DataBinderTests {
|
|||
assertEquals(new Float(0.0), tb.getMyFloat());
|
||||
assertEquals("1x2", binder.getBindingResult().getFieldValue("myFloat"));
|
||||
assertTrue(binder.getBindingResult().hasFieldErrors("myFloat"));
|
||||
assertEquals("typeMismatch", binder.getBindingResult().getFieldError("myFloat").getCode());
|
||||
}
|
||||
finally {
|
||||
LocaleContextHolder.resetLocaleContext();
|
||||
|
@ -881,7 +887,6 @@ public class DataBinderTests {
|
|||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue(new Integer(99));
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return "argh";
|
||||
|
@ -906,7 +911,6 @@ public class DataBinderTests {
|
|||
public void setAsText(String text) throws IllegalArgumentException {
|
||||
setValue("prefix" + text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAsText() {
|
||||
return ((String) getValue()).substring(6);
|
||||
|
@ -979,7 +983,6 @@ public class DataBinderTests {
|
|||
public Integer parse(String text, Locale locale) throws ParseException {
|
||||
return 99;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String print(Integer object, Locale locale) {
|
||||
return "argh";
|
||||
|
|
Loading…
Reference in New Issue