-
-
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.
- Loading branch information
Showing
9 changed files
with
245 additions
and
4 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
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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/poiji/exception/HeaderMissingException.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,11 @@ | ||
package com.poiji.exception; | ||
|
||
/** | ||
* Exception thrown if namedHeaderMandatory is set in the options, but a header specified in an @ExcelCellName | ||
* is missing in the sheet. | ||
*/ | ||
public class HeaderMissingException extends PoijiException { | ||
public HeaderMissingException(String message) { | ||
super(message); | ||
} | ||
} |
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
55 changes: 55 additions & 0 deletions
55
src/test/java/com/poiji/deserialize/MandatoryNamedColumnsTest.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,55 @@ | ||
package com.poiji.deserialize; | ||
|
||
import com.poiji.bind.Poiji; | ||
import com.poiji.deserialize.model.byid.Person; | ||
import com.poiji.deserialize.model.byname.PersonByNameWithMissingColumn; | ||
import com.poiji.exception.HeaderMissingException; | ||
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 com.poiji.util.Data.unmarshallingPersons; | ||
|
||
@RunWith(Parameterized.class) | ||
public class MandatoryNamedColumnsTest { | ||
|
||
private String path; | ||
private List<Person> expectedPersonList; | ||
private Class<?> clazz; | ||
|
||
public MandatoryNamedColumnsTest(String path, List<Person> expectedPersonList, Class<?> clazz) { | ||
this.path = path; | ||
this.expectedPersonList = expectedPersonList; | ||
this.clazz = clazz; | ||
} | ||
|
||
@Parameterized.Parameters(name = "{index}: ({0})={1}") | ||
public static Iterable<Object[]> queries() { | ||
return Arrays.asList(new Object[][]{ | ||
{"src/test/resources/person.xlsx", unmarshallingPersons(), PersonByNameWithMissingColumn.class}, | ||
{"src/test/resources/person.xls", unmarshallingPersons(), PersonByNameWithMissingColumn.class} | ||
}); | ||
} | ||
|
||
@Test | ||
public void testExcelSuccess() { | ||
Poiji.fromExcel(new File(path), PersonByNameWithMissingColumn.class, PoijiOptions.PoijiOptionsBuilder | ||
.settings() | ||
.namedHeaderMandatory(false) | ||
.build()); | ||
} | ||
|
||
@Test(expected = HeaderMissingException.class) | ||
public void testExcelFail() { | ||
|
||
Poiji.fromExcel(new File(path), PersonByNameWithMissingColumn.class, PoijiOptions.PoijiOptionsBuilder | ||
.settings() | ||
.namedHeaderMandatory(true) | ||
.build()); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
src/test/java/com/poiji/deserialize/model/byname/PersonByNameWithMissingColumn.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.byname; | ||
|
||
import com.poiji.annotation.ExcelCellName; | ||
import com.poiji.annotation.ExcelRow; | ||
|
||
/** | ||
* Created by ar on 9/03/2018. | ||
*/ | ||
public class PersonByNameWithMissingColumn { | ||
|
||
@ExcelCellName("Name") | ||
protected String name; | ||
|
||
@ExcelCellName("Address") | ||
protected String address; | ||
|
||
@ExcelCellName("Mobile") | ||
protected String mobile; | ||
|
||
@ExcelCellName("Email") | ||
protected String email; | ||
|
||
@ExcelCellName("This column will be missing") | ||
protected String missingColumn; | ||
|
||
@ExcelRow | ||
protected int row; | ||
|
||
public int getRow() { | ||
return row; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public void setAddress(String address) { | ||
this.address = address; | ||
} | ||
|
||
} |