You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ki...@apache.org on 2015/09/07 22:19:51 UTC
svn commit: r1701688 [7/7] - in /poi/trunk: ./
src/java/org/apache/poi/hssf/eventusermodel/
src/java/org/apache/poi/hssf/model/ src/java/org/apache/poi/hssf/usermodel/
src/java/org/apache/poi/poifs/filesystem/
src/java/org/apache/poi/ss/format/ src/jav...
Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTime.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTime.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTime.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestTime.java Mon Sep 7 20:19:50 2015
@@ -17,9 +17,9 @@
package org.apache.poi.ss.formula.functions;
-import java.util.regex.Pattern;
+import static org.junit.Assert.assertEquals;
-import junit.framework.TestCase;
+import java.util.regex.Pattern;
import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFCellStyle;
@@ -28,13 +28,13 @@ import org.apache.poi.hssf.usermodel.HSS
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.junit.Before;
+import org.junit.Test;
/**
* Tests for {@link TimeFunc}
- *
- * @author @author Steven Butler (sebutler @ gmail dot com)
*/
-public final class TestTime extends TestCase {
+public final class TestTime {
private static final int SECONDS_PER_MINUTE = 60;
private static final int SECONDS_PER_HOUR = 60 * SECONDS_PER_MINUTE;
@@ -44,7 +44,8 @@ public final class TestTime extends Test
private HSSFWorkbook wb;
private HSSFDataFormatter form;
private HSSFCellStyle style;
-
+
+ @Before
public void setUp() {
wb = new HSSFWorkbook();
HSSFSheet sheet = wb.createSheet("new sheet");
@@ -58,11 +59,13 @@ public final class TestTime extends Test
evaluator = new HSSFFormulaEvaluator(wb);
}
+ @Test
public void testSomeArgumentsMissing() {
confirm("00:00:00", "TIME(, 0, 0)");
confirm("12:00:00", "TIME(12, , )");
}
+ @Test
public void testValid() {
confirm("00:00:01", 0, 0, 1);
confirm("00:01:00", 0, 1, 0);
@@ -101,7 +104,6 @@ public final class TestTime extends Test
}
private void confirm(String expectedTimeStr, String formulaText) {
-// System.out.println("=" + formulaText);
String[] parts = Pattern.compile(":").split(expectedTimeStr);
int expH = Integer.parseInt(parts[0]);
int expM = Integer.parseInt(parts[1]);
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java Mon Sep 7 20:19:50 2015
@@ -17,23 +17,31 @@
package org.apache.poi.ss.usermodel;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.util.Calendar;
import java.util.Locale;
import java.util.TimeZone;
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.SpreadsheetVersion;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
+
+import junit.framework.AssertionFailedError;
/**
* Common superclass for testing implementations of
* {@link org.apache.poi.ss.usermodel.Cell}
*/
-public abstract class BaseTestCell extends TestCase {
+public abstract class BaseTestCell {
protected final ITestDataProvider _testDataProvider;
@@ -44,6 +52,7 @@ public abstract class BaseTestCell exten
_testDataProvider = testDataProvider;
}
+ @Test
public void testSetValues() {
Workbook book = _testDataProvider.createWorkbook();
Sheet sheet = book.createSheet("test");
@@ -80,7 +89,7 @@ public abstract class BaseTestCell exten
assertProhibitedValueAccess(cell, Cell.CELL_TYPE_NUMERIC, Cell.CELL_TYPE_BOOLEAN,
Cell.CELL_TYPE_FORMULA, Cell.CELL_TYPE_ERROR);
- Calendar c = Calendar.getInstance(TimeZone.getTimeZone("UTC"), Locale.ROOT);
+ Calendar c = LocaleUtil.getLocaleCalendar();
c.setTimeInMillis(123456789);
cell.setCellValue(c.getTime());
assertEquals(c.getTime().getTime(), cell.getDateCellValue().getTime());
@@ -132,6 +141,7 @@ public abstract class BaseTestCell exten
/**
* test that Boolean and Error types (BoolErrRecord) are supported properly.
*/
+ @Test
public void testBoolErr() {
Workbook wb = _testDataProvider.createWorkbook();
@@ -173,6 +183,7 @@ public abstract class BaseTestCell exten
/**
* test that Cell Styles being applied to formulas remain intact
*/
+ @Test
public void testFormulaStyle() {
Workbook wb = _testDataProvider.createWorkbook();
@@ -214,6 +225,7 @@ public abstract class BaseTestCell exten
}
/**tests the toString() method of HSSFCell*/
+ @Test
public void testToString() {
Workbook wb = _testDataProvider.createWorkbook();
Row r = wb.createSheet("Sheet1").createRow(0);
@@ -245,6 +257,7 @@ public abstract class BaseTestCell exten
/**
* Test that setting cached formula result keeps the cell type
*/
+ @Test
public void testSetFormulaValue() {
Workbook wb = _testDataProvider.createWorkbook();
Sheet s = wb.createSheet();
@@ -278,7 +291,7 @@ public abstract class BaseTestCell exten
return _testDataProvider.createWorkbook().createSheet("Sheet1").createRow(0).createCell(0);
}
-
+ @Test
public void testChangeTypeStringToBool() {
Cell cell = createACell();
@@ -305,6 +318,7 @@ public abstract class BaseTestCell exten
assertEquals("FALSE", cell.getRichStringCellValue().getString());
}
+ @Test
public void testChangeTypeBoolToString() {
Cell cell = createACell();
@@ -321,6 +335,7 @@ public abstract class BaseTestCell exten
assertEquals("TRUE", cell.getRichStringCellValue().getString());
}
+ @Test
public void testChangeTypeErrorToNumber() {
Cell cell = createACell();
cell.setCellErrorValue((byte)ErrorConstants.ERROR_NAME);
@@ -332,6 +347,7 @@ public abstract class BaseTestCell exten
assertEquals(2.5, cell.getNumericCellValue(), 0.0);
}
+ @Test
public void testChangeTypeErrorToBoolean() {
Cell cell = createACell();
cell.setCellErrorValue((byte)ErrorConstants.ERROR_NAME);
@@ -353,6 +369,7 @@ public abstract class BaseTestCell exten
* {@link FormulaEvaluator#evaluateInCell(Cell)} with a
* string result type.
*/
+ @Test
public void testConvertStringFormulaCell() {
Cell cellA1 = createACell();
cellA1.setCellFormula("\"abc\"");
@@ -371,10 +388,12 @@ public abstract class BaseTestCell exten
}
assertEquals("abc", cellA1.getStringCellValue());
}
+
/**
* similar to {@link #testConvertStringFormulaCell()} but checks at a
* lower level that {#link {@link Cell#setCellType(int)} works properly
*/
+ @Test
public void testSetTypeStringOnFormulaCell() {
Cell cellA1 = createACell();
FormulaEvaluator fe = cellA1.getSheet().getWorkbook().getCreationHelper().createFormulaEvaluator();
@@ -418,6 +437,7 @@ public abstract class BaseTestCell exten
/**
* Test for bug in convertCellValueToBoolean to make sure that formula results get converted
*/
+ @Test
public void testChangeTypeFormulaToBoolean() {
Cell cell = createACell();
cell.setCellFormula("1=1");
@@ -433,6 +453,7 @@ public abstract class BaseTestCell exten
* Bug 40296: HSSFCell.setCellFormula throws
* ClassCastException if cell is created using HSSFRow.createCell(short column, int type)
*/
+ @Test
public void test40296() {
Workbook wb = _testDataProvider.createWorkbook();
Sheet workSheet = wb.createSheet("Sheet1");
@@ -470,6 +491,7 @@ public abstract class BaseTestCell exten
assertEquals("SUM(A1:B1)", cell.getCellFormula());
}
+ @Test
public void testSetStringInFormulaCell_bug44606() {
Workbook wb = _testDataProvider.createWorkbook();
Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0);
@@ -484,7 +506,8 @@ public abstract class BaseTestCell exten
/**
* Make sure that cell.setCellType(Cell.CELL_TYPE_BLANK) preserves the cell style
*/
- public void testSetBlank_bug47028() {
+ @Test
+ public void testSetBlank_bug47028() {
Workbook wb = _testDataProvider.createWorkbook();
CellStyle style = wb.createCellStyle();
Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0);
@@ -514,7 +537,8 @@ public abstract class BaseTestCell exten
* </li>
* </ul>
*/
- public void testNanAndInfinity() {
+ @Test
+ public void testNanAndInfinity() {
Workbook wb = _testDataProvider.createWorkbook();
Sheet workSheet = wb.createSheet("Sheet1");
Row row = workSheet.createRow(0);
@@ -550,7 +574,8 @@ public abstract class BaseTestCell exten
assertEquals(ErrorConstants.ERROR_DIV_0, cell2.getErrorCellValue());
}
- public void testDefaultStyleProperties() {
+ @Test
+ public void testDefaultStyleProperties() {
Workbook wb = _testDataProvider.createWorkbook();
Cell cell = wb.createSheet("Sheet1").createRow(0).createCell(0);
@@ -584,7 +609,8 @@ public abstract class BaseTestCell exten
assertFalse(style2.getHidden());
}
- public void testBug55658SetNumericValue(){
+ @Test
+ public void testBug55658SetNumericValue(){
Workbook wb = _testDataProvider.createWorkbook();
Sheet sh = wb.createSheet();
Row row = sh.createRow(0);
@@ -604,7 +630,8 @@ public abstract class BaseTestCell exten
assertEquals("24", wb.getSheetAt(0).getRow(0).getCell(1).getStringCellValue());
}
- public void testRemoveHyperlink(){
+ @Test
+ public void testRemoveHyperlink(){
Workbook wb = _testDataProvider.createWorkbook();
Sheet sh = wb.createSheet("test");
Row row = sh.createRow(0);
@@ -646,7 +673,8 @@ public abstract class BaseTestCell exten
* an problem that cell could not return error value form formula cell).
* @throws IOException
*/
- public void testGetErrorCellValueFromFormulaCell() throws IOException {
+ @Test
+ public void testGetErrorCellValueFromFormulaCell() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
try {
Sheet sheet = wb.createSheet();
@@ -660,7 +688,8 @@ public abstract class BaseTestCell exten
}
}
- public void testSetRemoveStyle() throws Exception {
+ @Test
+ public void testSetRemoveStyle() throws Exception {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
Row row = sheet.createRow(0);
@@ -699,6 +728,7 @@ public abstract class BaseTestCell exten
wb.close();
}
+ @Test
public void test57008() throws IOException {
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
@@ -740,6 +770,7 @@ public abstract class BaseTestCell exten
* The maximum length of cell contents (text) is 32,767 characters.
* @throws IOException
*/
+ @Test
public void testMaxTextLength() throws IOException{
Workbook wb = _testDataProvider.createWorkbook();
Sheet sheet = wb.createSheet();
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/BaseTestSheetAutosizeColumn.java Mon Sep 7 20:19:50 2015
@@ -17,15 +17,20 @@
package org.apache.poi.ss.usermodel;
-import static org.junit.Assert.*;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Calendar;
+import java.util.Locale;
import org.apache.poi.ss.ITestDataProvider;
import org.apache.poi.ss.util.CellRangeAddress;
import org.apache.poi.util.JvmBugs;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
import org.junit.Test;
-import java.util.Calendar;
-
/**
* Common superclass for testing automatic sizing of sheet columns
*
@@ -35,12 +40,25 @@ public abstract class BaseTestSheetAutos
private final ITestDataProvider _testDataProvider;
+ private static Locale userLocale;
+
+ @BeforeClass
+ public static void initLocale() {
+ userLocale = LocaleUtil.getUserLocale();
+ LocaleUtil.setUserLocale(Locale.ROOT);
+ }
+
+ @AfterClass
+ public static void resetLocale() {
+ LocaleUtil.setUserLocale(userLocale);
+ }
+
protected BaseTestSheetAutosizeColumn(ITestDataProvider testDataProvider) {
_testDataProvider = testDataProvider;
}
@Test
- public void numericCells(){
+ public void numericCells() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
fixFonts(workbook);
DataFormat df = workbook.getCreationHelper().createDataFormat();
@@ -77,10 +95,12 @@ public abstract class BaseTestSheetAutos
assertEquals(sheet.getColumnWidth(1), sheet.getColumnWidth(2)); // columns 1, 2 and 3 should have the same width
assertEquals(sheet.getColumnWidth(2), sheet.getColumnWidth(3)); // columns 1, 2 and 3 should have the same width
assertEquals(sheet.getColumnWidth(4), sheet.getColumnWidth(5)); // 10.0000 and '10.0000'
+
+ workbook.close();
}
@Test
- public void booleanCells(){
+ public void booleanCells() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
fixFonts(workbook);
Sheet sheet = workbook.createSheet();
@@ -106,10 +126,12 @@ public abstract class BaseTestSheetAutos
assertTrue(sheet.getColumnWidth(1) > sheet.getColumnWidth(0)); // 'true' is wider than '0'
assertEquals(sheet.getColumnWidth(1), sheet.getColumnWidth(2)); // columns 1, 2 and 3 should have the same width
assertEquals(sheet.getColumnWidth(2), sheet.getColumnWidth(3)); // columns 1, 2 and 3 should have the same width
+
+ workbook.close();
}
@Test
- public void dateCells(){
+ public void dateCells() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
fixFonts(workbook);
Sheet sheet = workbook.createSheet();
@@ -124,8 +146,7 @@ public abstract class BaseTestSheetAutos
CellStyle style5 = workbook.createCellStyle(); //rotated text
style5.setDataFormat(df.getFormat("mmm/dd/yyyy"));
- Calendar calendar = Calendar.getInstance();
- calendar.set(2010, 0, 1); // Jan 1 2010
+ Calendar calendar = LocaleUtil.getLocaleCalendar(2010, 0, 1); // Jan 1 2010
Row row = sheet.createRow(0);
row.createCell(0).setCellValue(DateUtil.getJavaDate(0)); //default date
@@ -172,10 +193,12 @@ public abstract class BaseTestSheetAutos
assertTrue(sheet.getColumnWidth(5) > sheet.getColumnWidth(3)); // 'mmm/dd/yyyy' is wider than 'mmm'
assertEquals(sheet.getColumnWidth(6), sheet.getColumnWidth(5)); // date formatted as 'mmm/dd/yyyy'
assertEquals(sheet.getColumnWidth(4), sheet.getColumnWidth(7)); // date formula formatted as 'mmm'
+
+ workbook.close();
}
@Test
- public void stringCells(){
+ public void stringCells() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
fixFonts(workbook);
Sheet sheet = workbook.createSheet();
@@ -205,10 +228,12 @@ public abstract class BaseTestSheetAutos
assertEquals(sheet.getColumnWidth(4), sheet.getColumnWidth(3));
boolean ignoreFontSizeX2 = JvmBugs.hasLineBreakMeasurerBug();
assertTrue(ignoreFontSizeX2 || sheet.getColumnWidth(5) > sheet.getColumnWidth(4)); //larger font results in a wider column width
+
+ workbook.close();
}
@Test
- public void rotatedText(){
+ public void rotatedText() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
fixFonts(workbook);
Sheet sheet = workbook.createSheet();
@@ -230,10 +255,12 @@ public abstract class BaseTestSheetAutos
int w1 = sheet.getColumnWidth(1);
assertTrue(w0*5 < w1); // rotated text occupies at least five times less horizontal space than normal text
+
+ workbook.close();
}
@Test
- public void mergedCells(){
+ public void mergedCells() throws Exception {
Workbook workbook = _testDataProvider.createWorkbook();
fixFonts(workbook);
Sheet sheet = workbook.createSheet();
@@ -251,6 +278,8 @@ public abstract class BaseTestSheetAutos
sheet.autoSizeColumn(0, true);
assertTrue(sheet.getColumnWidth(0) > defaulWidth);
+
+ workbook.close();
}
@@ -293,6 +322,8 @@ public abstract class BaseTestSheetAutos
Row r60708 = sheet.createRow(60708);
r60708.createCell(0).setCellValue("Near the end");
sheet.autoSizeColumn(0);
+
+ workbook.close();
}
// TODO should we have this stuff in the FormulaEvaluator?
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java Mon Sep 7 20:19:50 2015
@@ -21,16 +21,22 @@
package org.apache.poi.ss.usermodel;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
import java.text.DateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;
-import junit.framework.TestCase;
-
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.apache.poi.hssf.usermodel.TestHSSFDataFormatter;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Ignore;
+import org.junit.Test;
/**
* Tests of {@link DataFormatter}
@@ -38,13 +44,14 @@ import org.apache.poi.hssf.usermodel.Tes
* See {@link TestHSSFDataFormatter} too for
* more tests.
*/
-public class TestDataFormatter extends TestCase {
+public class TestDataFormatter {
private static final double _15_MINUTES = 0.041666667;
/**
* Test that we use the specified locale when deciding
* how to format normal numbers
*/
+ @Test
public void testLocale() {
DataFormatter dfUS = new DataFormatter(Locale.US);
DataFormatter dfFR = new DataFormatter(Locale.FRENCH);
@@ -61,6 +68,7 @@ public class TestDataFormatter extends T
* a specific locale, but we should format things as if
* the locale (eg '[$-1010409]') isn't there
*/
+ @Test
public void testLocaleBasedFormats() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -78,6 +86,7 @@ public class TestDataFormatter extends T
* Ensure that colours get correctly
* zapped from within the format strings
*/
+ @Test
public void testColours() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -105,6 +114,7 @@ public class TestDataFormatter extends T
assertEquals("[ab]12.34[x]", dfUS.formatRawCellContents(12.343, -1, "[ab]##.##[x]"));
}
+ @Test
public void testColoursAndBrackets() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -149,6 +159,7 @@ public class TestDataFormatter extends T
* and Excel differ, and workarounds are not
* yet in place for all of these
*/
+ @Test
public void testNegativeZero() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -193,6 +204,7 @@ public class TestDataFormatter extends T
* Test that we correctly handle fractions in the
* format string, eg # #/#
*/
+ @Test
public void testFractions() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -262,6 +274,7 @@ public class TestDataFormatter extends T
* and *x (fill to the column width with "x"s) are
* correctly ignored by us.
*/
+ @Test
public void testPaddingSpaces() {
DataFormatter dfUS = new DataFormatter(Locale.US);
assertEquals("12.34", dfUS.formatRawCellContents(12.343, -1, "##.##_ "));
@@ -278,6 +291,7 @@ public class TestDataFormatter extends T
/**
* DataFormatter is the CSV mode preserves spaces
*/
+ @Test
public void testPaddingSpacesCSV() {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
assertEquals("12.34 ", dfUS.formatRawCellContents(12.343, -1, "##.##_ "));
@@ -311,12 +325,11 @@ public class TestDataFormatter extends T
* Test that the special Excel month format MMMMM
* gets turned into the first letter of the month
*/
+ @Test
public void testMMMMM() {
DataFormatter dfUS = new DataFormatter(Locale.US);
- Calendar c = Calendar.getInstance();
- c.set(Calendar.MILLISECOND, 0);
- c.set(2010, 5, 1, 2, 0, 0);
+ Calendar c = LocaleUtil.getLocaleCalendar(2010, 5, 1, 2, 0, 0);
assertEquals("2010-J-1 2:00:00", dfUS.formatRawCellContents(
DateUtil.getExcelDate(c, false), -1, "YYYY-MMMMM-D h:mm:ss"
@@ -326,6 +339,7 @@ public class TestDataFormatter extends T
/**
* Tests that we do AM/PM handling properly
*/
+ @Test
public void testAMPM() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -343,6 +357,7 @@ public class TestDataFormatter extends T
* Test that we can handle elapsed time,
* eg formatting 1 day 4 hours as 28 hours
*/
+ @Test
public void testElapsedTime() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -447,6 +462,7 @@ public class TestDataFormatter extends T
}
}
+ @Test
public void testDateWindowing() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -455,6 +471,7 @@ public class TestDataFormatter extends T
assertEquals("1904-01-01 00:00:00", dfUS.formatRawCellContents(0.0, -1, "yyyy-mm-dd hh:mm:ss", true));
}
+ @Test
public void testScientificNotation() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -463,6 +480,7 @@ public class TestDataFormatter extends T
assertEquals("0.00E+00", dfUS.formatRawCellContents(0.0, -1, "0.00E+00"));
}
+ @Test
public void testInvalidDate() {
DataFormatter df1 = new DataFormatter(Locale.US);
assertEquals("-1.0", df1.formatRawCellContents(-1, -1, "mm/dd/yyyy"));
@@ -472,6 +490,7 @@ public class TestDataFormatter extends T
df2.formatRawCellContents(-1, -1, "mm/dd/yyyy"));
}
+ @Test
public void testEscapes() {
DataFormatter dfUS = new DataFormatter(Locale.US);
@@ -485,6 +504,7 @@ public class TestDataFormatter extends T
assertEquals("1901/01/01", dfUS.formatRawCellContents(367.0, -1, "yyyy\\/mm\\/dd"));
}
+ @Test
public void testOther() {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
@@ -494,6 +514,7 @@ public class TestDataFormatter extends T
assertEquals(" $- ", dfUS.formatRawCellContents(0.0, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-"));
}
+ @Test
public void testErrors() throws IOException {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
@@ -519,6 +540,7 @@ public class TestDataFormatter extends T
* the start of a format string to format it differently, we
* should at least handle it as it if wasn't there
*/
+ @Test
public void testDatesWithLocales() {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
@@ -543,7 +565,9 @@ public class TestDataFormatter extends T
/**
* TODO Fix these so that they work
*/
- public void DISABLEDtestCustomFormats() {
+ @Test
+ @Ignore
+ public void testCustomFormats() {
DataFormatter dfUS = new DataFormatter(Locale.US, true);
String fmt;
@@ -560,6 +584,7 @@ public class TestDataFormatter extends T
/**
* ExcelStyleDateFormatter should work for Milliseconds too
*/
+ @Test
public void testExcelStyleDateFormatterStringOnMillis() {
// Test directly with the .000 style
DateFormat formatter1 = new ExcelStyleDateFormatter("ss.000");
@@ -589,7 +614,8 @@ public class TestDataFormatter extends T
assertEquals("01.010", dfUS.formatRawCellContents(0.0000116898, -1, "ss.000"));
}
- public void testBug54786() {
+ @Test
+ public void testBug54786() {
DataFormatter formatter = new DataFormatter();
String format = "[h]\"\"h\"\" m\"\"m\"\"";
assertTrue(DateUtil.isADateFormat(-1,format));
@@ -613,7 +639,8 @@ public class TestDataFormatter extends T
}
}
- public void testIsADateFormat() {
+ @Test
+ public void testIsADateFormat() {
// first check some cases that should not be a date, also call multiple times to ensure the cache is used
assertFalse(DateUtil.isADateFormat(-1, null));
assertFalse(DateUtil.isADateFormat(-1, null));
Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDateUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDateUtil.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDateUtil.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDateUtil.java Mon Sep 7 20:19:50 2015
@@ -23,6 +23,7 @@ import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
+import org.apache.poi.util.LocaleUtil;
import org.junit.Test;
public class TestDateUtil {
@@ -30,7 +31,7 @@ public class TestDateUtil {
@Test
public void getJavaDate_InvalidValue() {
double dateValue = -1;
- TimeZone tz = TimeZone.getDefault();
+ TimeZone tz = LocaleUtil.getUserTimeZone();
boolean use1904windowing = false;
boolean roundSeconds = false;
@@ -44,13 +45,11 @@ public class TestDateUtil {
@Test
public void getJavaDate_ValidValue() {
double dateValue = 0;
- TimeZone tz = TimeZone.getDefault();
+ TimeZone tz = LocaleUtil.getUserTimeZone();
boolean use1904windowing = false;
boolean roundSeconds = false;
- Calendar calendar = Calendar.getInstance(tz);
- calendar.set(1900, 0, 0, 0, 0, 0);
- calendar.set(Calendar.MILLISECOND, 0);
+ Calendar calendar = LocaleUtil.getLocaleCalendar(1900, 0, 0);
Date date = calendar.getTime();
assertEquals(date, DateUtil.getJavaDate(dateValue));
@@ -63,7 +62,7 @@ public class TestDateUtil {
@Test
public void getJavaCalendar_InvalidValue() {
double dateValue = -1;
- TimeZone tz = TimeZone.getDefault();
+ TimeZone tz = LocaleUtil.getUserTimeZone();
boolean use1904windowing = false;
boolean roundSeconds = false;
@@ -76,17 +75,21 @@ public class TestDateUtil {
@Test
public void getJavaCalendar_ValidValue() {
double dateValue = 0;
- TimeZone tz = TimeZone.getDefault();
+ TimeZone tz = LocaleUtil.getUserTimeZone();
boolean use1904windowing = false;
boolean roundSeconds = false;
- Calendar calendar = Calendar.getInstance(tz);
- calendar.set(1900, 0, 0, 0, 0, 0);
- calendar.set(Calendar.MILLISECOND, 0);
-
- assertEquals(calendar, DateUtil.getJavaCalendar(dateValue));
- assertEquals(calendar, DateUtil.getJavaCalendar(dateValue, use1904windowing));
- assertEquals(calendar, DateUtil.getJavaCalendar(dateValue, use1904windowing, tz));
- assertEquals(calendar, DateUtil.getJavaCalendar(dateValue, use1904windowing, tz, roundSeconds));
+ Calendar expCal = LocaleUtil.getLocaleCalendar(1900, 0, 0);
+
+ Calendar actCal[] = {
+ DateUtil.getJavaCalendar(dateValue),
+ DateUtil.getJavaCalendar(dateValue, use1904windowing),
+ DateUtil.getJavaCalendar(dateValue, use1904windowing, tz),
+ DateUtil.getJavaCalendar(dateValue, use1904windowing, tz, roundSeconds)
+ };
+ assertEquals(expCal, actCal[0]);
+ assertEquals(expCal, actCal[1]);
+ assertEquals(expCal, actCal[2]);
+ assertEquals(expCal, actCal[3]);
}
}
Modified: poi/trunk/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/util/TestDateFormatConverter.java Mon Sep 7 20:19:50 2015
@@ -69,7 +69,7 @@ public final class TestDateFormatConvert
Row row = sheet.createRow(rowNum++);
row.createCell(0).setCellValue(locale.toString());
- row.createCell(1).setCellValue(locale.getDisplayName());
+ row.createCell(1).setCellValue(locale.getDisplayName(Locale.ROOT));
DateFormat dateFormat;
if( dates ) {
Modified: poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/util/TestHexDump.java Mon Sep 7 20:19:50 2015
@@ -134,7 +134,7 @@ public final class TestHexDump {
obj[17] = chrs.toString();
format.append("%18$s"+HexDump.EOL);
- String str = String.format(format.toString(), obj);
+ String str = String.format(LocaleUtil.getUserLocale(), format.toString(), obj);
strExp.append(str);
}
byte bytesExp[] = strExp.toString().getBytes(HexDump.UTF8);
Modified: poi/trunk/src/testcases/org/apache/poi/util/TestStringUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/util/TestStringUtil.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/util/TestStringUtil.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/util/TestStringUtil.java Mon Sep 7 20:19:50 2015
@@ -144,7 +144,7 @@ public final class TestStringUtil extend
}
private static String fmt(double num, int minIntDigits, int maxFracDigitis) {
- NumberFormat nf = NumberFormat.getInstance();
+ NumberFormat nf = NumberFormat.getInstance(LocaleUtil.getUserLocale());
if (minIntDigits != -1) {
nf.setMinimumIntegerDigits(minIntDigits);
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org