aboutsummaryrefslogtreecommitdiffstats
path: root/src/testcases/org/apache
diff options
context:
space:
mode:
authorDominik Stadler <centic@apache.org>2020-06-15 20:51:43 +0000
committerDominik Stadler <centic@apache.org>2020-06-15 20:51:43 +0000
commitc9912a7e92eb6b9e82ce513cf7ccc9cb709a326c (patch)
tree46e658917cf4de95cca937dbf29afdb895d24a92 /src/testcases/org/apache
parent863659f48c4711d7af457c4f8f5a45c074ae14c0 (diff)
downloadpoi-c9912a7e92eb6b9e82ce513cf7ccc9cb709a326c.tar.gz
poi-c9912a7e92eb6b9e82ce513cf7ccc9cb709a326c.zip
Always close Reader in test
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1878869 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/testcases/org/apache')
-rw-r--r--src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java62
1 files changed, 31 insertions, 31 deletions
diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java b/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
index 95e2947007..ec8359a46d 100644
--- a/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
+++ b/src/testcases/org/apache/poi/ss/usermodel/TestFractionFormat.java
@@ -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){