Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
205 additions
and
16 deletions.
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
73 changes: 73 additions & 0 deletions
73
src/test/java/com/poiji/deserialize/MultiHeadersExcelSheetTest.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,73 @@ | ||
package com.poiji.deserialize; | ||
|
||
import com.poiji.bind.Poiji; | ||
import com.poiji.deserialize.model.byid.PersonATest; | ||
import com.poiji.deserialize.model.byid.PersonBTest; | ||
import com.poiji.deserialize.model.byid.PersonCreditInfo; | ||
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.Arrays; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.*; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.fail; | ||
|
||
@RunWith(Parameterized.class) | ||
public class MultiHeadersExcelSheetTest { | ||
|
||
private String path; | ||
|
||
public MultiHeadersExcelSheetTest(String path) { | ||
this.path = path; | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Iterable<Object[]> queries() { | ||
return Arrays.asList(new Object[][]{ | ||
{"src/test/resources/test-multi-headers.xlsx"}, | ||
{"src/test/resources/test-multi-headers.xls"} | ||
}); | ||
} | ||
|
||
@Test | ||
public void shouldRetrieveDataWith2LevelHeaders() { | ||
try { | ||
PoijiOptions options = PoijiOptions.PoijiOptionsBuilder.settings() | ||
.headerCount(2) | ||
.trimCellValue(true) | ||
.build(); | ||
List<PersonCreditInfo> actualPersonalCredits = | ||
Poiji.fromExcel(new File(path), PersonCreditInfo.class, options); | ||
|
||
assertThat(actualPersonalCredits, notNullValue()); | ||
assertThat(actualPersonalCredits.size(), not(0)); | ||
assertThat(actualPersonalCredits.size(), is(3)); | ||
|
||
PersonCreditInfo personCreditInfo1 = actualPersonalCredits.get(0); | ||
PersonCreditInfo personCreditInfo2 = actualPersonalCredits.get(1); | ||
|
||
PersonCreditInfo.PersonInfo expectedPerson1 = personCreditInfo1.getPersonInfo(); | ||
PersonCreditInfo.CardInfo expectedCard1 = personCreditInfo1.getCardInfo(); | ||
PersonCreditInfo.PersonInfo expectedPerson2 = personCreditInfo2.getPersonInfo(); | ||
PersonCreditInfo.CardInfo expectedCard2 = personCreditInfo2.getCardInfo(); | ||
|
||
assertThat(expectedPerson1.getAge(), is(21)); | ||
assertThat(expectedPerson2.getCity(), is("Greenbelt")); | ||
assertThat(expectedPerson1.getName(), is("John Doe")); | ||
assertThat(expectedPerson2.getState(), is("Maryland")); | ||
assertThat(expectedPerson1.getZipCode(), is("22349")); | ||
|
||
assertThat(expectedCard1.getType(), is("VISA")); | ||
assertThat(expectedCard2.getLast4Digits(), is("2345")); | ||
assertThat(expectedCard1.getExpirationDate(), is("Jan-21")); | ||
} catch (Exception e) { | ||
fail(e.getMessage()); | ||
} | ||
} | ||
|
||
} |
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
82 changes: 82 additions & 0 deletions
82
src/test/java/com/poiji/deserialize/model/byid/PersonCreditInfo.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,82 @@ | ||
package com.poiji.deserialize.model.byid; | ||
|
||
import com.poiji.annotation.ExcelCellName; | ||
import com.poiji.annotation.ExcelCellRange; | ||
|
||
public class PersonCreditInfo { | ||
|
||
@ExcelCellName("No.") | ||
private Integer no; | ||
|
||
@ExcelCellRange | ||
private PersonInfo personInfo; | ||
|
||
@ExcelCellRange | ||
private CardInfo cardInfo; | ||
|
||
public Integer getNo() { | ||
return no; | ||
} | ||
|
||
public PersonInfo getPersonInfo() { | ||
return personInfo; | ||
} | ||
|
||
public CardInfo getCardInfo() { | ||
return cardInfo; | ||
} | ||
|
||
public static class PersonInfo { | ||
@ExcelCellName("Name") | ||
private String name; | ||
@ExcelCellName("Age") | ||
private Integer age; | ||
@ExcelCellName("City") | ||
private String city; | ||
@ExcelCellName("State") | ||
private String state; | ||
@ExcelCellName("Zip Code") | ||
private String zipCode; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Integer getAge() { | ||
return age; | ||
} | ||
|
||
public String getCity() { | ||
return city; | ||
} | ||
|
||
public String getState() { | ||
return state; | ||
} | ||
|
||
public String getZipCode() { | ||
return zipCode; | ||
} | ||
} | ||
|
||
public static class CardInfo { | ||
@ExcelCellName("Card Type") | ||
private String type; | ||
@ExcelCellName("Last 4 Digits") | ||
private String last4Digits; | ||
@ExcelCellName("Expiration Date") | ||
private String expirationDate; | ||
|
||
public String getType() { | ||
return type; | ||
} | ||
|
||
public String getLast4Digits() { | ||
return last4Digits; | ||
} | ||
|
||
public String getExpirationDate() { | ||
return expirationDate; | ||
} | ||
} | ||
} |
Binary file not shown.
Binary file not shown.