Skip to content

Commit

Permalink
Merge pull request #1 from RenukaHiwale9284/master
Browse files Browse the repository at this point in the history
added extras
  • Loading branch information
WurstCommander authored Mar 29, 2024
2 parents 51942f2 + 404889f commit 1bdde48
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 2 deletions.
Binary file added Data/emptyExcelData.xlsx
Binary file not shown.
Binary file added Data/exceldata2.xlsx
Binary file not shown.
Binary file added Data/exceldataBig2.xlsx
Binary file not shown.
18 changes: 18 additions & 0 deletions Documentations/JavaBeansToExcel.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
2.Java Beans To Excel:
-Converts Java Beans to Excel files (xlxs) via Apache POI including cellformats.
-BeanColumn:This class represents a column in the Excel sheet. It defines properties.
-FormatType:represents different data formats that a column in the Excel sheet.
-bean2xlsx(List<?> data, BeanColumn[] columns, String filename, String sheetname):
Converts the list of beans to an Excel file.
It calls addSheet() to add data to the workbook, then writes the workbook to the specified file.
-We Run Junit test cases for this project are:
which is responsible for exporting data to an Excel file.
exportDataToXlxs() Test Case:verify whether the Bean2xlsx class correctly exports data to
an Excel file when provided with a small amount of test data.
createBigXLSx() Test Case: This test case verifies the behavior of the Bean2xlsx class
when dealing with a large amount of data.

I write my own test cases are:
exportEmptyDataToXlsx() and it checks the behavior of the Bean2xlsx class
when provided with an empty data list.

4 changes: 4 additions & 0 deletions extras.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
its a JavaBeans to Excel Project Details
I add Junit test Dependency and Run Junit Test cases
and I also Write My own Test case

18 changes: 18 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,24 @@
<artifactId>commons-beanutils</artifactId>
<version>1.9.2</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>5.9.3</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>com.mkyong</groupId>
<artifactId>poi</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>demo123</groupId>
<artifactId>Demo</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>

</dependencies>
</project>
33 changes: 31 additions & 2 deletions src/test/java/de/wurstcommander/bean2xlsxtest/ExportdataTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package de.wurstcommander.bean2xlsxtest;

import static org.junit.Assert.assertTrue;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

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

@Test
Expand All @@ -37,6 +40,32 @@ public void createBigXLSx() {
manycars.addAll((TestData.createTestData()));
}
Bean2xlsx beanexcel = new Bean2xlsx();
beanexcel.bean2xlsx(manycars, columns, "C://exceldataBig.xlsx", "Cars");
beanexcel.bean2xlsx(manycars, columns, "Data/exceldataBig2.xlsx", "Cars");
}

//my writen test case


@Test
public void exportEmptyDataToXlsx() {
// Column definitions
BeanColumn[] columns = new BeanColumn[] {
new BeanColumn("name", "Carmodel", FormatType.TEXT),
new BeanColumn("power", "Power", FormatType.INTEGER),
new BeanColumn("priceinEuro", "Price in Euro", FormatType.MONEY) };

// Create an empty list for empty data
List<Car> emptyData = new ArrayList<>();
String excelPath = "Data/emptyExcelData.xlsx";
String sheetName = "EmptyDataSheet";


Bean2xlsx beanExcel = new Bean2xlsx();
beanExcel.bean2xlsx(emptyData, columns, excelPath, sheetName);

// Verify test case
File file = new File(excelPath);
assertTrue("Excel file not created", file.exists());
assertTrue("Excel file is empty", file.length() > 0);
}
}

0 comments on commit 1bdde48

Please sign in to comment.