aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2016-06-11 17:03:59 +0000
committerDominik Stadler <centic@apache.org>2016-06-11 17:03:59 +0000
commit2edb0f535b13ceec3bae7d52bd7b6292b420014a (patch)
tree7bd2ed1baf89d200039313c29ad49474ae4ddf9a
parent781a4283b59435c030de030849a89ed3363cf106 (diff)
downloadpoi-2edb0f535b13ceec3bae7d52bd7b6292b420014a.tar.gz
poi-2edb0f535b13ceec3bae7d52bd7b6292b420014a.zip
Add some pre-checks to fail the test with better assertion if the locale is not set correctly.
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747916 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
index d827355cb5..705e4ae91d 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
@@ -34,7 +34,11 @@ import java.util.Locale;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
+import org.apache.poi.ss.format.CellFormat;
+import org.apache.poi.ss.format.CellFormatResult;
+import org.apache.poi.ss.util.NumberToTextConverter;
import org.apache.poi.util.LocaleUtil;
+import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
@@ -47,6 +51,28 @@ import org.junit.Test;
public class TestDataFormatter {
private static final double _15_MINUTES = 0.041666667;
+ @BeforeClass
+ public static void setUpClass() {
+ // some pre-checks to hunt for a problem in the Maven build
+ // these checks ensure that the correct locale is set, so a failure here
+ // usually indicates an invalid locale during test-execution
+
+ assertFalse(DateUtil.isADateFormat(-1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-"));
+ assertEquals(Locale.getDefault(), LocaleUtil.getUserLocale());
+ final String textValue = NumberToTextConverter.toText(1234.56);
+ assertEquals(-1, textValue.indexOf('E'));
+ Object cellValueO = Double.valueOf(1234.56);
+
+ /*CellFormat cellFormat = new CellFormat("_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-");
+ CellFormatResult result = cellFormat.apply(cellValueO);
+ assertEquals(" 1,234.56 ", result.text);*/
+
+ CellFormat cfmt = CellFormat.getInstance("_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-");
+ CellFormatResult result = cfmt.apply(cellValueO);
+ assertEquals("This failure can indicate that the wrong locale is used during test-execution, ensure you run with english/US via -Duser.language=en -Duser.country=US",
+ " 1,234.56 ", result.text);
+ }
+
/**
* Test that we use the specified locale when deciding
* how to format normal numbers