Skip to content

Commit 1bdde48

Browse files
Merge pull request #1 from RenukaHiwale9284/master
added extras
2 parents 51942f2 + 404889f commit 1bdde48

File tree

7 files changed

+71
-2
lines changed

7 files changed

+71
-2
lines changed

Data/emptyExcelData.xlsx

3.26 KB
Binary file not shown.

Data/exceldata2.xlsx

3.48 KB
Binary file not shown.

Data/exceldataBig2.xlsx

5.48 MB
Binary file not shown.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
2.Java Beans To Excel:
2+
-Converts Java Beans to Excel files (xlxs) via Apache POI including cellformats.
3+
-BeanColumn:This class represents a column in the Excel sheet. It defines properties.
4+
-FormatType:represents different data formats that a column in the Excel sheet.
5+
-bean2xlsx(List<?> data, BeanColumn[] columns, String filename, String sheetname):
6+
Converts the list of beans to an Excel file.
7+
It calls addSheet() to add data to the workbook, then writes the workbook to the specified file.
8+
-We Run Junit test cases for this project are:
9+
which is responsible for exporting data to an Excel file.
10+
exportDataToXlxs() Test Case:verify whether the Bean2xlsx class correctly exports data to
11+
an Excel file when provided with a small amount of test data.
12+
createBigXLSx() Test Case: This test case verifies the behavior of the Bean2xlsx class
13+
when dealing with a large amount of data.
14+
15+
I write my own test cases are:
16+
exportEmptyDataToXlsx() and it checks the behavior of the Bean2xlsx class
17+
when provided with an empty data list.
18+

extras.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
its a JavaBeans to Excel Project Details
2+
I add Junit test Dependency and Run Junit Test cases
3+
and I also Write My own Test case
4+

pom.xml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,24 @@
4343
<artifactId>commons-beanutils</artifactId>
4444
<version>1.9.2</version>
4545
</dependency>
46+
47+
<dependency>
48+
<groupId>org.junit.jupiter</groupId>
49+
<artifactId>junit-jupiter</artifactId>
50+
<version>5.9.3</version>
51+
<scope>test</scope>
52+
</dependency>
53+
54+
<dependency>
55+
<groupId>com.mkyong</groupId>
56+
<artifactId>poi</artifactId>
57+
<version>1.0</version>
58+
</dependency>
59+
<dependency>
60+
<groupId>demo123</groupId>
61+
<artifactId>Demo</artifactId>
62+
<version>0.0.1-SNAPSHOT</version>
63+
</dependency>
4664

4765
</dependencies>
4866
</project>

src/test/java/de/wurstcommander/bean2xlsxtest/ExportdataTest.java

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package de.wurstcommander.bean2xlsxtest;
22

3+
import static org.junit.Assert.assertTrue;
4+
5+
import java.io.File;
36
import java.util.ArrayList;
47
import java.util.List;
58

@@ -23,7 +26,7 @@ public void exportDataToXlxs() {
2326
// create testdata
2427
List<Car> data = TestData.createTestData();
2528
Bean2xlsx beanexcel = new Bean2xlsx();
26-
beanexcel.bean2xlsx(data, columns, "C://exceldata.xlsx", "Cars");
29+
beanexcel.bean2xlsx(data, columns, "Data/exceldata2.xlsx", "Cars");
2730
}
2831

2932
@Test
@@ -37,6 +40,32 @@ public void createBigXLSx() {
3740
manycars.addAll((TestData.createTestData()));
3841
}
3942
Bean2xlsx beanexcel = new Bean2xlsx();
40-
beanexcel.bean2xlsx(manycars, columns, "C://exceldataBig.xlsx", "Cars");
43+
beanexcel.bean2xlsx(manycars, columns, "Data/exceldataBig2.xlsx", "Cars");
4144
}
45+
46+
//my writen test case
47+
48+
49+
@Test
50+
public void exportEmptyDataToXlsx() {
51+
// Column definitions
52+
BeanColumn[] columns = new BeanColumn[] {
53+
new BeanColumn("name", "Carmodel", FormatType.TEXT),
54+
new BeanColumn("power", "Power", FormatType.INTEGER),
55+
new BeanColumn("priceinEuro", "Price in Euro", FormatType.MONEY) };
56+
57+
// Create an empty list for empty data
58+
List<Car> emptyData = new ArrayList<>();
59+
String excelPath = "Data/emptyExcelData.xlsx";
60+
String sheetName = "EmptyDataSheet";
61+
62+
63+
Bean2xlsx beanExcel = new Bean2xlsx();
64+
beanExcel.bean2xlsx(emptyData, columns, excelPath, sheetName);
65+
66+
// Verify test case
67+
File file = new File(excelPath);
68+
assertTrue("Excel file not created", file.exists());
69+
assertTrue("Excel file is empty", file.length() > 0);
70+
}
4271
}

0 commit comments

Comments
 (0)