From 73e006714ca2d154acfe10c6bc7dfb45da52fcf9 Mon Sep 17 00:00:00 2001 From: cowtowncoder Date: Mon, 29 Jan 2018 14:53:09 -0800 Subject: [PATCH] minor test cleanup --- .../databind/deser/creators/jdk8/Person.java | 36 ------------ .../deser/creators/jdk8/PersonTest.java | 56 ++++++++++++++----- 2 files changed, 43 insertions(+), 49 deletions(-) delete mode 100644 src/test/java/com/fasterxml/jackson/databind/deser/creators/jdk8/Person.java diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/jdk8/Person.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/jdk8/Person.java deleted file mode 100644 index 6caab79bb3..0000000000 --- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/jdk8/Person.java +++ /dev/null @@ -1,36 +0,0 @@ -package com.fasterxml.jackson.databind.deser.creators.jdk8; - -class Person { - - // mandatory fields - private final String name; - private final String surname; - - // optional fields - private String nickname; - - // no annotations are required if preconditions are met (details below) - public Person(String name, String surname) { - - this.name = name; - this.surname = surname; - } - - public String getName() { - return name; - } - - public String getSurname() { - return surname; - } - - public String getNickname() { - - return nickname; - } - - public void setNickname(String nickname) { - - this.nickname = nickname; - } -} \ No newline at end of file diff --git a/src/test/java/com/fasterxml/jackson/databind/deser/creators/jdk8/PersonTest.java b/src/test/java/com/fasterxml/jackson/databind/deser/creators/jdk8/PersonTest.java index e4fbdd77be..80fa51176c 100644 --- a/src/test/java/com/fasterxml/jackson/databind/deser/creators/jdk8/PersonTest.java +++ b/src/test/java/com/fasterxml/jackson/databind/deser/creators/jdk8/PersonTest.java @@ -1,26 +1,56 @@ package com.fasterxml.jackson.databind.deser.creators.jdk8; -import static org.assertj.core.api.BDDAssertions.then; - import java.io.IOException; +import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.databind.BaseMapTest; import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.Test; -public class PersonTest +public class PersonTest extends BaseMapTest { - @Test - public void shouldBeAbleToDeserializePerson() throws IOException + static class Person { + + // mandatory fields + private final String name; + private final String surname; + + // optional fields + private String nickname; + + // 29-Jan-2018, tatu: Should (apparently?! nice) work without annotation, as long as + // parameter names exist +// @JsonCreator(mode = JsonCreator.Mode.PROPERTIES) + public Person(String name, String surname) { + + this.name = name; + this.surname = surname; + } + + public String getName() { + return name; + } + + public String getSurname() { + return surname; + } + + public String getNickname() { + + return nickname; + } + + public void setNickname(String nickname) { + + this.nickname = nickname; + } + } + public void testPersonDeserialization() throws IOException { final ObjectMapper mapper = new ObjectMapper(); - - // when Person actual = mapper.readValue("{\"name\":\"joe\",\"surname\":\"smith\",\"nickname\":\"joey\"}", Person.class); - // then - Person expected = new Person("joe", "smith"); - expected.setNickname("joey"); - then(actual).isEqualToComparingFieldByField(expected); - + assertEquals("joe", actual.getName()); + assertEquals("smith", actual.getSurname()); + assertEquals("joey", actual.getNickname()); } }