-
-
Notifications
You must be signed in to change notification settings - Fork 994
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add locale based comma support for /pay (#5962)
Co-authored-by: JRoy <[email protected]>
- Loading branch information
Showing
3 changed files
with
133 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
Essentials/src/test/java/com/earth2me/essentials/utils/NumberUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.earth2me.essentials.utils; | ||
|
||
import com.earth2me.essentials.commands.InvalidModifierException; | ||
import org.junit.Test; | ||
|
||
import java.math.BigDecimal; | ||
import java.text.ParseException; | ||
import java.util.Locale; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
import static org.junit.Assert.assertThrows; | ||
|
||
public class NumberUtilTest { | ||
|
||
@Test | ||
public void testStringParseBDecimal() throws ParseException, InvalidModifierException { | ||
|
||
final BigDecimal decimal = NumberUtil.parseStringToBDecimal("10,000,000.5"); | ||
assertEquals("10000000.5", decimal.toString()); | ||
|
||
final BigDecimal decimal2 = NumberUtil.parseStringToBDecimal("10.000.000,5"); | ||
assertNotEquals("10000000.5", decimal2.toString()); | ||
|
||
final BigDecimal decimal3 = NumberUtil.parseStringToBDecimal("10000000,5"); | ||
assertNotEquals("10000000.5", decimal3.toString()); | ||
|
||
final BigDecimal decimal4 = NumberUtil.parseStringToBDecimal("10000000.5"); | ||
assertEquals("10000000.5", decimal4.toString()); | ||
|
||
final BigDecimal decimal5 = NumberUtil.parseStringToBDecimal("10000000.50000"); | ||
assertEquals("10000000.5", decimal5.toString()); | ||
|
||
final BigDecimal decimal6 = NumberUtil.parseStringToBDecimal(".50000"); | ||
assertEquals("0.5", decimal6.toString()); | ||
|
||
final BigDecimal decimal7 = NumberUtil.parseStringToBDecimal("00000.50000"); | ||
assertEquals("0.5", decimal7.toString()); | ||
|
||
final BigDecimal decimal8 = NumberUtil.parseStringToBDecimal(",50000"); | ||
assertEquals("50000", decimal8.toString()); | ||
|
||
assertThrows(InvalidModifierException.class, ()-> NumberUtil.parseStringToBDecimal("abc")); | ||
|
||
assertThrows(IllegalArgumentException.class, ()-> NumberUtil.parseStringToBDecimal("")); | ||
|
||
assertThrows(ParseException.class, ()-> NumberUtil.parseStringToBDecimal("M")); | ||
} | ||
|
||
@Test | ||
public void testStringParseBDecimalLocale() throws ParseException, InvalidModifierException { | ||
|
||
final Locale locale = Locale.GERMANY; | ||
|
||
final BigDecimal decimal = NumberUtil.parseStringToBDecimal("10,000,000.5", locale); | ||
assertNotEquals("10000000.5", decimal.toString()); | ||
|
||
final BigDecimal decimal2 = NumberUtil.parseStringToBDecimal("10.000.000,5", locale); | ||
assertEquals("10000000.5", decimal2.toString()); | ||
|
||
final BigDecimal decimal3 = NumberUtil.parseStringToBDecimal("10000000,5", locale); | ||
assertEquals("10000000.5", decimal3.toString()); | ||
|
||
final BigDecimal decimal4 = NumberUtil.parseStringToBDecimal("10000000.5", locale); | ||
assertNotEquals("10000000.5", decimal4.toString()); | ||
|
||
final BigDecimal decimal5 = NumberUtil.parseStringToBDecimal(",5", locale); | ||
assertEquals("0.5", decimal5.toString()); | ||
|
||
final BigDecimal decimal6 = NumberUtil.parseStringToBDecimal(".50000", locale); | ||
assertEquals("50000", decimal6.toString()); | ||
} | ||
} |