polish
This commit is contained in:
parent
6ce119483d
commit
9b7e9942db
|
|
@ -20,7 +20,6 @@ import org.junit.After;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.ui.binding.Binder;
|
||||
import org.springframework.ui.binding.Binding;
|
||||
import org.springframework.ui.binding.BindingConfiguration;
|
||||
import org.springframework.ui.binding.BindingResult;
|
||||
|
|
@ -31,12 +30,13 @@ import org.springframework.ui.format.date.DateFormatter;
|
|||
import org.springframework.ui.format.number.CurrencyFormat;
|
||||
import org.springframework.ui.format.number.CurrencyFormatter;
|
||||
import org.springframework.ui.format.number.IntegerFormatter;
|
||||
import org.springframework.ui.message.MockMessageSource;
|
||||
|
||||
public class GenericBinderTests {
|
||||
|
||||
private TestBean bean;
|
||||
|
||||
private Binder binder;
|
||||
private GenericBinder binder;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
|
@ -206,6 +206,17 @@ public class GenericBinderTests {
|
|||
assertEquals("2,300", b.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void invalidFormatBindingResultCustomAlertMessage() {
|
||||
MockMessageSource messages = new MockMessageSource();
|
||||
messages.addMessage("invalidFormat", Locale.US, "Please enter an integer in format ### for the #{label} field; you entered #{value}");
|
||||
binder.setMessageSource(messages);
|
||||
binder.configureBinding(new BindingConfiguration("integer", new IntegerFormatter()));
|
||||
Binding b = binder.getBinding("integer");
|
||||
BindingResult result = b.setValue("bogus");
|
||||
assertEquals("Please enter an integer in format ### for the integer field; you entered bogus", result.getAlert().getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getBindingMultiValued() {
|
||||
Binding b = binder.getBinding("foos");
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ import java.util.Map;
|
|||
import org.springframework.context.support.AbstractMessageSource;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
class MockMessageSource extends AbstractMessageSource {
|
||||
public class MockMessageSource extends AbstractMessageSource {
|
||||
|
||||
/** Map from 'code + locale' keys to message Strings */
|
||||
private final Map<String, String> messages = new HashMap<String, String>();
|
||||
|
|
|
|||
Loading…
Reference in New Issue