SPR-6012, SPR-6013, SPR-6014 initial commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
package org.springframework.ui.format;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.ui.format.number.IntegerFormatter;
|
||||
|
||||
public class GenericFormatterRegistryTests {
|
||||
|
||||
private GenericFormatterRegistry registry;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
registry = new GenericFormatterRegistry();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testAdd() {
|
||||
registry.add(new IntegerFormatter());
|
||||
Formatter formatter = registry.getFormatter(typeDescriptor(Long.class));
|
||||
String formatted = formatter.format(new Long(3), Locale.US);
|
||||
assertEquals("3", formatted);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testAddByOtherObjectType() {
|
||||
registry.add(Integer.class, new IntegerFormatter());
|
||||
Formatter formatter = registry.getFormatter(typeDescriptor(Integer.class));
|
||||
String formatted = formatter.format(new Integer(3), Locale.US);
|
||||
assertEquals("3", formatted);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void testAddAnnotationFormatterFactory() {
|
||||
}
|
||||
|
||||
private static TypeDescriptor typeDescriptor(Class<?> clazz) {
|
||||
return TypeDescriptor.valueOf(clazz);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
package org.springframework.ui.format.date;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Calendar;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ui.format.date.DateFormatter;
|
||||
|
||||
public class DateFormatterTests {
|
||||
|
||||
private DateFormatter formatter = new DateFormatter();
|
||||
|
||||
@Test
|
||||
public void formatValue() {
|
||||
Calendar cal = Calendar.getInstance(Locale.US);
|
||||
cal.clear();
|
||||
cal.set(Calendar.YEAR, 2009);
|
||||
cal.set(Calendar.MONTH, Calendar.JUNE);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||
assertEquals("2009-06-01", formatter.format(cal.getTime(), Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValue() throws ParseException {
|
||||
Calendar cal = Calendar.getInstance(Locale.US);
|
||||
cal.clear();
|
||||
cal.set(Calendar.YEAR, 2009);
|
||||
cal.set(Calendar.MONTH, Calendar.JUNE);
|
||||
cal.set(Calendar.DAY_OF_MONTH, 1);
|
||||
assertEquals(cal.getTime(), formatter.parse("2009-06-01", Locale.US));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
package org.springframework.ui.format.number;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ui.format.number.CurrencyFormatter;
|
||||
|
||||
public class CurrencyFormatterTests {
|
||||
|
||||
private CurrencyFormatter formatter = new CurrencyFormatter();
|
||||
|
||||
@Test
|
||||
public void formatValue() {
|
||||
assertEquals("$23.00", formatter.format(new BigDecimal("23"), Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValue() throws ParseException {
|
||||
assertEquals(new BigDecimal("23.56"), formatter.parse("$23.56", Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEmptyValue() throws ParseException {
|
||||
assertEquals(null, formatter.parse("", Locale.US));
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void parseBogusValue() throws ParseException {
|
||||
formatter.parse("bogus", Locale.US);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValueDefaultRoundDown() throws ParseException {
|
||||
assertEquals(new BigDecimal("23.56"), formatter.parse("$23.567", Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseWholeValue() throws ParseException {
|
||||
assertEquals(new BigDecimal("23.00"), formatter.parse("$23", Locale.US));
|
||||
}
|
||||
|
||||
@Test(expected=ParseException.class)
|
||||
public void parseValueNotLenientFailure() throws ParseException {
|
||||
formatter.parse("$23.56bogus", Locale.US);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.springframework.ui.format.number;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ui.format.number.DecimalFormatter;
|
||||
|
||||
public class DecimalFormatterTests {
|
||||
|
||||
private DecimalFormatter formatter = new DecimalFormatter();
|
||||
|
||||
@Test
|
||||
public void formatValue() {
|
||||
assertEquals("23.56", formatter.format(new BigDecimal("23.56"), Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValue() throws ParseException {
|
||||
assertEquals(new BigDecimal("23.56"), formatter.parse("23.56", Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEmptyValue() throws ParseException {
|
||||
assertEquals(null, formatter.parse("", Locale.US));
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void parseBogusValue() throws ParseException {
|
||||
formatter.parse("bogus", Locale.US);
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void parsePercentValueNotLenientFailure() throws ParseException {
|
||||
formatter.parse("23.56bogus", Locale.US);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.springframework.ui.format.number;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ui.format.number.IntegerFormatter;
|
||||
|
||||
public class IntegerFormatterTests {
|
||||
|
||||
private IntegerFormatter formatter = new IntegerFormatter();
|
||||
|
||||
@Test
|
||||
public void formatValue() {
|
||||
assertEquals("23", formatter.format(23L, Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValue() throws ParseException {
|
||||
assertEquals((Long) 2356L, formatter.parse("2356", Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEmptyValue() throws ParseException {
|
||||
assertEquals(null, formatter.parse("", Locale.US));
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void parseBogusValue() throws ParseException {
|
||||
formatter.parse("bogus", Locale.US);
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void parsePercentValueNotLenientFailure() throws ParseException {
|
||||
formatter.parse("23.56", Locale.US);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,42 @@
|
||||
package org.springframework.ui.format.number;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.ui.format.number.PercentFormatter;
|
||||
|
||||
public class PercentFormatterTests {
|
||||
|
||||
private PercentFormatter formatter = new PercentFormatter();
|
||||
|
||||
@Test
|
||||
public void formatValue() {
|
||||
assertEquals("23%", formatter.format(new BigDecimal(".23"), Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseValue() throws ParseException {
|
||||
assertEquals(new BigDecimal(".2356"), formatter.parse("23.56%",
|
||||
Locale.US));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void parseEmptyValue() throws ParseException {
|
||||
assertEquals(null, formatter.parse("", Locale.US));
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void parseBogusValue() throws ParseException {
|
||||
formatter.parse("bogus", Locale.US);
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
public void parsePercentValueNotLenientFailure() throws ParseException {
|
||||
formatter.parse("23.56%bogus", Locale.US);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user