-
-
Notifications
You must be signed in to change notification settings - Fork 133
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add new test for custom config, move casting and defaultConfig to the…
… config package
- Loading branch information
1 parent
bb484ff
commit 9ac894a
Showing
9 changed files
with
112 additions
and
8 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
4 changes: 3 additions & 1 deletion
4
src/main/java/com/poiji/util/Casting.java → src/main/java/com/poiji/config/Casting.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.poiji.deserialize; | ||
|
||
import com.poiji.bind.Poiji; | ||
import com.poiji.config.Casting; | ||
import com.poiji.deserialize.model.byid.ConfigPerson; | ||
import com.poiji.option.PoijiOptions; | ||
import org.junit.Test; | ||
|
||
import java.io.File; | ||
import java.util.List; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.CoreMatchers.not; | ||
import static org.hamcrest.CoreMatchers.notNullValue; | ||
import static org.junit.Assert.assertThat; | ||
|
||
/** | ||
* Created by hakan on 2018-12-01 | ||
*/ | ||
public class CustomConfigTest { | ||
|
||
@Test | ||
public void shouldUseCustomConfig() { | ||
|
||
PoijiOptions poijiOptions = PoijiOptions.PoijiOptionsBuilder.settings() | ||
.withCasting(new MyConfig()) | ||
.build(); | ||
|
||
List<ConfigPerson> actualEmployees = Poiji.fromExcel(new File("src/test/resources/employees.xlsx"), ConfigPerson.class, poijiOptions); | ||
|
||
assertThat(actualEmployees, notNullValue()); | ||
assertThat(actualEmployees.size(), not(0)); | ||
|
||
ConfigPerson actualEmployee1 = actualEmployees.get(0); | ||
|
||
assertThat(actualEmployee1.getEmployeeId(), is("123923")); | ||
assertThat(actualEmployee1.getAge(), is("30")); | ||
assertThat(actualEmployee1.getBirthday(), is("4/9/1987")); | ||
assertThat(actualEmployee1.getName(), is("Joe")); | ||
assertThat(actualEmployee1.getSurname(), is("Doe")); | ||
|
||
} | ||
|
||
static class MyConfig implements Casting { | ||
@Override | ||
public Object castValue(Class<?> fieldType, String value, PoijiOptions options) { | ||
return value.trim(); | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
src/test/java/com/poiji/deserialize/model/byid/ConfigPerson.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,52 @@ | ||
package com.poiji.deserialize.model.byid; | ||
|
||
import com.poiji.annotation.ExcelCell; | ||
|
||
/** | ||
* Created by hakan on 2018-12-01 | ||
*/ | ||
public class ConfigPerson { | ||
|
||
@ExcelCell(0) | ||
protected String employeeId; | ||
|
||
@ExcelCell(1) | ||
protected String name; | ||
|
||
@ExcelCell(2) | ||
protected String surname; | ||
|
||
@ExcelCell(3) | ||
protected String age; | ||
|
||
@ExcelCell(4) | ||
protected String single; | ||
|
||
@ExcelCell(5) | ||
protected String birthday; | ||
|
||
public String getEmployeeId() { | ||
return employeeId; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getSurname() { | ||
return surname; | ||
} | ||
|
||
public String getAge() { | ||
return age; | ||
} | ||
|
||
public String getSingle() { | ||
return single; | ||
} | ||
|
||
public String getBirthday() { | ||
return birthday; | ||
} | ||
|
||
} |
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