From b9ceae5ef37d31bfe4555325e7f6edc4c9892a57 Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sat, 11 Jun 2016 17:03:59 +0000 Subject: [PATCH] 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 --- .../poi/ss/usermodel/TestDataFormatter.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java index d827355cb..705e4ae91 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