22
33import exceptions .ExtensionNotValidException ;
44import exceptions .OpenWorkbookException ;
5+ import exceptions .ReadValueException ;
56import exceptions .SheetNotFoundException ;
67import org .junit .jupiter .api .Assertions ;
78import org .junit .jupiter .api .Test ;
89
910import java .io .File ;
1011import java .io .IOException ;
12+ import java .time .LocalDate ;
13+ import java .time .LocalDateTime ;
14+ import java .util .Date ;
15+ import java .util .List ;
1116
1217class ExcelCellTest {
1318
@@ -22,4 +27,50 @@ void getRow() throws OpenWorkbookException, ExtensionNotValidException, IOExcept
2227 ExcelRow excelRow1 = excelCell .getRow ();
2328 Assertions .assertEquals (excelRow , excelRow1 );
2429 }
30+
31+ @ Test
32+ void readValue () throws OpenWorkbookException , ExtensionNotValidException , IOException , SheetNotFoundException , ReadValueException {
33+ ExcelWorkbook excelWorkbook = ExcelWorkbook .open (excelFile );
34+ ExcelSheet excelSheet = excelWorkbook .getSheet ();
35+ ExcelRow excelRow = excelSheet .getRows ().get (1 );
36+ List <ExcelCell > excelCells = excelRow .getCells ();
37+ Assertions .assertEquals ("Rossi" , excelCells .get (0 ).readValue (String .class ));
38+ Assertions .assertEquals ("Mario" , excelCells .get (1 ).readValue (String .class ));
39+ Assertions .assertEquals (25 , excelCells .get (2 ).readValue (Integer .class ));
40+ Assertions .assertEquals (LocalDate .of (1987 , 5 , 22 ), excelCells .get (3 ).readValue (LocalDate .class ));
41+ Assertions .assertNotNull (excelCells .get (4 ).readValue (Date .class ));
42+ Assertions .assertEquals (28000.00 , excelCells .get (5 ).readValue (Double .class ));
43+ Assertions .assertEquals (LocalDateTime .of (2023 , 2 , 11 , 12 , 35 , 55 , 603000000 ), excelCells .get (6 ).readValue (LocalDateTime .class ));
44+ Assertions .assertEquals (true , excelCells .get (7 ).readValue (Boolean .class ));
45+ }
46+
47+ @ Test
48+ void writeValue () throws OpenWorkbookException , ExtensionNotValidException , IOException , ReadValueException {
49+ ExcelWorkbook excelWorkbook = ExcelWorkbook .open (excelFile );
50+ ExcelSheet excelSheet = excelWorkbook .getSheetOrCreate ("TestWrite" );
51+ ExcelRow excelRow = excelSheet .createRow (0 );
52+ ExcelCell excelCell = excelRow .createCell (0 );
53+ excelCell .writeValue ("Text" );
54+ ExcelCell excelCell1 = excelRow .createCell (1 );
55+ excelCell1 .writeValue (21 );
56+ ExcelCell excelCell2 = excelRow .createCell (2 );
57+ LocalDateTime localDateTime = LocalDateTime .of (2021 , 1 , 1 , 21 , 21 , 21 , 0 );
58+ excelCell2 .writeValue (localDateTime );
59+ ExcelCell excelCell3 = excelRow .createCell (3 );
60+ excelCell3 .writeValue (false );
61+ Assertions .assertEquals ("Text" , excelCell .readValue (String .class ));
62+ Assertions .assertEquals (21 , excelCell1 .readValue (Integer .class ));
63+ Assertions .assertEquals (localDateTime , excelCell2 .readValue (LocalDateTime .class ));
64+ Assertions .assertEquals (false , excelCell3 .readValue (Boolean .class ));
65+ }
66+
67+ @ Test
68+ void formatStyle () throws OpenWorkbookException , ExtensionNotValidException , IOException , SheetNotFoundException {
69+ ExcelWorkbook excelWorkbook = ExcelWorkbook .open (excelFile );
70+ ExcelSheet excelSheet = excelWorkbook .getSheet ();
71+ ExcelRow excelRow = excelSheet .getRows ().get (0 );
72+ ExcelCell excelCell = excelRow .getCells ().get (0 );
73+ excelCell .formatStyle ((short ) 1 );
74+ Assertions .assertEquals ((short ) 1 , excelCell .getCell ().getCellStyle ().getDataFormat ());
75+ }
2576}
0 commit comments