poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cen...@apache.org
Subject svn commit: r1878869 - /poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
Date Mon, 15 Jun 2020 20:51:43 GMT
Author: centic
Date: Mon Jun 15 20:51:43 2020
New Revision: 1878869

URL: http://svn.apache.org/viewvc?rev=1878869&view=rev
Log:
Always close Reader in test

Modified:
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java?rev=1878869&r1=1878868&r2=1878869&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java Mon Jun 15
20:51:43 2020
@@ -65,52 +65,52 @@ public final class TestFractionFormat {
     @Test
     public void testWithBigWholePart() {
         FractionFormat f = new FractionFormat("#", "???/???");
-        
+
         assertEquals("10100136259702", f.format(10100136259702d));
         assertEquals("-10100136259702", f.format(-10100136259702d));
-        
+
         // Excel displays fraction: 51/512
         assertEquals("10100136259702 10/100", f.format(10100136259702.1d));
         assertEquals("-10100136259702 10/100", f.format(-10100136259702.1d));
-        
+
         // Excel displays fraction: 461/512
         assertEquals("10100136259702 90/100", f.format(10100136259702.9d));
         assertEquals("-10100136259702 90/100", f.format(-10100136259702.9d));
     }
-     
+
     @Test
     public void testTruthFile() throws Exception {
         File truthFile = HSSFTestDataSamples.getSampleFile("54686_fraction_formats.txt");
-        BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(truthFile),
LocaleUtil.CHARSET_1252));
-        Workbook wb = HSSFTestDataSamples.openSampleWorkbook("54686_fraction_formats.xls");
-        Sheet sheet = wb.getSheetAt(0);
-        DataFormatter formatter = new DataFormatter();
-        FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
-
-        // Skip over the header row
-        String truthLine = reader.readLine();
-        String[] headers = truthLine.split("\t");
-        truthLine = reader.readLine();
-
-        for (int i = 1; i < sheet.getLastRowNum() && truthLine != null; i++){
-            Row r = sheet.getRow(i);
-            String[] truths = truthLine.split("\t");
-            // Intentionally ignore the last column (tika-1132), for now
-            for (short j = 3; j < 12; j++){
-                Cell cell = r.getCell(j, MissingCellPolicy.CREATE_NULL_AS_BLANK);
-                String formatted = clean(formatter.formatCellValue(cell, evaluator));
-                if (truths.length <= j){
-                    continue;
-                }
+        try (BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(truthFile),
LocaleUtil.CHARSET_1252))) {
+            Workbook wb = HSSFTestDataSamples.openSampleWorkbook("54686_fraction_formats.xls");
+            Sheet sheet = wb.getSheetAt(0);
+            DataFormatter formatter = new DataFormatter();
+            FormulaEvaluator evaluator = wb.getCreationHelper().createFormulaEvaluator();
 
-                String truth = clean(truths[j]);
-                String testKey = truths[0]+":"+truths[1]+":"+headers[j];
-                assertEquals(testKey, truth, formatted);
-            }
+            // Skip over the header row
+            String truthLine = reader.readLine();
+            String[] headers = truthLine.split("\t");
             truthLine = reader.readLine();
+
+            for (int i = 1; i < sheet.getLastRowNum() && truthLine != null; i++)
{
+                Row r = sheet.getRow(i);
+                String[] truths = truthLine.split("\t");
+                // Intentionally ignore the last column (tika-1132), for now
+                for (short j = 3; j < 12; j++) {
+                    Cell cell = r.getCell(j, MissingCellPolicy.CREATE_NULL_AS_BLANK);
+                    String formatted = clean(formatter.formatCellValue(cell, evaluator));
+                    if (truths.length <= j) {
+                        continue;
+                    }
+
+                    String truth = clean(truths[j]);
+                    String testKey = truths[0] + ":" + truths[1] + ":" + headers[j];
+                    assertEquals(testKey, truth, formatted);
+                }
+                truthLine = reader.readLine();
+            }
+            wb.close();
         }
-        wb.close();
-        reader.close();
     }
 
     private String clean(String s){



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


Mime
View raw message