-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(core): support regular expression for column name
Feature request Refs: 304
- Loading branch information
Showing
8 changed files
with
155 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/test/java/com/poiji/deserialize/ReadExcelWithRegexInColumnNameTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.poiji.deserialize; | ||
|
||
import com.poiji.bind.Poiji; | ||
import com.poiji.deserialize.model.InventoryData; | ||
import com.poiji.option.PoijiOptions; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import static com.poiji.option.PoijiOptions.PoijiOptionsBuilder.settings; | ||
import static com.poiji.util.Data.unmarshallingInventoryData; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* Test for Reading Excel columns with Regular expression (Regex) | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class ReadExcelWithRegexInColumnNameTest { | ||
private final String path; | ||
private final List<InventoryData> expectedData; | ||
private final PoijiOptions options; | ||
|
||
public ReadExcelWithRegexInColumnNameTest(String path, List<InventoryData> expectedData, PoijiOptions options) { | ||
this.path = path; | ||
this.expectedData = expectedData; | ||
this.options = options; | ||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: ({0})={1}") | ||
public static Iterable<Object[]> queries() { | ||
return List.of(new Object[][]{ | ||
{ | ||
"src/test/resources/regex/inventory.xlsx", | ||
unmarshallingInventoryData(), | ||
settings().sheetName("Books").build() | ||
}, | ||
{ | ||
"src/test/resources/regex/inventory.xlsx", | ||
unmarshallingInventoryData(), | ||
settings().sheetName("Songs").build() | ||
}, | ||
{ | ||
"src/test/resources/regex/inventory.xls", | ||
unmarshallingInventoryData(), | ||
settings().sheetName("Books").build() | ||
}, | ||
{ | ||
"src/test/resources/regex/inventory.xls", | ||
unmarshallingInventoryData(), | ||
settings().sheetName("Songs").build() | ||
}, | ||
}); | ||
} | ||
|
||
@Test | ||
public void shouldReadInventoryData() { | ||
List<InventoryData> actualData = Poiji.fromExcel(new File(path), InventoryData.class, options); | ||
|
||
assertEquals(expectedData, actualData); | ||
} | ||
|
||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/com/poiji/deserialize/model/InventoryData.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package com.poiji.deserialize.model; | ||
|
||
import com.poiji.annotation.ExcelCellName; | ||
|
||
import java.util.Objects; | ||
|
||
/** | ||
* An InventoryData POJO. | ||
*/ | ||
public class InventoryData { | ||
@ExcelCellName(value = "Id") | ||
private Integer id; | ||
|
||
@ExcelCellName(value = "", expression = "Author|Composer") | ||
private String author; | ||
|
||
public void setId(Integer id) { | ||
this.id = id; | ||
} | ||
|
||
public void setAuthor(String author) { | ||
this.author = author; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "InventoryData{" + | ||
"id='" + id + '\'' + | ||
", author='" + author + '\'' + | ||
'}'; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
InventoryData that = (InventoryData) o; | ||
return Objects.equals(id, that.id) && Objects.equals(author, that.author); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(id, author); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.