添加新的测试代码
This commit is contained in:
parent
f3f528cf1c
commit
b498a8f105
|
@ -1,19 +1,23 @@
|
||||||
package com.ossez.jackson.optionalwithjackson;
|
package com.ossez.jackson.optionalwithjackson;
|
||||||
|
|
||||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.JsonMappingException;
|
||||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
|
||||||
|
|
||||||
import static io.restassured.path.json.JsonPath.from;
|
import static io.restassured.path.json.JsonPath.from;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class OptionalTypeUnitTest {
|
public class OptionalTypeUnitTest {
|
||||||
|
|
||||||
ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module());
|
ObjectMapper mapper = new ObjectMapper().registerModule(new Jdk8Module());
|
||||||
|
|
||||||
@Test
|
|
||||||
public void givenPresentOptional_whenSerializing_thenValueInJson() throws JsonProcessingException {
|
public void givenPresentOptional_whenSerializing_thenValueInJson() throws JsonProcessingException {
|
||||||
|
|
||||||
String subTitle = "The Parish Boy's Progress";
|
String subTitle = "The Parish Boy's Progress";
|
||||||
|
@ -26,6 +30,12 @@ public class OptionalTypeUnitTest {
|
||||||
assertThat(from(result).getString("subTitle")).isEqualTo(subTitle);
|
assertThat(from(result).getString("subTitle")).isEqualTo(subTitle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void givenFieldWithValue_whenDeserializing_thenThrowExceptio() throws JsonProcessingException {
|
||||||
|
String bookJson = "{ \"title\": \"Oliver Twist\", \"subTitle\": \"foo\" }";
|
||||||
|
Book result = mapper.readValue(bookJson, Book.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void givenEmptyOptional_whenSerializing_thenNullValue() throws JsonProcessingException {
|
public void givenEmptyOptional_whenSerializing_thenNullValue() throws JsonProcessingException {
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue