format system initial commit
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
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;
|
||||
|
||||
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,40 @@
|
||||
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;
|
||||
|
||||
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,39 @@
|
||||
package org.springframework.ui.format.number;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
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,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;
|
||||
|
||||
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