Alerts test

This commit is contained in:
Keith Donald
2009-06-26 15:09:56 +00:00
parent 3b68cde32b
commit 60c2b38c03
4 changed files with 48 additions and 31 deletions

View File

@@ -0,0 +1,32 @@
package org.springframework.ui.alert;
import static org.junit.Assert.assertEquals;
import static org.springframework.ui.alert.Alerts.error;
import static org.springframework.ui.alert.Alerts.fatal;
import static org.springframework.ui.alert.Alerts.info;
import static org.springframework.ui.alert.Alerts.warning;
import org.junit.Test;
public class AlertsTests {
@Test
public void testFactoryMethods() {
Alert a1 = info("alert 1");
assertEquals(Severity.INFO, a1.getSeverity());
assertEquals("alert 1", a1.getMessage());
Alert a2 = warning("alert 2");
assertEquals(Severity.WARNING, a2.getSeverity());
assertEquals("alert 2", a2.getMessage());
Alert a3 = error("alert 3");
assertEquals(Severity.ERROR, a3.getSeverity());
assertEquals("alert 3", a3.getMessage());
Alert a4 = fatal("alert 4");
assertEquals(Severity.FATAL, a4.getSeverity());
assertEquals("alert 4", a4.getMessage());
}
}

View File

@@ -1,4 +1,4 @@
package org.springframework.ui.alert;
package org.springframework.ui.alert.support;
import static org.junit.Assert.assertEquals;
@@ -8,7 +8,7 @@ import org.springframework.ui.alert.Alert;
import org.springframework.ui.alert.Severity;
import org.springframework.ui.alert.support.DefaultAlertContext;
public class DefaultMessageContextTests {
public class DefaultAlertContextTests {
private DefaultAlertContext context;
@@ -20,10 +20,6 @@ public class DefaultMessageContextTests {
@Test
public void addAlert() {
Alert alert = new Alert() {
public String getElement() {
return "form.property";
}
public String getCode() {
return "invalidFormat";
}
@@ -36,7 +32,7 @@ public class DefaultMessageContextTests {
return Severity.ERROR;
}
};
context.add(alert);
context.add("form.property", alert);
assertEquals(1, context.getAlerts().size());
assertEquals("invalidFormat", context.getAlerts("form.property").get(0).getCode());
}

View File

@@ -103,9 +103,7 @@ public class GenericBinderTests {
@Test
public void bindSingleValueWithFormatterRegistedByType() throws ParseException {
GenericFormatterRegistry registry = new GenericFormatterRegistry();
registry.add(Date.class, new DateFormatter());
binder.setFormatterRegistry(registry);
binder.registerFormatter(Date.class, new DateFormatter());
binder.bind(Collections.singletonMap("date", "2009-06-01"));
assertEquals(new DateFormatter().parse("2009-06-01", Locale.US), bean.getDate());
}
@@ -121,9 +119,7 @@ public class GenericBinderTests {
@Test
public void bindSingleValueWithnAnnotationFormatterFactoryRegistered() throws ParseException {
GenericFormatterRegistry registry = new GenericFormatterRegistry();
registry.add(new CurrencyAnnotationFormatterFactory());
binder.setFormatterRegistry(registry);
binder.registerFormatterFactory(new CurrencyAnnotationFormatterFactory());
binder.bind(Collections.singletonMap("currency", "$23.56"));
assertEquals(new BigDecimal("23.56"), bean.getCurrency());
}