Skip to content

Commit

Permalink
Test Guava's Optional type as reported in Issue mtedone#23
Browse files Browse the repository at this point in the history
  • Loading branch information
daivanov committed Jan 11, 2015
1 parent ca6c9e3 commit 672afb7
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,12 @@
<version>3.0.5.RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>18.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<reporting>
Expand Down
21 changes: 21 additions & 0 deletions src/test/java/uk/co/jemos/podam/test/dto/OptionalPojo.java
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;
}
}
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());
}

}

0 comments on commit 672afb7

Please sign in to comment.