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
This commit is contained in:
Dominik Stadler 2016-06-11 17:03:59 +00:00
parent b758810081
commit b9ceae5ef3

View 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