forked from mtedone/podam
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Test Guava's Optional type as reported in Issue mtedone#23
- Loading branch information
Showing
3 changed files
with
74 additions
and
0 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
21 changes: 21 additions & 0 deletions
21
src/test/java/uk/co/jemos/podam/test/dto/OptionalPojo.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,21 @@ | ||
package uk.co.jemos.podam.test.dto; | ||
|
||
import com.google.common.base.Optional; | ||
|
||
/** | ||
* POJO to test Guava Optional type. | ||
* | ||
* @author daivanov | ||
* | ||
*/ | ||
public class OptionalPojo<T> { | ||
private Optional<T> value; | ||
|
||
public Optional<T> getValue() { | ||
return value; | ||
} | ||
|
||
public void setValue(Optional<T> value) { | ||
this.value = value; | ||
} | ||
} |
47 changes: 47 additions & 0 deletions
47
src/test/java/uk/co/jemos/podam/test/unit/GuavaOptionalUnitTest.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,47 @@ | ||
package uk.co.jemos.podam.test.unit; | ||
|
||
import com.google.common.base.Optional; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Test; | ||
|
||
import uk.co.jemos.podam.api.PodamFactory; | ||
import uk.co.jemos.podam.api.PodamFactoryImpl; | ||
import uk.co.jemos.podam.test.dto.OptionalPojo; | ||
|
||
/** | ||
* Test @uk.co.jemos.podam.test.dto.OptionalPojo@ construction | ||
* | ||
* @author daivanov | ||
* | ||
*/ | ||
public class GuavaOptionalUnitTest { | ||
|
||
private final static PodamFactory podam = new PodamFactoryImpl(); | ||
|
||
@Test | ||
public void testGuavaOptionalAsPojo() throws Exception { | ||
|
||
Optional<?> pojo = podam.manufacturePojo(Optional.class, Long.class); | ||
Assert.assertNotNull("Construction failed", pojo); | ||
Assert.assertEquals("Optional should hold a value", | ||
true, pojo.isPresent()); | ||
Assert.assertNotNull("Value attr should hold an object", pojo.get()); | ||
Assert.assertEquals("Invalid object type", | ||
Long.class, pojo.get().getClass()); | ||
} | ||
|
||
@Test | ||
public void testGuavaOptionalFieldSetting() throws Exception { | ||
|
||
OptionalPojo<?> pojo = podam.manufacturePojo(OptionalPojo.class, String.class); | ||
Assert.assertNotNull("Construction failed", pojo); | ||
Assert.assertNotNull("Value attr should not be empty", pojo.getValue()); | ||
Assert.assertEquals("Optional should hold a value", | ||
true, pojo.getValue().isPresent()); | ||
Assert.assertNotNull("Value attr should hold an object", pojo.getValue().get()); | ||
Assert.assertEquals("Invalid object type", | ||
String.class, pojo.getValue().get().getClass()); | ||
} | ||
|
||
} |