]> source.dussan.org Git - poi.git/commitdiff
Add some pre-checks to fail the test with better assertion if the locale is not set...
authorDominik Stadler <centic@apache.org>
Sat, 11 Jun 2016 17:03:59 +0000 (17:03 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 11 Jun 2016 17:03:59 +0000 (17:03 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747916 13f79535-47bb-0310-9956-ffa450edef68

src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java

index d827355cb5f1a5f54b09980c31569556a7f51581..705e4ae91dfa28a0faf1b0199177196c230ea8c3 100644 (file)
@@ -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