@@ -17,12 +17,6 @@ Licensed to the Apache Software Foundation (ASF) under one or more
1717
1818package org .apache .poi .hssf .eventusermodel ;
1919
20- import static org .junit .jupiter .api .Assertions .assertArrayEquals ;
21- import static org .junit .jupiter .api .Assertions .assertEquals ;
22- import static org .junit .jupiter .api .Assertions .assertFalse ;
23- import static org .junit .jupiter .api .Assertions .assertThrows ;
24- import static org .junit .jupiter .api .Assertions .assertTrue ;
25-
2620import java .io .IOException ;
2721import java .io .InputStream ;
2822import java .util .ArrayList ;
@@ -43,27 +37,42 @@ Licensed to the Apache Software Foundation (ASF) under one or more
4337import org .apache .poi .poifs .filesystem .POIFSFileSystem ;
4438import org .junit .jupiter .api .Test ;
4539
40+ import static org .junit .jupiter .api .Assertions .*;
41+
4642/**
4743 * Testing for {@link HSSFEventFactory}
4844 */
4945final class TestHSSFEventFactory {
50- private final List <org .apache .poi .hssf .record .Record > records = new ArrayList <>();
5146
52- private void openSample (String sampleFileName ) throws IOException {
53- records .clear ();
47+ private List <org .apache .poi .hssf .record .Record > openSample (String sampleFileName ) throws IOException {
48+ final List <org .apache .poi .hssf .record .Record > records = new ArrayList <>();
49+ HSSFRequest req = new HSSFRequest ();
50+ req .addListenerForAllRecords (records ::add );
51+ try (InputStream is = HSSFTestDataSamples .openSampleFileStream (sampleFileName );
52+ POIFSFileSystem fs = new POIFSFileSystem (is )) {
53+ HSSFEventFactory factory = new HSSFEventFactory ();
54+ factory .processWorkbookEvents (req , fs );
55+ }
56+ return records ;
57+ }
58+
59+ private List <org .apache .poi .hssf .record .Record > openSample (
60+ String sampleFileName , String password ) throws IOException {
61+ final List <org .apache .poi .hssf .record .Record > records = new ArrayList <>();
5462 HSSFRequest req = new HSSFRequest ();
5563 req .addListenerForAllRecords (records ::add );
5664 try (InputStream is = HSSFTestDataSamples .openSampleFileStream (sampleFileName );
5765 POIFSFileSystem fs = new POIFSFileSystem (is )) {
5866 HSSFEventFactory factory = new HSSFEventFactory ();
5967 factory .processWorkbookEvents (req , fs );
6068 }
69+ return records ;
6170 }
6271
6372 @ Test
6473 void testWithMissingRecords () throws Exception {
6574
66- openSample ("SimpleWithSkip.xls" );
75+ final List < org . apache . poi . hssf . record . Record > records = openSample ("SimpleWithSkip.xls" );
6776
6877 int numRec = records .size ();
6978
@@ -82,7 +91,8 @@ void testWithCrazyContinueRecords() throws Exception {
8291 // Some files have crazy ordering of their continue records
8392 // Check that we don't break on them (bug #42844)
8493
85- openSample ("ContinueRecordProblem.xls" );
94+ final List <org .apache .poi .hssf .record .Record > records =
95+ openSample ("ContinueRecordProblem.xls" );
8696
8797 int numRec = records .size ();
8898 // Check we got the records
@@ -106,14 +116,14 @@ void testWithCrazyContinueRecords() throws Exception {
106116 @ Test
107117 @ SuppressWarnings ("java:S2699" )
108118 void testUnknownContinueRecords () throws Exception {
109- openSample ("42844.xls" );
119+ assertNotNull ( openSample ("42844.xls" ) );
110120 }
111121
112122 @ Test
113123 @ SuppressWarnings ("java:S2699" )
114124 void testWithDifferentWorkbookName () throws Exception {
115- openSample ("BOOK_in_capitals.xls" );
116- openSample ("WORKBOOK_in_capitals.xls" );
125+ assertNotNull ( openSample ("BOOK_in_capitals.xls" ) );
126+ assertNotNull ( openSample ("WORKBOOK_in_capitals.xls" ) );
117127 }
118128
119129 @ Test
@@ -128,7 +138,8 @@ void testWithPasswordProtectedWorkbooks() throws Exception {
128138 // With the password, is properly processed
129139 Biff8EncryptionKey .setCurrentUserPassword ("abc" );
130140 try {
131- openSample ("xor-encryption-abc.xls" );
141+ final List <org .apache .poi .hssf .record .Record > records =
142+ openSample ("xor-encryption-abc.xls" );
132143
133144 // Check we got the sheet and the contents
134145 assertTrue (records .size () > 50 );
0 commit comments