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 [6/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/format/TestCellFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormat.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormat.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/format/TestCellFormat.java Mon Sep  7 20:19:50 2015
@@ -16,23 +16,45 @@
 ==================================================================== */
 package org.apache.poi.ss.format;
 
+import static org.junit.Assert.assertEquals;
+
 import java.io.IOException;
 import java.text.ParseException;
 import java.text.SimpleDateFormat;
 import java.util.Date;
+import java.util.Locale;
+import java.util.TimeZone;
 
 import javax.swing.JLabel;
 
-import junit.framework.TestCase;
-
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
 import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.DateUtil;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
 import org.apache.poi.ss.usermodel.Workbook;
-
-public class TestCellFormat extends TestCase {
+import org.apache.poi.util.LocaleUtil;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class TestCellFormat {
+    
+    private static TimeZone userTimeZone;
+    
+    @BeforeClass
+    public static void setTimeZone() {
+        userTimeZone = LocaleUtil.getUserTimeZone();
+        LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("CET"));
+        LocaleUtil.setUserLocale(Locale.US);
+    }
+    
+    @AfterClass
+    public static void resetTimeZone() {
+        LocaleUtil.setUserTimeZone(userTimeZone);
+        LocaleUtil.setUserLocale(Locale.ROOT);
+    }
+    
     
     private static final String _255_POUND_SIGNS;
     static {
@@ -43,6 +65,7 @@ public class TestCellFormat extends Test
         _255_POUND_SIGNS = sb.toString();
     }
     
+    @Test
     public void testSome() {
         JLabel l = new JLabel();
         CellFormat fmt = CellFormat.getInstance(
@@ -50,48 +73,56 @@ public class TestCellFormat extends Test
         fmt.apply(l, 1.1);
     }
     
+    @Test
     public void testPositiveFormatHasOnePart() {
         CellFormat fmt = CellFormat.getInstance("0.00");
         CellFormatResult result = fmt.apply(12.345);
         assertEquals("12.35", result.text);
     }
     
+    @Test
     public void testNegativeFormatHasOnePart() {
         CellFormat fmt = CellFormat.getInstance("0.00");
         CellFormatResult result = fmt.apply(-12.345);
         assertEquals("-12.35", result.text);
     }
     
+    @Test
     public void testZeroFormatHasOnePart() {
         CellFormat fmt = CellFormat.getInstance("0.00");
         CellFormatResult result = fmt.apply(0.0);
         assertEquals("0.00", result.text);
     }
     
+    @Test
     public void testPositiveFormatHasPosAndNegParts() {
         CellFormat fmt = CellFormat.getInstance("0.00;-0.00");
         CellFormatResult result = fmt.apply(12.345);
         assertEquals("12.35", result.text);
     }
     
+    @Test
     public void testNegativeFormatHasPosAndNegParts() {
         CellFormat fmt = CellFormat.getInstance("0.00;-0.00");
         CellFormatResult result = fmt.apply(-12.345);
         assertEquals("-12.35", result.text);
     }
 
+    @Test
     public void testNegativeFormatHasPosAndNegParts2() {
         CellFormat fmt = CellFormat.getInstance("0.00;(0.00)");
         CellFormatResult result = fmt.apply(-12.345);
         assertEquals("(12.35)", result.text);
     }
     
+    @Test
     public void testZeroFormatHasPosAndNegParts() {
         CellFormat fmt = CellFormat.getInstance("0.00;-0.00");
         CellFormatResult result = fmt.apply(0.0);
         assertEquals("0.00", result.text);
     }
 
+    @Test
     public void testFormatWithThreeSections() {
         CellFormat fmt = CellFormat.getInstance("0.00;-0.00;-");
         
@@ -101,6 +132,7 @@ public class TestCellFormat extends Test
         assertEquals("abc",    fmt.apply("abc").text);
     }
     
+    @Test
     public void testFormatWithFourSections() {
         CellFormat fmt = CellFormat.getInstance("0.00;-0.00;-; @ ");
         
@@ -110,7 +142,8 @@ public class TestCellFormat extends Test
         assertEquals(" abc ",  fmt.apply("abc").text);
     }
 
-    public void testApplyCellForGeneralFormat() {
+    @Test
+    public void testApplyCellForGeneralFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -147,9 +180,11 @@ public class TestCellFormat extends Test
         CellFormatResult result4 = cf.apply(cell4);
         assertEquals("abc", result4.text);
         
+        wb.close();
     }
     
-    public void testApplyCellForAtFormat() {
+    @Test
+    public void testApplyCellForAtFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -186,9 +221,11 @@ public class TestCellFormat extends Test
         CellFormatResult result4 = cf.apply(cell4);
         assertEquals("abc", result4.text);
         
+        wb.close();
     }
     
-    public void testApplyCellForDateFormat() {
+    @Test
+    public void testApplyCellForDateFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -207,9 +244,11 @@ public class TestCellFormat extends Test
         CellFormatResult result1 = cf.apply(cell1);
         assertEquals(_255_POUND_SIGNS, result1.text);
         
+        wb.close();
     }
     
-    public void testApplyCellForTimeFormat() {
+    @Test
+    public void testApplyCellForTimeFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -223,9 +262,11 @@ public class TestCellFormat extends Test
         CellFormatResult result = cf.apply(cell);
         assertEquals("03:04", result.text);
         
+        wb.close();
     }
     
-   public void testApplyCellForDateFormatAndNegativeFormat() {
+    @Test
+    public void testApplyCellForDateFormatAndNegativeFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -244,9 +285,11 @@ public class TestCellFormat extends Test
         CellFormatResult result1 = cf.apply(cell1);
         assertEquals("(1)", result1.text);
         
+        wb.close();
     }
     
-    public void testApplyJLabelCellForGeneralFormat() {
+    @Test
+    public void testApplyJLabelCellForGeneralFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -294,9 +337,11 @@ public class TestCellFormat extends Test
         assertEquals("abc", result4.text);
         assertEquals("abc", label4.getText());
         
+        wb.close();
     }
     
-    public void testApplyJLabelCellForAtFormat() {
+    @Test
+    public void testApplyJLabelCellForAtFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -344,9 +389,11 @@ public class TestCellFormat extends Test
         assertEquals("abc", result4.text);
         assertEquals("abc", label4.getText());
         
+        wb.close();
     }
 
-    public void testApplyJLabelCellForDateFormat() {
+    @Test
+    public void testApplyJLabelCellForDateFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -370,9 +417,11 @@ public class TestCellFormat extends Test
         assertEquals(_255_POUND_SIGNS, result1.text);
         assertEquals(_255_POUND_SIGNS, label1.getText());
         
+        wb.close();
     }
 
-    public void testApplyJLabelCellForTimeFormat() {
+    @Test
+    public void testApplyJLabelCellForTimeFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -389,9 +438,11 @@ public class TestCellFormat extends Test
         assertEquals("03:04", result.text);
         assertEquals("03:04", label.getText());
         
+        wb.close();
     }
     
-    public void testApplyJLabelCellForDateFormatAndNegativeFormat() {
+    @Test
+    public void testApplyJLabelCellForDateFormatAndNegativeFormat() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -415,9 +466,11 @@ public class TestCellFormat extends Test
         assertEquals("(1)", result1.text);
         assertEquals("(1)", label1.getText());
         
+        wb.close();
     }
 
-    public void testApplyFormatHasOnePartAndPartHasCondition() {
+    @Test
+    public void testApplyFormatHasOnePartAndPartHasCondition() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -442,9 +495,11 @@ public class TestCellFormat extends Test
         cell.setCellValue("abc");
         assertEquals("abc", cf.apply(cell).text);
         
+        wb.close();
     }
     
-    public void testApplyFormatHasTwoPartsFirstHasCondition() {
+    @Test
+    public void testApplyFormatHasTwoPartsFirstHasCondition() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -475,9 +530,11 @@ public class TestCellFormat extends Test
         cell.setCellValue("TRUE");
         assertEquals("TRUE", cf.apply(cell).text);
         
+        wb.close();
     }
     
-    public void testApplyFormatHasTwoPartsBothHaveCondition() {
+    @Test
+    public void testApplyFormatHasTwoPartsBothHaveCondition() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -505,9 +562,11 @@ public class TestCellFormat extends Test
         cell.setCellValue("abc");
         assertEquals("abc", cf.apply(cell).text);
         
+        wb.close();
     }
     
-    public void testApplyFormatHasThreePartsFirstHasCondition() {
+    @Test
+    public void testApplyFormatHasThreePartsFirstHasCondition() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -537,9 +596,11 @@ public class TestCellFormat extends Test
         cell.setCellValue("abc");
         assertEquals("abc", cf.apply(cell).text);
         
+        wb.close();
     }
     
-    public void testApplyFormatHasThreePartsFirstTwoHaveCondition() {
+    @Test
+    public void testApplyFormatHasThreePartsFirstTwoHaveCondition() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -564,9 +625,11 @@ public class TestCellFormat extends Test
         cell.setCellValue("abc");
         assertEquals("abc", cf.apply(cell).text);
         
+        wb.close();
     }
 
-    public void testApplyFormatHasThreePartsFirstIsDateFirstTwoHaveCondition() {
+    @Test
+    public void testApplyFormatHasThreePartsFirstIsDateFirstTwoHaveCondition() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -591,9 +654,11 @@ public class TestCellFormat extends Test
         cell.setCellValue("abc");
         assertEquals("abc", cf.apply(cell).text);
         
+        wb.close();
     }
 
-    public void testApplyFormatHasTwoPartsFirstHasConditionSecondIsGeneral() {
+    @Test
+    public void testApplyFormatHasTwoPartsFirstHasConditionSecondIsGeneral() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -618,9 +683,11 @@ public class TestCellFormat extends Test
         cell.setCellValue("abc");
         assertEquals("abc", cf.apply(cell).text);
         
+        wb.close();
     }
 
-    public void testApplyFormatHasThreePartsFirstTwoHaveConditionThirdIsGeneral() {
+    @Test
+    public void testApplyFormatHasThreePartsFirstTwoHaveConditionThirdIsGeneral() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -645,9 +712,11 @@ public class TestCellFormat extends Test
         cell.setCellValue("abc");
         assertEquals("abc", cf.apply(cell).text);
         
+        wb.close();
     }
     
-    public void testApplyFormatHasFourPartsFirstHasCondition() {
+    @Test
+    public void testApplyFormatHasFourPartsFirstHasCondition() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -677,9 +746,11 @@ public class TestCellFormat extends Test
         cell.setCellValue("abc");
         assertEquals("~~abc~~", cf.apply(cell).text);
         
+        wb.close();
     }
     
-    public void testApplyFormatHasFourPartsSecondHasCondition() {
+    @Test
+    public void testApplyFormatHasFourPartsSecondHasCondition() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -710,9 +781,11 @@ public class TestCellFormat extends Test
         cell.setCellValue(true);
         assertEquals("~~TRUE~~", cf.apply(cell).text);
         
+        wb.close();
     }
 
-    public void testApplyFormatHasFourPartsFirstTwoHaveCondition() {
+    @Test
+    public void testApplyFormatHasFourPartsFirstTwoHaveCondition() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -739,11 +812,14 @@ public class TestCellFormat extends Test
         
         cell.setCellValue(true);
         assertEquals("~~TRUE~~", cf.apply(cell).text);
+        
+        wb.close();
     }
     
     /*
      * Test apply(Object value) with a number as parameter
      */
+    @Test
     public void testApplyObjectNumber() {
         
         CellFormat cf1 = CellFormat.getInstance("0.000");
@@ -771,15 +847,17 @@ public class TestCellFormat extends Test
     /*
      * Test apply(Object value) with a Date as parameter
      */
+    @Test
     public void testApplyObjectDate() throws ParseException {
         
         CellFormat cf1 = CellFormat.getInstance("m/d/yyyy");
-        Date date1 = new SimpleDateFormat("M/d/y").parse("01/11/2012");
+        Date date1 = new SimpleDateFormat("M/d/y", Locale.ROOT).parse("01/11/2012");
         assertEquals("1/11/2012", cf1.apply(date1).text);
         
     }
 
-    public void testApplyCellForDateFormatWithConditions() {
+    @Test
+    public void testApplyCellForDateFormatWithConditions() throws Exception {
         
         // Create a workbook, row and cell to test with
         Workbook wb = new HSSFWorkbook();
@@ -798,11 +876,13 @@ public class TestCellFormat extends Test
         cell.setCellValue(-1);
         assertEquals(_255_POUND_SIGNS, cf.apply(cell).text);
         
+        wb.close();
     }
     
     /*
      * Test apply(Object value) with a String as parameter
      */
+    @Test
     public void testApplyObjectString() {
         
         CellFormat cf = CellFormat.getInstance("0.00");
@@ -814,6 +894,7 @@ public class TestCellFormat extends Test
     /*
      * Test apply(Object value) with a Boolean as parameter
      */
+    @Test
     public void testApplyObjectBoolean() {
         
         CellFormat cf1 = CellFormat.getInstance("0");
@@ -826,6 +907,7 @@ public class TestCellFormat extends Test
         
     }
     
+    @Test
     public void testSimpleFractionFormat() throws IOException {
         CellFormat cf1 = CellFormat.getInstance("# ?/?");
         // Create a workbook, row and cell to test with

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestDateParser.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestDateParser.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestDateParser.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestDateParser.java Mon Sep  7 20:19:50 2015
@@ -17,21 +17,18 @@
 
 package org.apache.poi.ss.formula.atp;
 
-import static java.util.Calendar.OCTOBER;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
 
 import java.util.Calendar;
-import java.util.Date;
-
-import junit.framework.TestCase;
 
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.EvaluationException;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
 
-/**
- * @author jfaenomoto@gmail.com
- */
-public class TestDateParser extends TestCase {
-
+public class TestDateParser {
+    @Test
     public void testFailWhenNoDate() {
         try {
             DateParser.parseDate("potato");
@@ -41,6 +38,7 @@ public class TestDateParser extends Test
         }
     }
 
+    @Test
     public void testFailWhenLooksLikeDateButItIsnt() {
         try {
             DateParser.parseDate("potato/cucumber/banana");
@@ -50,6 +48,7 @@ public class TestDateParser extends Test
         }
     }
 
+    @Test
     public void testFailWhenIsInvalidDate() {
         try {
             DateParser.parseDate("13/13/13");
@@ -59,18 +58,18 @@ public class TestDateParser extends Test
         }
     }
 
-    @SuppressWarnings("deprecation")
+    @Test
     public void testShouldParseValidDate() throws EvaluationException {
-        Calendar aDate = Calendar.getInstance();
-        aDate.setTime(new Date(84, OCTOBER, 20));
-        assertEquals(aDate, DateParser.parseDate("1984/10/20"));
+        Calendar expDate = LocaleUtil.getLocaleCalendar(1984, Calendar.OCTOBER, 20);
+        Calendar actDate = DateParser.parseDate("1984/10/20");
+        assertEquals(expDate, actDate);
     }
 
-    @SuppressWarnings("deprecation")
+    @Test
     public void testShouldIgnoreTimestamp() throws EvaluationException {
-        Calendar aDate = Calendar.getInstance();
-        aDate.setTime(new Date(84, OCTOBER, 20));
-        assertEquals(aDate, DateParser.parseDate("1984/10/20 12:34:56"));
+        Calendar expDate = LocaleUtil.getLocaleCalendar(1984, Calendar.OCTOBER, 20);
+        Calendar actDate = DateParser.parseDate("1984/10/20 12:34:56");
+        assertEquals(expDate, actDate);
     }
 
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestNetworkdaysFunction.java Mon Sep  7 20:19:50 2015
@@ -17,21 +17,12 @@
 
 package org.apache.poi.ss.formula.atp;
 
-import static java.util.Calendar.DECEMBER;
-import static java.util.Calendar.JANUARY;
-import static java.util.Calendar.MARCH;
-import static java.util.Calendar.NOVEMBER;
-import static java.util.Calendar.OCTOBER;
 import static org.apache.poi.ss.formula.eval.ErrorEval.NAME_INVALID;
 import static org.apache.poi.ss.formula.eval.ErrorEval.VALUE_INVALID;
 
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
-import java.util.Date;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.apache.poi.ss.formula.OperationEvaluationContext;
 import org.apache.poi.ss.formula.TwoDEval;
 import org.apache.poi.ss.formula.eval.AreaEval;
@@ -40,23 +31,15 @@ import org.apache.poi.ss.formula.eval.Nu
 import org.apache.poi.ss.formula.eval.StringEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
 
-/**
- * @author jfaenomoto@gmail.com
- */
-@SuppressWarnings("deprecation") // YK: uses deprecated {@link java.util.Date(int year, int month, int date)}
-public class TestNetworkdaysFunction extends TestCase {
-
-    private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
-
-    private static final String STARTING_DATE = formatter.format(new Date(108, OCTOBER, 1));
-
-    private static final String END_DATE = formatter.format(new Date(109, MARCH, 1));
-
-    private static final String FIRST_HOLIDAY = formatter.format(new Date(108, NOVEMBER, 26));
+import junit.framework.TestCase;
 
-    private static final String SECOND_HOLIDAY = formatter.format(new Date(108, DECEMBER, 4));
+public class TestNetworkdaysFunction extends TestCase {
 
-    private static final String THIRD_HOLIDAY = formatter.format(new Date(109, JANUARY, 21));
+    private static final String STARTING_DATE = "2008/10/01";
+    private static final String END_DATE = "2009/03/01";
+    private static final String FIRST_HOLIDAY = "2008/11/26";
+    private static final String SECOND_HOLIDAY = "2008/12/04";
+    private static final String THIRD_HOLIDAY = "2009/01/21";
 
     private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 1, 1, 1, null);
 

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayCalculator.java Mon Sep  7 20:19:50 2015
@@ -17,87 +17,100 @@
 
 package org.apache.poi.ss.formula.atp;
 
-import static java.util.Calendar.DECEMBER;
 import static java.util.Calendar.SATURDAY;
+import static org.junit.Assert.assertEquals;
 
+import java.util.Calendar;
 import java.util.Date;
 
-import junit.framework.TestCase;
-
 import org.apache.poi.ss.usermodel.DateUtil;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
 
-/**
- * @author jfaenomoto@gmail.com
- */
-@SuppressWarnings("deprecation") // YK: heavily uses deprecated {@link java.util.Date(int year, int month, int date)}
-public class TestWorkdayCalculator extends TestCase {
+public class TestWorkdayCalculator {
 
+    @Test
     public void testCalculateWorkdaysShouldReturnJustWeekdaysWhenNoWeekend() {
-        final double A_MONDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 12));
-        final double A_FRIDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 16));
+        final double A_MONDAY = DateUtil.getExcelDate(d(2011, 12, 12));
+        final double A_FRIDAY = DateUtil.getExcelDate(d(2011, 12, 16));
         assertEquals(5, WorkdayCalculator.instance.calculateWorkdays(A_MONDAY, A_FRIDAY, new double[0]));
     }
 
+    @Test
     public void testCalculateWorkdaysShouldReturnAllDaysButNoSaturdays() {
-        final double A_WEDNESDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 14));
-        final double A_SATURDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 18));
+        final double A_WEDNESDAY = DateUtil.getExcelDate(d(2011, 12, 14));
+        final double A_SATURDAY = DateUtil.getExcelDate(d(2011, 12, 18));
         assertEquals(3, WorkdayCalculator.instance.calculateWorkdays(A_WEDNESDAY, A_SATURDAY, new double[0]));
     }
 
+    @Test
     public void testCalculateWorkdaysShouldReturnAllDaysButNoSundays() {
-        final double A_SUNDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 11));
-        final double A_THURSDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 15));
+        final double A_SUNDAY = DateUtil.getExcelDate(d(2011, 12, 11));
+        final double A_THURSDAY = DateUtil.getExcelDate(d(2011, 12, 15));
         assertEquals(4, WorkdayCalculator.instance.calculateWorkdays(A_SUNDAY, A_THURSDAY, new double[0]));
     }
 
+    @Test
     public void testCalculateWorkdaysShouldReturnAllDaysButNoHolidays() {
-        final double A_MONDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 12));
-        final double A_FRIDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 16));
-        final double A_WEDNESDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 14));
+        final double A_MONDAY = DateUtil.getExcelDate(d(2011, 12, 12));
+        final double A_FRIDAY = DateUtil.getExcelDate(d(2011, 12, 16));
+        final double A_WEDNESDAY = DateUtil.getExcelDate(d(2011, 12, 14));
         assertEquals(4, WorkdayCalculator.instance.calculateWorkdays(A_MONDAY, A_FRIDAY, new double[]{ A_WEDNESDAY }));
     }
 
+    @Test
     public void testCalculateWorkdaysShouldIgnoreWeekendHolidays() {
-        final double A_FRIDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 16));
-        final double A_SATURDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 17));
-        final double A_SUNDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 18));
-        final double A_WEDNESDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 21));
+        final double A_FRIDAY = DateUtil.getExcelDate(d(2011, 12, 16));
+        final double A_SATURDAY = DateUtil.getExcelDate(d(2011, 12, 17));
+        final double A_SUNDAY = DateUtil.getExcelDate(d(2011, 12, 18));
+        final double A_WEDNESDAY = DateUtil.getExcelDate(d(2011, 12, 21));
         assertEquals(4, WorkdayCalculator.instance.calculateWorkdays(A_FRIDAY, A_WEDNESDAY, new double[]{ A_SATURDAY, A_SUNDAY }));
     }
 
+    @Test
     public void testCalculateWorkdaysNumberOfDays() {
     	double start = 41553.0;
     	int days = 1;
-        assertEquals(new Date(113, 9, 7), WorkdayCalculator.instance.calculateWorkdays(start, days, new double[0]));
+        assertEquals(d(2013, 10, 7), WorkdayCalculator.instance.calculateWorkdays(start, days, new double[0]));
     }
 
+    @Test
     public void testPastDaysOfWeekShouldReturn0Past0Saturdays() {
-        final double A_WEDNESDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 7));
-        final double A_FRIDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 9));
+        final double A_WEDNESDAY = DateUtil.getExcelDate(d(2011, 12, 7));
+        final double A_FRIDAY = DateUtil.getExcelDate(d(2011, 12, 9));
         assertEquals(0, WorkdayCalculator.instance.pastDaysOfWeek(A_WEDNESDAY, A_FRIDAY, SATURDAY));
     }
 
+    @Test
     public void testPastDaysOfWeekShouldReturn1Past1Saturdays() {
-        final double A_WEDNESDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 7));
-        final double A_SUNDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 11));
+        final double A_WEDNESDAY = DateUtil.getExcelDate(d(2011, 12, 7));
+        final double A_SUNDAY = DateUtil.getExcelDate(d(2011, 12, 11));
         assertEquals(1, WorkdayCalculator.instance.pastDaysOfWeek(A_WEDNESDAY, A_SUNDAY, SATURDAY));
     }
 
+    @Test
     public void testPastDaysOfWeekShouldReturn2Past2Saturdays() {
-        final double A_THURSDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 8));
-        final double A_MONDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 19));
+        final double A_THURSDAY = DateUtil.getExcelDate(d(2011, 12, 8));
+        final double A_MONDAY = DateUtil.getExcelDate(d(2011, 12, 19));
         assertEquals(2, WorkdayCalculator.instance.pastDaysOfWeek(A_THURSDAY, A_MONDAY, SATURDAY));
     }
 
+    @Test
     public void testPastDaysOfWeekShouldReturn1BeginningFromASaturday() {
-        final double A_SATURDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 10));
-        final double A_SUNDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 11));
+        final double A_SATURDAY = DateUtil.getExcelDate(d(2011, 12, 10));
+        final double A_SUNDAY = DateUtil.getExcelDate(d(2011, 12, 11));
         assertEquals(1, WorkdayCalculator.instance.pastDaysOfWeek(A_SATURDAY, A_SUNDAY, SATURDAY));
     }
 
+    @Test
     public void testPastDaysOfWeekShouldReturn1EndingAtASaturday() {
-        final double A_THURSDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 8));
-        final double A_SATURDAY = DateUtil.getExcelDate(new Date(111, DECEMBER, 10));
+        final double A_THURSDAY = DateUtil.getExcelDate(d(2011, 12, 8));
+        final double A_SATURDAY = DateUtil.getExcelDate(d(2011, 12, 10));
         assertEquals(1, WorkdayCalculator.instance.pastDaysOfWeek(A_THURSDAY, A_SATURDAY, SATURDAY));
     }
+    
+    private static Date d(int year, int month, int day) {
+        Calendar cal = LocaleUtil.getLocaleCalendar(year, month-1, day, 0, 0, 0);
+        return cal.getTime();
+    }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestWorkdayFunction.java Mon Sep  7 20:19:50 2015
@@ -18,17 +18,12 @@
 
 package org.apache.poi.ss.formula.atp;
 
-import static java.util.Calendar.APRIL;
-import static java.util.Calendar.DECEMBER;
-import static java.util.Calendar.JANUARY;
-import static java.util.Calendar.MAY;
-import static java.util.Calendar.NOVEMBER;
-import static java.util.Calendar.OCTOBER;
-import static java.util.Calendar.SEPTEMBER;
+
 import static org.apache.poi.ss.formula.eval.ErrorEval.VALUE_INVALID;
+import static org.junit.Assert.assertEquals;
 
-import java.text.SimpleDateFormat;
 import java.util.ArrayList;
+import java.util.Calendar;
 import java.util.Date;
 import java.util.List;
 
@@ -40,114 +35,140 @@ import org.apache.poi.ss.formula.eval.Nu
 import org.apache.poi.ss.formula.eval.StringEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.usermodel.DateUtil;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
 
-import junit.framework.TestCase;
-
-/**
- * @author jfaenomoto@gmail.com
- */
-@SuppressWarnings("deprecation") // YK: heavily uses deprecated {@link java.util.Date(int year, int month, int date)}
-public class TestWorkdayFunction extends TestCase {
-
-    private static final SimpleDateFormat formatter = new SimpleDateFormat("yyyy/MM/dd");
-
-    private static final String STARTING_DATE = formatter.format(new Date(108, OCTOBER, 1));
+public class TestWorkdayFunction {
 
-    private static final String FIRST_HOLIDAY = formatter.format(new Date(108, NOVEMBER, 26));
-
-    private static final String SECOND_HOLIDAY = formatter.format(new Date(108, DECEMBER, 4));
-
-    private static final String THIRD_HOLIDAY = formatter.format(new Date(109, JANUARY, 21));
-
-    private static final String RETROATIVE_HOLIDAY = formatter.format(new Date(108, SEPTEMBER, 29));
+    private static final String STARTING_DATE      = "2008/10/01";
+    private static final String FIRST_HOLIDAY      = "2008/11/26";
+    private static final String SECOND_HOLIDAY     = "2008/12/04";
+    private static final String THIRD_HOLIDAY      = "2009/01/21";
+    private static final String RETROATIVE_HOLIDAY = "2008/09/29";
 
     private static final OperationEvaluationContext EC = new OperationEvaluationContext(null, null, 1, 1, 1, null);
 
+    @Test
     public void testFailWhenNoArguments() {
-        assertEquals(VALUE_INVALID, WorkdayFunction.instance.evaluate(new ValueEval[0], null));
+        ValueEval ve[] = new ValueEval[0];
+        assertEquals(VALUE_INVALID, WorkdayFunction.instance.evaluate(ve, null));
     }
 
+    @Test
     public void testFailWhenLessThan2Arguments() {
-        assertEquals(VALUE_INVALID, WorkdayFunction.instance.evaluate(new ValueEval[1], null));
+        ValueEval ve[] = new ValueEval[1];
+        assertEquals(VALUE_INVALID, WorkdayFunction.instance.evaluate(ve, null));
     }
 
+    @Test
     public void testFailWhenMoreThan3Arguments() {
-        assertEquals(VALUE_INVALID, WorkdayFunction.instance.evaluate(new ValueEval[4], null));
+        ValueEval ve[] = new ValueEval[4];
+        assertEquals(VALUE_INVALID, WorkdayFunction.instance.evaluate(ve, null));
     }
 
+    @Test
     public void testFailWhenArgumentsAreNotDatesNorNumbers() {
-        assertEquals(VALUE_INVALID, WorkdayFunction.instance.evaluate(
-                new ValueEval[]{ new StringEval("Potato"), new StringEval("Cucumber") }, EC));
+        ValueEval ve[] = { new StringEval("Potato"), new StringEval("Cucumber") };
+        assertEquals(VALUE_INVALID, WorkdayFunction.instance.evaluate(ve, EC));
     }
 
+    @Test
     public void testReturnWorkdays() {
-        assertEquals(new Date(109, APRIL, 30), DateUtil.getJavaDate(((NumberEval) WorkdayFunction.instance.evaluate(new ValueEval[]{
-                new StringEval(STARTING_DATE), new NumberEval(151) }, EC)).getNumberValue()));
+        Calendar expCal = LocaleUtil.getLocaleCalendar(2009, 3, 30);
+        Date expDate = expCal.getTime();
+        ValueEval ve[] = { new StringEval(STARTING_DATE), new NumberEval(151) };
+        Date actDate = DateUtil.getJavaDate(((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue());
+        assertEquals(expDate, actDate);
     }
 
+    @Test
     public void testReturnWorkdaysSpanningAWeekendSubtractingDays() {
-    	String startDate = "2013/09/30";
-    	int days = -1;
-		StringEval stringEval = new StringEval(startDate);
-		double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(new ValueEval[]{
-                stringEval, new NumberEval(days) }, EC)).getNumberValue();
-		assertEquals(41544.0, numberValue);
+        Calendar expCal = LocaleUtil.getLocaleCalendar(2013, 8, 27);
+        Date expDate = expCal.getTime();
+
+    	ValueEval ve[] = { new StringEval("2013/09/30"), new NumberEval(-1) };
+		double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
+		assertEquals(41544.0, numberValue, 0);
 		
-		Date date = DateUtil.getJavaDate(numberValue);
-        assertEquals("Should be 2013/09/27", new Date(113, 8, 27), date);
+		Date actDate = DateUtil.getJavaDate(numberValue);
+        assertEquals(expDate, actDate);
     }
 
+    @Test
     public void testReturnWorkdaysSpanningAWeekendAddingDays() {
-    	String startDate = "2013/09/27";
-    	int days = 1;
-		StringEval stringEval = new StringEval(startDate);
-		double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(new ValueEval[]{
-                stringEval, new NumberEval(days) }, EC)).getNumberValue();
-        assertEquals(41547.0, numberValue);
+        Calendar expCal = LocaleUtil.getLocaleCalendar(2013, 8, 30);
+        Date expDate = expCal.getTime();
+        
+        ValueEval ve[] = { new StringEval("2013/09/27"), new NumberEval(1) };
+        double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
+        assertEquals(41547.0, numberValue, 0);
 
-        Date date = DateUtil.getJavaDate(numberValue);
-		assertEquals("Should be 2013/09/30", new Date(113, 8, 30), date);
+        Date actDate = DateUtil.getJavaDate(numberValue);
+        assertEquals(expDate, actDate);
     }
 
+    @Test
     public void testReturnWorkdaysWhenStartIsWeekendAddingDays() {
-    	String startDate = "2013/10/06";
-    	int days = 1;
-		StringEval stringEval = new StringEval(startDate);
-		double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(new ValueEval[]{
-                stringEval, new NumberEval(days) }, EC)).getNumberValue();
-        assertEquals(41554.0, numberValue);
+        Calendar expCal = LocaleUtil.getLocaleCalendar(2013, 9, 7);
+        Date expDate = expCal.getTime();
+        
+        ValueEval ve[] = { new StringEval("2013/10/06"), new NumberEval(1) };
+        double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
+        assertEquals(41554.0, numberValue, 0);
 
-        Date date = DateUtil.getJavaDate(numberValue);
-        assertEquals("Should be 2013/10/07", new Date(113, 9, 7), date);
+        Date actDate = DateUtil.getJavaDate(numberValue);
+        assertEquals(expDate, actDate);
     }
 
+    @Test
     public void testReturnWorkdaysWhenStartIsWeekendSubtractingDays() {
-    	String startDate = "2013/10/06";
-    	int days = -1;
-		StringEval stringEval = new StringEval(startDate);
-		double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(new ValueEval[]{
-                stringEval, new NumberEval(days) }, EC)).getNumberValue();
-        assertEquals(41551.0, numberValue);
+        Calendar expCal = LocaleUtil.getLocaleCalendar(2013, 9, 4);
+        Date expDate = expCal.getTime();
+        
+        ValueEval ve[] = { new StringEval("2013/10/06"), new NumberEval(-1) };
+        double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
+        assertEquals(41551.0, numberValue, 0);
 
-        Date date = DateUtil.getJavaDate(numberValue);
-        assertEquals("Should be 2013/10/04", new Date(113, 9, 4), date);
+        Date actDate = DateUtil.getJavaDate(numberValue);
+        assertEquals(expDate, actDate);
     }
 
+    @Test
     public void testReturnWorkdaysWithDaysTruncated() {
-        assertEquals(new Date(109, APRIL, 30), DateUtil.getJavaDate(((NumberEval) WorkdayFunction.instance.evaluate(new ValueEval[]{
-                new StringEval(STARTING_DATE), new NumberEval(151.99999) }, EC)).getNumberValue()));
+        Calendar expCal = LocaleUtil.getLocaleCalendar(2009, 3, 30);
+        Date expDate = expCal.getTime();
+        
+        ValueEval ve[] = { new StringEval(STARTING_DATE), new NumberEval(151.99999) };
+        double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
+        
+        Date actDate = DateUtil.getJavaDate(numberValue);
+        assertEquals(expDate, actDate);
     }
 
+    @Test
     public void testReturnRetroativeWorkday() {
-        assertEquals(new Date(108, SEPTEMBER, 23), DateUtil.getJavaDate(((NumberEval) WorkdayFunction.instance.evaluate(new ValueEval[]{
-                new StringEval(STARTING_DATE), new NumberEval(-5), new StringEval(RETROATIVE_HOLIDAY) }, EC))
-                .getNumberValue()));
+        Calendar expCal = LocaleUtil.getLocaleCalendar(2008, 8, 23);
+        Date expDate = expCal.getTime();
+        
+        ValueEval ve[] = { new StringEval(STARTING_DATE), new NumberEval(-5), new StringEval(RETROATIVE_HOLIDAY) };
+        double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
+        
+        Date actDate = DateUtil.getJavaDate(numberValue);
+        assertEquals(expDate, actDate);
     }
 
+    @Test
     public void testReturnNetworkdaysWithManyHolidays() {
-        assertEquals(new Date(109, MAY, 5), DateUtil.getJavaDate(((NumberEval) WorkdayFunction.instance.evaluate(new ValueEval[]{
-                new StringEval(STARTING_DATE), new NumberEval(151),
-                new MockAreaEval(FIRST_HOLIDAY, SECOND_HOLIDAY, THIRD_HOLIDAY) }, EC)).getNumberValue()));
+        Calendar expCal = LocaleUtil.getLocaleCalendar(2009, 4, 5);
+        Date expDate = expCal.getTime();
+        
+        ValueEval ve[] = {
+            new StringEval(STARTING_DATE), new NumberEval(151),
+            new MockAreaEval(FIRST_HOLIDAY, SECOND_HOLIDAY, THIRD_HOLIDAY) };
+        double numberValue = ((NumberEval) WorkdayFunction.instance.evaluate(ve, EC)).getNumberValue();
+        
+        Date actDate = DateUtil.getJavaDate(numberValue);
+        assertEquals(expDate, actDate);
     }
 
     private class MockAreaEval extends AreaEvalBase {

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculator.java Mon Sep  7 20:19:50 2015
@@ -17,20 +17,21 @@
 
 package org.apache.poi.ss.formula.atp;
 
-import java.util.Calendar;
-import java.util.GregorianCalendar;
-import java.util.Locale;
+import static org.junit.Assert.assertEquals;
 
-import junit.framework.TestCase;
+import java.util.Calendar;
 
 import org.apache.poi.ss.formula.eval.EvaluationException;
 import org.apache.poi.ss.usermodel.DateUtil;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
 
 /**
  * Specific test cases for YearFracCalculator
  */
-public final class TestYearFracCalculator extends TestCase {
+public final class TestYearFracCalculator {
 
+    @Test
 	public void testBasis1() {
 		confirm(md(1999, 1, 1), md(1999, 4, 5), 1, 0.257534247);
 		confirm(md(1999, 4, 1), md(1999, 4, 5), 1, 0.010958904);
@@ -59,10 +60,7 @@ public final class TestYearFracCalculato
 	}
 
 	private static double md(int year, int month, int day) {
-		Calendar c = new GregorianCalendar(Locale.ROOT);
-		
-		c.set(year, month-1, day, 0, 0, 0);
-		c.set(Calendar.MILLISECOND, 0);
+		Calendar c = LocaleUtil.getLocaleCalendar(year, month-1, day);
 		return DateUtil.getExcelDate(c.getTime());
 	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/atp/TestYearFracCalculatorFromSpreadsheet.java Mon Sep  7 20:19:50 2015
@@ -17,31 +17,29 @@
 
 package org.apache.poi.ss.formula.atp;
 
-import java.io.PrintStream;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
 import java.util.Calendar;
-import java.util.GregorianCalendar;
 import java.util.Iterator;
 
-import junit.framework.Assert;
-import junit.framework.AssertionFailedError;
-import junit.framework.ComparisonFailure;
-import junit.framework.TestCase;
-
 import org.apache.poi.hssf.HSSFTestDataSamples;
-import org.apache.poi.ss.formula.eval.EvaluationException;
 import org.apache.poi.hssf.usermodel.HSSFCell;
 import org.apache.poi.hssf.usermodel.HSSFDateUtil;
 import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
 import org.apache.poi.hssf.usermodel.HSSFRow;
 import org.apache.poi.hssf.usermodel.HSSFSheet;
 import org.apache.poi.hssf.usermodel.HSSFWorkbook;
+import org.apache.poi.ss.formula.eval.EvaluationException;
+import org.apache.poi.ss.usermodel.Row;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
 
 /**
  * Tests YearFracCalculator using test-cases listed in a sample spreadsheet
- * 
- * @author Josh Micich
  */
-public final class TestYearFracCalculatorFromSpreadsheet extends TestCase {
+public final class TestYearFracCalculatorFromSpreadsheet {
 	
 	private static final class SS {
 
@@ -52,15 +50,14 @@ public final class TestYearFracCalculato
 		public static final int EXPECTED_RESULT_COLUMN = 13; // "N"
 	}
 
-	public void testAll() {
+	@Test
+	public void testAll() throws Exception {
 		
 		HSSFWorkbook wb = HSSFTestDataSamples.openSampleWorkbook("yearfracExamples.xls");
 		HSSFSheet sheet = wb.getSheetAt(0);
 		HSSFFormulaEvaluator formulaEvaluator = new HSSFFormulaEvaluator(wb);
 		int nSuccess = 0;
-		int nFailures = 0;
-		int nUnexpectedErrors = 0;
-		Iterator rowIterator = sheet.rowIterator();
+		Iterator<Row> rowIterator = sheet.rowIterator();
 		while(rowIterator.hasNext()) {
 			HSSFRow row = (HSSFRow) rowIterator.next();
 			
@@ -68,28 +65,16 @@ public final class TestYearFracCalculato
 			if (cell == null || cell.getCellType() != HSSFCell.CELL_TYPE_FORMULA) {
 				continue;
 			}
-			try {
-				processRow(row, cell, formulaEvaluator);
-				nSuccess++;
-			} catch (RuntimeException e) {
-				nUnexpectedErrors ++;
-				printShortStackTrace(System.err, e);
-			} catch (AssertionFailedError e) {
-				nFailures ++;
-				printShortStackTrace(System.err, e);
-			}
-		}
-		if (nUnexpectedErrors + nFailures > 0) {
-			String msg = nFailures + " failures(s) and " + nUnexpectedErrors 
-				+ " unexpected errors(s) occurred. See stderr for details";
-			throw new AssertionFailedError(msg);
-		}
-		if (nSuccess < 1) {
-			throw new RuntimeException("No test sample cases found");
+            processRow(row, cell, formulaEvaluator);
+            nSuccess++;
 		}
+
+		assertTrue("No test sample cases found", nSuccess > 0);
+		wb.close();
 	}
 	
-	private static void processRow(HSSFRow row, HSSFCell cell, HSSFFormulaEvaluator formulaEvaluator) {
+	private void processRow(HSSFRow row, HSSFCell cell, HSSFFormulaEvaluator formulaEvaluator)
+	throws EvaluationException {
 		
 		double startDate = makeDate(row, SS.START_YEAR_COLUMN);
 		double endDate = makeDate(row, SS.END_YEAR_COLUMN);
@@ -98,81 +83,33 @@ public final class TestYearFracCalculato
 		
 		double expectedValue = getDoubleCell(row, SS.EXPECTED_RESULT_COLUMN);
 		
-		double actualValue;
-		try {
-			actualValue = YearFracCalculator.calculate(startDate, endDate, basis);
-		} catch (EvaluationException e) {
-			throw new RuntimeException(e);
-		}
-		if (expectedValue != actualValue) {
-			throw new ComparisonFailure("Direct calculate failed - row " + (row.getRowNum()+1), 
-					String.valueOf(expectedValue), String.valueOf(actualValue));
-		}
+		double actualValue = YearFracCalculator.calculate(startDate, endDate, basis);
+
+		String loc = " - row " + (row.getRowNum()+1);
+		assertEquals("Direct calculate failed"+loc, expectedValue, actualValue, 0);
 		actualValue = formulaEvaluator.evaluate(cell).getNumberValue();
-		if (expectedValue != actualValue) {
-			throw new ComparisonFailure("Formula evaluate failed - row " + (row.getRowNum()+1), 
-					String.valueOf(expectedValue), String.valueOf(actualValue));
-		}
+		assertEquals("Formula evaluate failed"+loc, expectedValue, actualValue, 0);
 	}
 
 	private static double makeDate(HSSFRow row, int yearColumn) {
 		int year = getIntCell(row, yearColumn + 0);
 		int month = getIntCell(row, yearColumn + 1);
 		int day = getIntCell(row, yearColumn + 2);
-		Calendar c = new GregorianCalendar(year, month-1, day, 0, 0, 0);
-		c.set(Calendar.MILLISECOND, 0);
+		Calendar c = LocaleUtil.getLocaleCalendar(year, month-1, day);
 		return HSSFDateUtil.getExcelDate(c.getTime());
 	}
 
 	private static int getIntCell(HSSFRow row, int colIx) {
 		double dVal = getDoubleCell(row, colIx);
-		if (Math.floor(dVal) != dVal) {
-			throw new RuntimeException("Non integer value (" + dVal 
-					+ ") cell found at column " + (char)('A' + colIx));
-		}
+		String msg = "Non integer value (" + dVal + ") cell found at column " + (char)('A' + colIx);
+		assertEquals(msg, Math.floor(dVal), dVal, 0);
 		return (int)dVal;
 	}
 
 	private static double getDoubleCell(HSSFRow row, int colIx) {
 		HSSFCell cell = row.getCell(colIx);
-		if (cell == null) {
-			throw new RuntimeException("No cell found at column " + colIx);
-		}
+		assertNotNull("No cell found at column " + colIx, cell);
 		double dVal = cell.getNumericCellValue();
 		return dVal;
 	}
-
-	/**
-	 * Useful to keep output concise when expecting many failures to be reported by this test case
-	 * TODO - refactor duplicates in other Test~FromSpreadsheet classes
-	 */
-	private static void printShortStackTrace(PrintStream ps, Throwable e) {
-		StackTraceElement[] stes = e.getStackTrace();
-		
-		int startIx = 0;
-		// skip any top frames inside junit.framework.Assert
-		while(startIx<stes.length) {
-			if(!stes[startIx].getClassName().equals(Assert.class.getName())) {
-				break;
-			}
-			startIx++;
-		}
-		// skip bottom frames (part of junit framework)
-		int endIx = startIx+1;
-		while(endIx < stes.length) {
-			if(stes[endIx].getClassName().equals(TestCase.class.getName())) {
-				break;
-			}
-			endIx++;
-		}
-		if(startIx >= endIx) {
-			// something went wrong. just print the whole stack trace
-			e.printStackTrace(ps);
-		}
-		endIx -= 4; // skip 4 frames of reflection invocation
-		ps.println(e.toString());
-		for(int i=startIx; i<endIx; i++) {
-			ps.println("\tat " + stes[i].toString());
-		}
-	}
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/eval/TestFormulasFromSpreadsheet.java Mon Sep  7 20:19:50 2015
@@ -21,8 +21,9 @@ import static org.junit.Assert.assertEqu
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.fail;
 
-import java.io.PrintStream;
+import java.util.ArrayList;
 import java.util.Collection;
+import java.util.List;
 import java.util.Locale;
 
 import org.apache.poi.hssf.HSSFTestDataSamples;
@@ -33,14 +34,15 @@ import org.apache.poi.ss.usermodel.Cell;
 import org.apache.poi.ss.usermodel.CellValue;
 import org.apache.poi.ss.usermodel.Row;
 import org.apache.poi.ss.usermodel.Sheet;
-import org.apache.poi.util.POILogFactory;
-import org.apache.poi.util.POILogger;
-import org.junit.Assert;
-import org.junit.Before;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.AfterClass;
 import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameter;
+import org.junit.runners.Parameterized.Parameters;
 
 import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
 
 /**
  * Tests formulas and operators as loaded from a test data spreadsheet.<p/>
@@ -49,248 +51,166 @@ import junit.framework.TestCase;
  * exercised as well.  Tests for bug fixes and specific/tricky behaviour can be found in the
  * corresponding test class (<tt>TestXxxx</tt>) of the target (<tt>Xxxx</tt>) implementor,
  * where execution can be observed more easily.
- *
- * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
  */
+@RunWith(Parameterized.class)
 public final class TestFormulasFromSpreadsheet {
-    private static final POILogger logger = POILogFactory.getLogger(TestFormulasFromSpreadsheet.class);
 
-	private static final class Result {
-		public static final int SOME_EVALUATIONS_FAILED = -1;
-		public static final int ALL_EVALUATIONS_SUCCEEDED = +1;
-		public static final int NO_EVALUATIONS_FOUND = 0;
-	}
-
-	/**
+    private static HSSFWorkbook workbook;
+    private static Sheet sheet;
+    private static HSSFFormulaEvaluator evaluator;
+    private static Locale userLocale;
+    
+    /**
 	 * This class defines constants for navigating around the test data spreadsheet used for these tests.
 	 */
-	private static final class SS {
+	private static interface SS {
 
 		/**
 		 * Name of the test spreadsheet (found in the standard test data folder)
 		 */
-		public final static String FILENAME = "FormulaEvalTestData.xls";
+		String FILENAME = "FormulaEvalTestData.xls";
 		/**
 		 * Row (zero-based) in the test spreadsheet where the operator examples start.
 		 */
-		public static final int START_OPERATORS_ROW_INDEX = 22; // Row '23'
+		int START_OPERATORS_ROW_INDEX = 22; // Row '23'
 		/**
 		 * Row (zero-based) in the test spreadsheet where the function examples start.
 		 */
-		public static final int START_FUNCTIONS_ROW_INDEX = 95; // Row '96'
+		int START_FUNCTIONS_ROW_INDEX = 95; // Row '96'
 		/**
 		 * Index of the column that contains the function names
 		 */
-		public static final int COLUMN_INDEX_FUNCTION_NAME = 1; // Column 'B'
+		int COLUMN_INDEX_FUNCTION_NAME = 1; // Column 'B'
 
 		/**
 		 * Used to indicate when there are no more functions left
 		 */
-		public static final String FUNCTION_NAMES_END_SENTINEL = "<END-OF-FUNCTIONS>";
+		String FUNCTION_NAMES_END_SENTINEL = "<END-OF-FUNCTIONS>";
 
 		/**
 		 * Index of the column where the test values start (for each function)
 		 */
-		public static final short COLUMN_INDEX_FIRST_TEST_VALUE = 3; // Column 'D'
+		short COLUMN_INDEX_FIRST_TEST_VALUE = 3; // Column 'D'
 
 		/**
 		 * Each function takes 4 rows in the test spreadsheet
 		 */
-		public static final int NUMBER_OF_ROWS_PER_FUNCTION = 4;
-	}
-
-	private HSSFWorkbook workbook;
-	private Sheet sheet;
-	// Note - multiple failures are aggregated before ending.
-	// If one or more functions fail, a single AssertionFailedError is thrown at the end
-	private int _functionFailureCount;
-	private int _functionSuccessCount;
-	private int _evaluationFailureCount;
-	private int _evaluationSuccessCount;
-
-	private static final Cell getExpectedValueCell(Row row, int columnIndex) {
-		if (row == null) {
-			return null;
-		}
-		return row.getCell(columnIndex);
-	}
-
-
-	private static void confirmExpectedResult(String msg, Cell expected, CellValue actual) {
-		assertNotNull(msg + " - Bad setup data expected value is null", expected);
-		assertNotNull(msg + " - actual value was null", actual);
-
-		switch (expected.getCellType()) {
-			case Cell.CELL_TYPE_BLANK:
-				assertEquals(msg, Cell.CELL_TYPE_BLANK, actual.getCellType());
-				break;
-			case Cell.CELL_TYPE_BOOLEAN:
-				assertEquals(msg, Cell.CELL_TYPE_BOOLEAN, actual.getCellType());
-				assertEquals(msg, expected.getBooleanCellValue(), actual.getBooleanValue());
-				break;
-			case Cell.CELL_TYPE_ERROR:
-				assertEquals(msg, Cell.CELL_TYPE_ERROR, actual.getCellType());
-				assertEquals(msg, ErrorEval.getText(expected.getErrorCellValue()), ErrorEval.getText(actual.getErrorValue()));
-				break;
-			case Cell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
-				fail("Cannot expect formula as result of formula evaluation: " + msg);
-			case Cell.CELL_TYPE_NUMERIC:
-				assertEquals(msg, Cell.CELL_TYPE_NUMERIC, actual.getCellType());
-				TestMathX.assertEquals(msg, expected.getNumericCellValue(), actual.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
-				break;
-			case Cell.CELL_TYPE_STRING:
-				assertEquals(msg, Cell.CELL_TYPE_STRING, actual.getCellType());
-				assertEquals(msg, expected.getRichStringCellValue().getString(), actual.getStringValue());
-				break;
-		}
-	}
-
-	@Before
-	protected void setUp() {
-		if (workbook == null) {
-			workbook = HSSFTestDataSamples.openSampleWorkbook(SS.FILENAME);
-			sheet = workbook.getSheetAt( 0 );
-		}
-		_functionFailureCount = 0;
-		_functionSuccessCount = 0;
-		_evaluationFailureCount = 0;
-		_evaluationSuccessCount = 0;
+		int NUMBER_OF_ROWS_PER_FUNCTION = 4;
 	}
 
-	@Test
-	public void testFunctionsFromTestSpreadsheet() {
-
-		processFunctionGroup(SS.START_OPERATORS_ROW_INDEX, null);
-		processFunctionGroup(SS.START_FUNCTIONS_ROW_INDEX, null);
-		// example for debugging individual functions/operators:
-//		processFunctionGroup(SS.START_OPERATORS_ROW_INDEX, "ConcatEval");
-//		processFunctionGroup(SS.START_FUNCTIONS_ROW_INDEX, "AVERAGE");
-
-		// confirm results
-		String successMsg = "There were "
-				+ _evaluationSuccessCount + " successful evaluation(s) and "
-				+ _functionSuccessCount + " function(s) without error";
-        String msg = _functionFailureCount + " function(s) failed in "
-                + _evaluationFailureCount + " evaluation(s).  " + successMsg;
-		assertEquals(msg, _functionFailureCount, 0);
-        logger.log(POILogger.INFO, getClass().getName() + ": " + successMsg);
-	}
-
-	/**
-	 * @param startRowIndex row index in the spreadsheet where the first function/operator is found
-	 * @param testFocusFunctionName name of a single function/operator to test alone.
-	 * Typically pass <code>null</code> to test all functions
-	 */
-	private void processFunctionGroup(int startRowIndex, String testFocusFunctionName) {
-		HSSFFormulaEvaluator evaluator = new HSSFFormulaEvaluator(workbook);
-        Collection<String> funcs = FunctionEval.getSupportedFunctionNames();
-
-		int rowIndex = startRowIndex;
-		while (true) {
-			Row r = sheet.getRow(rowIndex);
-			String targetFunctionName = getTargetFunctionName(r);
-			assertNotNull("Test spreadsheet cell empty on row ("
+    @Parameter(value = 0)
+    public String targetFunctionName;
+    @Parameter(value = 1)
+    public int formulasRowIdx;
+    @Parameter(value = 2)
+    public int expectedValuesRowIdx;
+
+    @AfterClass
+    public static void closeResource() throws Exception {
+        LocaleUtil.setUserLocale(userLocale);
+        workbook.close();
+    }
+
+    @Parameters(name="{0}")
+    public static Collection<Object[]> data() throws Exception {
+        // Function "Text" uses custom-formats which are locale specific
+        // can't set the locale on a per-testrun execution, as some settings have been
+        // already set, when we would try to change the locale by then
+        userLocale = LocaleUtil.getUserLocale();
+        LocaleUtil.setUserLocale(Locale.ROOT);
+
+        workbook = HSSFTestDataSamples.openSampleWorkbook(SS.FILENAME);
+        sheet = workbook.getSheetAt( 0 );
+        evaluator = new HSSFFormulaEvaluator(workbook);
+        
+        List<Object[]> data = new ArrayList<Object[]>();
+        
+        processFunctionGroup(data, SS.START_OPERATORS_ROW_INDEX, null);
+        processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX, null);
+        // example for debugging individual functions/operators:
+        // processFunctionGroup(data, SS.START_OPERATORS_ROW_INDEX, "ConcatEval");
+        // processFunctionGroup(data, SS.START_FUNCTIONS_ROW_INDEX, "Text");
+
+        return data;
+    }
+    
+    /**
+     * @param startRowIndex row index in the spreadsheet where the first function/operator is found
+     * @param testFocusFunctionName name of a single function/operator to test alone.
+     * Typically pass <code>null</code> to test all functions
+     */
+    private static void processFunctionGroup(List<Object[]> data, int startRowIndex, String testFocusFunctionName) {
+        for (int rowIndex = startRowIndex; true; rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION) {
+            Row r = sheet.getRow(rowIndex);
+            String targetFunctionName = getTargetFunctionName(r);
+            assertNotNull("Test spreadsheet cell empty on row ("
                     + (rowIndex+1) + "). Expected function name or '"
                     + SS.FUNCTION_NAMES_END_SENTINEL + "'", targetFunctionName);
-			if(targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) {
-				// found end of functions list
-				break;
-			}
-			if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) {
+            if(targetFunctionName.equals(SS.FUNCTION_NAMES_END_SENTINEL)) {
+                // found end of functions list
+                break;
+            }
+            if(testFocusFunctionName == null || targetFunctionName.equalsIgnoreCase(testFocusFunctionName)) {
 
-				// expected results are on the row below
-				Row expectedValuesRow = sheet.getRow(rowIndex + 1);
+                // expected results are on the row below
+                Row expectedValuesRow = sheet.getRow(rowIndex + 1);
                 int missingRowNum = rowIndex + 2; //+1 for 1-based, +1 for next row
                 assertNotNull("Missing expected values row for function '"
                         + targetFunctionName + " (row " + missingRowNum + ")", expectedValuesRow);
-				switch(processFunctionRow(evaluator, targetFunctionName, r, expectedValuesRow)) {
-					case Result.ALL_EVALUATIONS_SUCCEEDED: _functionSuccessCount++; break;
-					case Result.SOME_EVALUATIONS_FAILED: _functionFailureCount++; break;
-					default:
-						throw new RuntimeException("unexpected result");
-					case Result.NO_EVALUATIONS_FOUND: // do nothing
-                        String uname = targetFunctionName.toUpperCase(Locale.ROOT);
-                        if(startRowIndex >= SS.START_FUNCTIONS_ROW_INDEX &&
-                                funcs.contains(uname)) {
-                            logger.log(POILogger.WARN, uname + ": function is supported but missing test data");
-                        }
-                        break;
-				}
-			}
-			rowIndex += SS.NUMBER_OF_ROWS_PER_FUNCTION;
-		}
-	}
-
-	/**
-	 *
-	 * @return a constant from the local Result class denoting whether there were any evaluation
-	 * cases, and whether they all succeeded.
-	 */
-	private int processFunctionRow(HSSFFormulaEvaluator evaluator, String targetFunctionName,
-			Row formulasRow, Row expectedValuesRow) {
-
-		int result = Result.NO_EVALUATIONS_FOUND; // so far
-		short endcolnum = formulasRow.getLastCellNum();
-
-		// iterate across the row for all the evaluation cases
-		for (int colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
-			Cell c = formulasRow.getCell(colnum);
-			if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) {
-				continue;
-			}
-
-			CellValue actualValue = evaluator.evaluate(c);
-
-			Cell expectedValueCell = getExpectedValueCell(expectedValuesRow, colnum);
-			try {
-				confirmExpectedResult("Function '" + targetFunctionName + "': Formula: " + c.getCellFormula() + " @ " + formulasRow.getRowNum() + ":" + colnum,
-						expectedValueCell, actualValue);
-				_evaluationSuccessCount ++;
-				if(result != Result.SOME_EVALUATIONS_FAILED) {
-					result = Result.ALL_EVALUATIONS_SUCCEEDED;
-				}
-			} catch (AssertionFailedError e) {
-				_evaluationFailureCount ++;
-				printShortStackTrace(System.err, e);
-				result = Result.SOME_EVALUATIONS_FAILED;
-			}
-		}
-		return result;
-	}
-
-	/**
-	 * Useful to keep output concise when expecting many failures to be reported by this test case
-	 */
-	private static void printShortStackTrace(PrintStream ps, AssertionFailedError e) {
-		StackTraceElement[] stes = e.getStackTrace();
-
-		int startIx = 0;
-		// skip any top frames inside junit.framework.Assert
-		while(startIx<stes.length) {
-			if(!stes[startIx].getClassName().equals(Assert.class.getName())) {
-				break;
-			}
-			startIx++;
-		}
-		// skip bottom frames (part of junit framework)
-		int endIx = startIx+1;
-		while(endIx < stes.length) {
-			if(stes[endIx].getClassName().equals(TestCase.class.getName())) {
-				break;
-			}
-			endIx++;
-		}
-		if(startIx >= endIx) {
-			// something went wrong. just print the whole stack trace
-			e.printStackTrace(ps);
-		}
-		endIx -= 4; // skip 4 frames of reflection invocation
-		ps.println(e.toString());
-		for(int i=startIx; i<endIx; i++) {
-			ps.println("\tat " + stes[i].toString());
-		}
-	}
 
+                data.add(new Object[]{targetFunctionName, rowIndex, rowIndex + 1});
+            }
+        }
+    }
+
+    @Test
+    public void processFunctionRow() {
+        Row formulasRow = sheet.getRow(formulasRowIdx);
+        Row expectedValuesRow = sheet.getRow(expectedValuesRowIdx);
+
+        short endcolnum = formulasRow.getLastCellNum();
+
+       // iterate across the row for all the evaluation cases
+       for (int colnum=SS.COLUMN_INDEX_FIRST_TEST_VALUE; colnum < endcolnum; colnum++) {
+           Cell c = formulasRow.getCell(colnum);
+           if (c == null || c.getCellType() != Cell.CELL_TYPE_FORMULA) {
+               continue;
+           }
+
+           CellValue actValue = evaluator.evaluate(c);
+           Cell expValue = (expectedValuesRow == null) ? null : expectedValuesRow.getCell(colnum);
+
+           String msg = String.format(Locale.ROOT, "Function '%s': Formula: %s @ %d:%d"
+                   , targetFunctionName, c.getCellFormula(), formulasRow.getRowNum(), colnum);
+
+           assertNotNull(msg + " - Bad setup data expected value is null", expValue);
+           assertNotNull(msg + " - actual value was null", actValue);
+
+           switch (expValue.getCellType()) {
+               case Cell.CELL_TYPE_BLANK:
+                   assertEquals(msg, Cell.CELL_TYPE_BLANK, actValue.getCellType());
+                   break;
+               case Cell.CELL_TYPE_BOOLEAN:
+                   assertEquals(msg, Cell.CELL_TYPE_BOOLEAN, actValue.getCellType());
+                   assertEquals(msg, expValue.getBooleanCellValue(), actValue.getBooleanValue());
+                   break;
+               case Cell.CELL_TYPE_ERROR:
+                   assertEquals(msg, Cell.CELL_TYPE_ERROR, actValue.getCellType());
+                   assertEquals(msg, ErrorEval.getText(expValue.getErrorCellValue()), ErrorEval.getText(actValue.getErrorValue()));
+                   break;
+               case Cell.CELL_TYPE_FORMULA: // will never be used, since we will call method after formula evaluation
+                   fail("Cannot expect formula as result of formula evaluation: " + msg);
+               case Cell.CELL_TYPE_NUMERIC:
+                   assertEquals(msg, Cell.CELL_TYPE_NUMERIC, actValue.getCellType());
+                   TestMathX.assertEquals(msg, expValue.getNumericCellValue(), actValue.getNumberValue(), TestMathX.POS_ZERO, TestMathX.DIFF_TOLERANCE_FACTOR);
+                   break;
+               case Cell.CELL_TYPE_STRING:
+                   assertEquals(msg, Cell.CELL_TYPE_STRING, actValue.getCellType());
+                   assertEquals(msg, expValue.getRichStringCellValue().getString(), actValue.getStringValue());
+                   break;
+           }
+       }
+   }
 	/**
 	 * @return <code>null</code> if cell is missing, empty or blank
 	 */

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestDays360.java Mon Sep  7 20:19:50 2015
@@ -28,6 +28,7 @@ import org.apache.poi.hssf.usermodel.HSS
 import org.apache.poi.ss.formula.eval.BoolEval;
 import org.apache.poi.ss.formula.eval.NumberEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.util.LocaleUtil;
 import org.junit.Test;
 
 public final class TestDays360 {
@@ -36,14 +37,13 @@ public final class TestDays360 {
 	 * @param month 1-based
 	 */
 	private static Date makeDate(int year, int month, int day) {
-		Calendar cal = Calendar.getInstance(Locale.ROOT);
-		cal.set(year, month-1, day, 0, 0, 0);
-		cal.set(Calendar.MILLISECOND, 0);
+		Calendar cal = LocaleUtil.getLocaleCalendar(year, month-1, day);
 		return cal.getTime();
 	}
 
 	private static Date decrementDay(Date d) {
-		Calendar c = (Calendar)d.clone();
+		Calendar c = LocaleUtil.getLocaleCalendar();
+		c.setTime(d);
 		c.add(Calendar.DAY_OF_MONTH, -1);
 		return c.getTime();
 	}

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestEDate.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestEDate.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestEDate.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestEDate.java Mon Sep  7 20:19:50 2015
@@ -17,22 +17,24 @@
 
 package org.apache.poi.ss.formula.functions;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import java.util.Calendar;
 import java.util.Date;
 
-import junit.framework.TestCase;
-
-import org.apache.poi.ss.formula.eval.AreaEval;
 import org.apache.poi.ss.formula.eval.BlankEval;
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.NumberEval;
-import org.apache.poi.ss.formula.eval.RefEval;
 import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.usermodel.DateUtil;
 import org.apache.poi.ss.usermodel.ErrorConstants;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
 
-public class TestEDate extends TestCase {
+public class TestEDate {
 
+    @Test
     public void testEDateProperValues() {
         // verify some border-case combinations of startDate and month-increase
         checkValue(1000, 0, 1000d);
@@ -49,71 +51,79 @@ public class TestEDate extends TestCase
     private void checkValue(int startDate, int monthInc, double expectedResult) {
         EDate eDate = new EDate();
         NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(startDate), new NumberEval(monthInc)}, null);
-        assertEquals(expectedResult, result.getNumberValue());
+        assertEquals(expectedResult, result.getNumberValue(), 0);
     }
     
+    @Test
     public void testEDateInvalidValues() {
         EDate eDate = new EDate();
         ErrorEval result = (ErrorEval) eDate.evaluate(new ValueEval[]{new NumberEval(1000)}, null);
-        assertEquals(ErrorConstants.ERROR_VALUE, result.getErrorCode());
+        assertEquals(ErrorConstants.ERROR_VALUE, result.getErrorCode(), 0);
     }
 
+    @Test
     public void testEDateIncrease() {
         EDate eDate = new EDate();
         Date startDate = new Date();
         int offset = 2;
         NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(DateUtil.getExcelDate(startDate)), new NumberEval(offset)}, null);
         Date resultDate = DateUtil.getJavaDate(result.getNumberValue());
-        Calendar instance = Calendar.getInstance();
+        Calendar instance = LocaleUtil.getLocaleCalendar();
         instance.setTime(startDate);
         instance.add(Calendar.MONTH, offset);
         assertEquals(resultDate, instance.getTime());
 
     }
 
+    @Test
     public void testEDateDecrease() {
         EDate eDate = new EDate();
         Date startDate = new Date();
         int offset = -2;
         NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(DateUtil.getExcelDate(startDate)), new NumberEval(offset)}, null);
         Date resultDate = DateUtil.getJavaDate(result.getNumberValue());
-        Calendar instance = Calendar.getInstance();
+        Calendar instance = LocaleUtil.getLocaleCalendar();
         instance.setTime(startDate);
         instance.add(Calendar.MONTH, offset);
         assertEquals(resultDate, instance.getTime());
     }
     
+    @Test
     public void testBug56688() {        
         EDate eDate = new EDate();
         NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(1000), new RefEvalImplementation(new NumberEval(0))}, null);
-        assertEquals(1000d, result.getNumberValue());
+        assertEquals(1000d, result.getNumberValue(), 0);
     }
 
+    @Test
     public void testRefEvalStartDate() {
         EDate eDate = new EDate();
         NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new RefEvalImplementation(new NumberEval(1000)), new NumberEval(0)}, null);
-        assertEquals(1000d, result.getNumberValue());
+        assertEquals(1000d, result.getNumberValue(), 0);
     }
 
+    @Test
     public void testEDateInvalidValueEval() {
         ValueEval evaluate = new EDate().evaluate(new ValueEval[]{new ValueEval() {}, new NumberEval(0)}, null);
         assertTrue(evaluate instanceof ErrorEval);
         assertEquals(ErrorEval.VALUE_INVALID, evaluate);
     }
 
+    @Test
     public void testEDateBlankValueEval() {
         NumberEval evaluate = (NumberEval) new EDate().evaluate(new ValueEval[]{BlankEval.instance, new NumberEval(0)}, null);
-        assertEquals(-1.0d, evaluate.getNumberValue());
+        assertEquals(-1.0d, evaluate.getNumberValue(), 0);
     }
 
+    @Test
     public void testEDateBlankRefValueEval() {
         EDate eDate = new EDate();
         NumberEval result = (NumberEval) eDate.evaluate(new ValueEval[]{new RefEvalImplementation(BlankEval.instance), new NumberEval(0)}, null);
         assertEquals("0 startDate triggers BAD_DATE currently, thus -1.0!", 
-                -1.0d, result.getNumberValue());
+                -1.0d, result.getNumberValue(), 0);
 
         result = (NumberEval) eDate.evaluate(new ValueEval[]{new NumberEval(1), new RefEvalImplementation(BlankEval.instance)}, null);
         assertEquals("Blank is handled as 0 otherwise", 
-                1.0d, result.getNumberValue());
+                1.0d, result.getNumberValue(), 0);
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestEOMonth.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestEOMonth.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestEOMonth.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestEOMonth.java Mon Sep  7 20:19:50 2015
@@ -17,12 +17,13 @@
 
 package org.apache.poi.ss.formula.functions;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
 import java.util.Calendar;
 import java.util.Date;
 
-import junit.framework.TestCase;
 import org.apache.poi.ss.formula.OperationEvaluationContext;
-
 import org.apache.poi.ss.formula.eval.BlankEval;
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.NumberEval;
@@ -30,8 +31,10 @@ import org.apache.poi.ss.formula.eval.St
 import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.usermodel.DateUtil;
 import org.apache.poi.ss.usermodel.ErrorConstants;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
 
-public class TestEOMonth extends TestCase{
+public class TestEOMonth {
 
     private static final double BAD_DATE = -1.0;
 
@@ -47,6 +50,7 @@ public class TestEOMonth extends TestCas
     private final FreeRefFunction eOMonth = EOMonth.instance;
     private final OperationEvaluationContext ec = new OperationEvaluationContext(null, null, 0, 0, 0, null);
 
+    @Test
     public void testEOMonthProperValues() {
         // verify some border-case combinations of startDate and month-increase
         checkValue(DATE_1900_01_01, 0, DATE_1900_01_31);
@@ -56,6 +60,7 @@ public class TestEOMonth extends TestCas
         checkValue(DATE_2034_06_09, 1, DATE_2034_07_31);
     }
 
+    @Test
     public void testEOMonthBadDateValues() {
         checkValue(0.0, -2, BAD_DATE);
         checkValue(0.0, -3, BAD_DATE);
@@ -63,74 +68,85 @@ public class TestEOMonth extends TestCas
     }
 
     private void checkValue(double startDate, int monthInc, double expectedResult) {
-        NumberEval result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new NumberEval(startDate), new NumberEval(monthInc)}, ec);
-        assertEquals(expectedResult, result.getNumberValue());
+        ValueEval ve[] = {new NumberEval(startDate), new NumberEval(monthInc)};
+        NumberEval result = (NumberEval) eOMonth.evaluate(ve, ec);
+        assertEquals(expectedResult, result.getNumberValue(), 0);
     }
 
+    @Test
     public void testEOMonthZeroDate() {
         NumberEval result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new NumberEval(0), new NumberEval(0)}, ec);
-        assertEquals("0 startDate is 1900-01-00", DATE_1900_01_31, result.getNumberValue());
+        assertEquals("0 startDate is 1900-01-00", DATE_1900_01_31, result.getNumberValue(), 0);
 
         result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new NumberEval(0), new NumberEval(1)}, ec);
-        assertEquals("0 startDate is 1900-01-00", DATE_1900_02_28, result.getNumberValue());
+        assertEquals("0 startDate is 1900-01-00", DATE_1900_02_28, result.getNumberValue(), 0);
     }
 
+    @Test
     public void testEOMonthInvalidArguments() {
         ValueEval result = eOMonth.evaluate(new ValueEval[] {new NumberEval(DATE_1902_09_26)}, ec);
         assertTrue(result instanceof ErrorEval);
-        assertEquals(ErrorConstants.ERROR_VALUE, ((ErrorEval) result).getErrorCode());
+        assertEquals(ErrorConstants.ERROR_VALUE, ((ErrorEval) result).getErrorCode(), 0);
 
         result = eOMonth.evaluate(new ValueEval[] {new StringEval("a"), new StringEval("b")}, ec);
         assertTrue(result instanceof ErrorEval);
-        assertEquals(ErrorConstants.ERROR_VALUE, ((ErrorEval) result).getErrorCode());
-    }
-
-    public void testEOMonthIncrease() {
-        checkOffset(new Date(), 2);
+        assertEquals(ErrorConstants.ERROR_VALUE, ((ErrorEval) result).getErrorCode(), 0);
     }
 
-    public void testEOMonthDecrease() {
-        checkOffset(new Date(), -2);
-    }
-
-    private void checkOffset(Date startDate, int offset) {
-        NumberEval result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new NumberEval(DateUtil.getExcelDate(startDate)), new NumberEval(offset)}, ec);
-        Date resultDate = DateUtil.getJavaDate(result.getNumberValue());
-        Calendar instance = Calendar.getInstance();
-        instance.setTime(startDate);
-        instance.add(Calendar.MONTH, offset);
-        instance.add(Calendar.MONTH, 1);
-        instance.set(Calendar.DAY_OF_MONTH, 1);
-        instance.add(Calendar.DAY_OF_MONTH, -1);
-        instance.set(Calendar.HOUR_OF_DAY, 0);
-        instance.set(Calendar.MINUTE, 0);
-        instance.set(Calendar.SECOND, 0);
-        instance.set(Calendar.MILLISECOND, 0);
-        assertEquals(instance.getTime(), resultDate);
+    @Test
+    public void checkOffset() {
+        for (int offset=-12; offset<=12; offset++) {
+            Calendar cal = LocaleUtil.getLocaleCalendar();
+            Date startDate = cal.getTime();
+
+            cal.add(Calendar.MONTH, offset);
+            cal.set(Calendar.DAY_OF_MONTH, cal.getActualMaximum(Calendar.DAY_OF_MONTH));
+            cal.clear(Calendar.HOUR);
+            cal.set(Calendar.HOUR_OF_DAY, 0);
+            cal.clear(Calendar.MINUTE);
+            cal.clear(Calendar.SECOND);
+            cal.clear(Calendar.MILLISECOND);
+            Date expDate = cal.getTime();
+            
+            ValueEval ve[] = {
+                new NumberEval(DateUtil.getExcelDate(startDate)),
+                new NumberEval(offset)
+            };
+            NumberEval result = (NumberEval) eOMonth.evaluate(ve, ec);
+            Date actDate = DateUtil.getJavaDate(result.getNumberValue());
+            
+            assertEquals(expDate, actDate);
+        }
     }
 
+    @Test
     public void testBug56688() {
-        NumberEval result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new NumberEval(DATE_1902_09_26), new RefEvalImplementation(new NumberEval(0))}, ec);
-        assertEquals(DATE_1902_09_30, result.getNumberValue());
+        ValueEval ve[] = {new NumberEval(DATE_1902_09_26), new RefEvalImplementation(new NumberEval(0))};
+        NumberEval result = (NumberEval) eOMonth.evaluate(ve, ec);
+        assertEquals(DATE_1902_09_30, result.getNumberValue(), 0);
     }
 
+    @Test
     public void testRefEvalStartDate() {
-        NumberEval result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new RefEvalImplementation(new NumberEval(DATE_1902_09_26)), new NumberEval(0)}, ec);
-        assertEquals(DATE_1902_09_30, result.getNumberValue());
+        ValueEval ve[] = {new RefEvalImplementation(new NumberEval(DATE_1902_09_26)), new NumberEval(0)};
+        NumberEval result = (NumberEval) eOMonth.evaluate(ve, ec);
+        assertEquals(DATE_1902_09_30, result.getNumberValue(), 0);
     }
 
+    @Test
     public void testEOMonthBlankValueEval() {
         NumberEval evaluate = (NumberEval) eOMonth.evaluate(new ValueEval[] {BlankEval.instance, new NumberEval(0)}, ec);
-        assertEquals("Blank is handled as 0", DATE_1900_01_31, evaluate.getNumberValue());
+        assertEquals("Blank is handled as 0", DATE_1900_01_31, evaluate.getNumberValue(), 0);
     }
 
+    @Test
     public void testEOMonthBlankRefValueEval() {
-        NumberEval result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new RefEvalImplementation(BlankEval.instance), new NumberEval(1)}, ec);
-        assertEquals("Blank is handled as 0",
-                DATE_1900_02_28, result.getNumberValue());
-
-        result = (NumberEval) eOMonth.evaluate(new ValueEval[] {new NumberEval(1), new RefEvalImplementation(BlankEval.instance)}, ec);
-        assertEquals("Blank is handled as 0",
-                DATE_1900_01_31, result.getNumberValue());
+        ValueEval[] ve1 = {new RefEvalImplementation(BlankEval.instance), new NumberEval(1)};
+        NumberEval result = (NumberEval) eOMonth.evaluate(ve1, ec);
+        assertEquals("Blank is handled as 0", DATE_1900_02_28, result.getNumberValue(), 0);
+
+        ValueEval[] ve2 = {new NumberEval(1), new RefEvalImplementation(BlankEval.instance)};
+        result = (NumberEval) eOMonth.evaluate(ve2, ec);
+        assertEquals("Blank is handled as 0", DATE_1900_01_31, result.getNumberValue(), 0);
     }
 }

Modified: poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestText.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestText.java?rev=1701688&r1=1701687&r2=1701688&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestText.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/formula/functions/TestText.java Mon Sep  7 20:19:50 2015
@@ -17,21 +17,25 @@
 
 package org.apache.poi.ss.formula.functions;
 
+import static org.junit.Assert.assertEquals;
+
+import java.text.DateFormatSymbols;
 import java.text.DecimalFormatSymbols;
 import java.text.SimpleDateFormat;
-import java.util.GregorianCalendar;
-import java.util.Locale;
+import java.util.TimeZone;
 
-import junit.framework.TestCase;
 import org.apache.poi.ss.formula.eval.ErrorEval;
 import org.apache.poi.ss.formula.eval.NumberEval;
-import org.apache.poi.ss.formula.eval.ValueEval;
 import org.apache.poi.ss.formula.eval.StringEval;
+import org.apache.poi.ss.formula.eval.ValueEval;
+import org.apache.poi.util.LocaleUtil;
+import org.junit.Test;
 
 /**
  * Test case for TEXT()
  */
-public final class TestText extends TestCase {
+public final class TestText {
+    @Test
     public void testTextWithStringFirstArg() {
         ValueEval strArg = new StringEval("abc");
         ValueEval formatArg = new StringEval("abc");
@@ -40,13 +44,14 @@ public final class TestText extends Test
         assertEquals(ErrorEval.VALUE_INVALID, result);
     }
 
+    @Test
     public void testTextWithDeciamlFormatSecondArg() {
         ValueEval numArg = new NumberEval(321321.321);
         ValueEval formatArg = new StringEval("#,###.00000");
         ValueEval[] args = { numArg, formatArg };
         ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
-        char groupSeparator = new DecimalFormatSymbols(Locale.getDefault()).getGroupingSeparator();
-        char decimalSeparator = new DecimalFormatSymbols(Locale.getDefault()).getDecimalSeparator();
+        char groupSeparator = new DecimalFormatSymbols(LocaleUtil.getUserLocale()).getGroupingSeparator();
+        char decimalSeparator = new DecimalFormatSymbols(LocaleUtil.getUserLocale()).getDecimalSeparator();
         ValueEval testResult = new StringEval("321" + groupSeparator + "321" + decimalSeparator + "32100");
         assertEquals(testResult.toString(), result.toString());
         numArg = new NumberEval(321.321);
@@ -64,6 +69,7 @@ public final class TestText extends Test
         assertEquals(testResult.toString(), result.toString());
     }
 
+    @Test
     public void testTextWithFractionFormatSecondArg() {
         ValueEval numArg = new NumberEval(321.321);
         ValueEval formatArg = new StringEval("# #/#");
@@ -85,37 +91,47 @@ public final class TestText extends Test
         assertEquals(testResult.toString(), result.toString());
     }
 
+    @Test
     public void testTextWithDateFormatSecondArg() {
-        // Test with Java style M=Month
-        ValueEval numArg = new NumberEval(321.321);
-        ValueEval formatArg = new StringEval("dd:MM:yyyy hh:mm:ss");
-        ValueEval[] args = { numArg, formatArg };
-        ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
-        ValueEval testResult = new StringEval("16:11:1900 07:42:14");
-        assertEquals(testResult.toString(), result.toString());
-
-        // Excel also supports "m before h is month"
-        formatArg = new StringEval("dd:mm:yyyy hh:mm:ss");
-        args[1] = formatArg;
-        result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
-        testResult = new StringEval("16:11:1900 07:42:14");
-        assertEquals(testResult.toString(), result.toString());
-
-        // this line is intended to compute how "November" would look like in the current locale
-        String november = new SimpleDateFormat("MMMM").format(new GregorianCalendar(2010,10,15).getTime());
-
-        // Again with Java style
-        formatArg = new StringEval("MMMM dd, yyyy");
-        args[1] = formatArg;
-        result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
-        testResult = new StringEval(november + " 16, 1900");
-        assertEquals(testResult.toString(), result.toString());
-
-        // And Excel style
-        formatArg = new StringEval("mmmm dd, yyyy");
-        args[1] = formatArg;
-        result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
-        testResult = new StringEval(november + " 16, 1900");
-        assertEquals(testResult.toString(), result.toString());
+        TimeZone userTZ = LocaleUtil.getUserTimeZone();
+        LocaleUtil.setUserTimeZone(TimeZone.getTimeZone("CET"));
+        try {
+            // Test with Java style M=Month
+            ValueEval numArg = new NumberEval(321.321);
+            ValueEval formatArg = new StringEval("dd:MM:yyyy hh:mm:ss");
+            ValueEval[] args = { numArg, formatArg };
+            ValueEval result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
+            ValueEval testResult = new StringEval("16:11:1900 07:42:14");
+            assertEquals(testResult.toString(), result.toString());
+    
+            // Excel also supports "m before h is month"
+            formatArg = new StringEval("dd:mm:yyyy hh:mm:ss");
+            args[1] = formatArg;
+            result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
+            testResult = new StringEval("16:11:1900 07:42:14");
+            assertEquals(testResult.toString(), result.toString());
+    
+            // this line is intended to compute how "November" would look like in the current locale
+            // update: now the locale will be (if not set otherwise) always Locale.getDefault() (see LocaleUtil)
+            DateFormatSymbols dfs = DateFormatSymbols.getInstance(LocaleUtil.getUserLocale());
+            SimpleDateFormat sdf = new SimpleDateFormat("MMMM", dfs);
+            String november = sdf.format(LocaleUtil.getLocaleCalendar(2015,10,1).getTime());
+    
+            // Again with Java style
+            formatArg = new StringEval("MMMM dd, yyyy");
+            args[1] = formatArg;
+            result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
+            testResult = new StringEval(november + " 16, 1900");
+            assertEquals(testResult.toString(), result.toString());
+    
+            // And Excel style
+            formatArg = new StringEval("mmmm dd, yyyy");
+            args[1] = formatArg;
+            result = TextFunction.TEXT.evaluate(args, -1, (short)-1);
+            testResult = new StringEval(november + " 16, 1900");
+            assertEquals(testResult.toString(), result.toString());
+        } finally {
+            LocaleUtil.setUserTimeZone(userTZ);
+        }
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org