@@ -110,4 +110,184 @@ public void shouldMapExcelToRecordWithExcelCell() {
110110 assertThat (calculation .toDate ().toString (), is ("2018-06-30" ));
111111 }
112112 }
113+
114+ @ Test
115+ public void shouldMapExcelToRecordFromInputStream () {
116+ // Test with InputStream
117+ try (java .io .FileInputStream stream = new java .io .FileInputStream (
118+ new File ("src/test/resources/employees.xlsx" ))) {
119+ List <EmployeeRecord > employees = Poiji .fromExcel (
120+ stream ,
121+ com .poiji .exception .PoijiExcelType .XLSX ,
122+ EmployeeRecord .class
123+ );
124+
125+ assertThat (employees , notNullValue ());
126+ assertThat (employees .size (), is (3 ));
127+
128+ EmployeeRecord firstEmployee = employees .get (0 );
129+ assertThat (firstEmployee .employeeId (), is (123923L ));
130+ assertThat (firstEmployee .name (), is ("Joe" ));
131+ } catch (Exception e ) {
132+ throw new RuntimeException (e );
133+ }
134+ }
135+
136+ @ Test
137+ public void shouldMapExcelToRecordFromInputStreamWithOptions () {
138+ // Test with InputStream and options
139+ PoijiOptions options = PoijiOptions .PoijiOptionsBuilder .settings ()
140+ .headerStart (0 )
141+ .build ();
142+
143+ try (java .io .FileInputStream stream = new java .io .FileInputStream (
144+ new File ("src/test/resources/employees.xlsx" ))) {
145+ List <EmployeeRecord > employees = Poiji .fromExcel (
146+ stream ,
147+ com .poiji .exception .PoijiExcelType .XLSX ,
148+ EmployeeRecord .class ,
149+ options
150+ );
151+
152+ assertThat (employees , notNullValue ());
153+ assertThat (employees .size (), is (3 ));
154+ } catch (Exception e ) {
155+ throw new RuntimeException (e );
156+ }
157+ }
158+
159+ @ Test
160+ public void shouldMapXLSFromInputStream () {
161+ // Test XLS with InputStream
162+ try (java .io .FileInputStream stream = new java .io .FileInputStream (
163+ new File ("src/test/resources/employees.xls" ))) {
164+ List <EmployeeRecord > employees = Poiji .fromExcel (
165+ stream ,
166+ com .poiji .exception .PoijiExcelType .XLS ,
167+ EmployeeRecord .class
168+ );
169+
170+ assertThat (employees , notNullValue ());
171+ assertThat (employees .size (), is (3 ));
172+
173+ EmployeeRecord firstEmployee = employees .get (0 );
174+ assertThat (firstEmployee .employeeId (), is (123923L ));
175+ } catch (Exception e ) {
176+ throw new RuntimeException (e );
177+ }
178+ }
179+
180+ @ Test
181+ public void shouldHandleRecordWithConsumer () {
182+ // Test with consumer interface
183+ final java .util .List <EmployeeRecord > collectedEmployees = new java .util .ArrayList <>();
184+
185+ Poiji .fromExcel (
186+ new File ("src/test/resources/employees.xlsx" ),
187+ EmployeeRecord .class ,
188+ collectedEmployees ::add
189+ );
190+
191+ assertThat (collectedEmployees .size (), is (3 ));
192+ assertThat (collectedEmployees .get (0 ).name (), is ("Joe" ));
193+ }
194+
195+ @ Test
196+ public void shouldHandleRecordWithConsumerAndOptions () {
197+ // Test with consumer interface and options
198+ PoijiOptions options = PoijiOptions .PoijiOptionsBuilder .settings ()
199+ .headerStart (0 )
200+ .build ();
201+
202+ final java .util .List <EmployeeRecord > collectedEmployees = new java .util .ArrayList <>();
203+
204+ Poiji .fromExcel (
205+ new File ("src/test/resources/employees.xlsx" ),
206+ EmployeeRecord .class ,
207+ options ,
208+ collectedEmployees ::add
209+ );
210+
211+ assertThat (collectedEmployees .size (), is (3 ));
212+ }
213+
214+ @ Test
215+ public void shouldMapExcelToRecordFromSheet () {
216+ // Test with Sheet API
217+ try {
218+ org .apache .poi .ss .usermodel .Workbook workbook = org .apache .poi .ss .usermodel .WorkbookFactory .create (
219+ new File ("src/test/resources/employees.xlsx" ));
220+ org .apache .poi .ss .usermodel .Sheet sheet = workbook .getSheetAt (0 );
221+
222+ List <EmployeeRecord > employees = Poiji .fromExcel (
223+ sheet ,
224+ EmployeeRecord .class
225+ );
226+
227+ assertThat (employees , notNullValue ());
228+ assertThat (employees .size (), is (3 ));
229+ assertThat (employees .get (0 ).name (), is ("Joe" ));
230+
231+ workbook .close ();
232+ } catch (Exception e ) {
233+ throw new RuntimeException (e );
234+ }
235+ }
236+
237+ @ Test
238+ public void shouldMapExcelToRecordFromSheetWithOptions () {
239+ // Test with Sheet API and options
240+ PoijiOptions options = PoijiOptions .PoijiOptionsBuilder .settings ()
241+ .headerStart (0 )
242+ .build ();
243+
244+ try {
245+ org .apache .poi .ss .usermodel .Workbook workbook = org .apache .poi .ss .usermodel .WorkbookFactory .create (
246+ new File ("src/test/resources/employees.xlsx" ));
247+ org .apache .poi .ss .usermodel .Sheet sheet = workbook .getSheetAt (0 );
248+
249+ List <EmployeeRecord > employees = Poiji .fromExcel (
250+ sheet ,
251+ EmployeeRecord .class ,
252+ options
253+ );
254+
255+ assertThat (employees , notNullValue ());
256+ assertThat (employees .size (), is (3 ));
257+
258+ workbook .close ();
259+ } catch (Exception e ) {
260+ throw new RuntimeException (e );
261+ }
262+ }
263+
264+ @ Test
265+ public void shouldMapExcelToRecordFromSheetWithConsumer () {
266+ // Test with Sheet API and consumer
267+ PoijiOptions options = PoijiOptions .PoijiOptionsBuilder .settings ()
268+ .headerStart (0 )
269+ .build ();
270+
271+ final java .util .List <EmployeeRecord > collectedEmployees = new java .util .ArrayList <>();
272+
273+ try {
274+ org .apache .poi .ss .usermodel .Workbook workbook = org .apache .poi .ss .usermodel .WorkbookFactory .create (
275+ new File ("src/test/resources/employees.xlsx" ));
276+ org .apache .poi .ss .usermodel .Sheet sheet = workbook .getSheetAt (0 );
277+
278+ Poiji .fromExcel (
279+ sheet ,
280+ EmployeeRecord .class ,
281+ options ,
282+ collectedEmployees ::add
283+ );
284+
285+ assertThat (collectedEmployees .size (), is (3 ));
286+ assertThat (collectedEmployees .get (0 ).name (), is ("Joe" ));
287+
288+ workbook .close ();
289+ } catch (Exception e ) {
290+ throw new RuntimeException (e );
291+ }
292+ }
113293}
0 commit comments