Skip to content

Commit

Permalink
Remove support for date/time values as arrays of components #215
Browse files Browse the repository at this point in the history
* refactoring the tests for readability
  • Loading branch information
andrus committed Apr 5, 2018
1 parent 4b8b537 commit 49d475d
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 132 deletions.
Expand Up @@ -9,13 +9,8 @@
import io.bootique.log.DefaultBootLogger;

import java.io.IOException;
import java.time.Month;
import java.time.MonthDay;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.Year;
import java.time.YearMonth;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;

Expand Down Expand Up @@ -60,57 +55,11 @@ public void setC(Bean2 c) {

protected static class Bean2 {

protected Year year;
protected Month month;
protected YearMonth yearMonth;
protected MonthDay monthDay;
protected Period period;
protected OffsetTime offsetTime;
protected OffsetDateTime offsetDateTime;
protected ZonedDateTime zonedDateTime;
protected ZoneOffset zoneOffset;


public Year getYear() {
return year;
}

public void setYear(Year year) {
this.year = year;
}

public Month getMonth() {
return month;
}

public void setMonth(Month month) {
this.month = month;
}

public YearMonth getYearMonth() {
return yearMonth;
}

public void setYearMonth(YearMonth yearMonth) {
this.yearMonth = yearMonth;
}

public MonthDay getMonthDay() {
return monthDay;
}

public void setMonthDay(MonthDay monthDay) {
this.monthDay = monthDay;
}

public Period getPeriod() {
return period;
}

public void setPeriod(Period period) {
this.period = period;
}

public OffsetTime getOffsetTime() {
return offsetTime;
}
Expand Down
Expand Up @@ -9,51 +9,45 @@
import java.time.MonthDay;
import java.time.temporal.TemporalAccessor;

import static junit.framework.TestCase.assertTrue;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class MonthDayDeserializerIT extends DeserializerTestBase {

@Test
public void testDeserialization01() throws Exception {
MonthDay monthDay = MonthDay.of(Month.JANUARY, 17);

MonthDay value = deserialize(MonthDay.class, "\"--01-17\"");

assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", monthDay, value);
public void testDeserialization_Value1() throws Exception {
MonthDay md = deserialize(MonthDay.class, "\"--01-17\"");
assertEquals(MonthDay.of(Month.JANUARY, 17), md);
}

@Test
public void testDeserialization02() throws Exception {
MonthDay monthDay = MonthDay.of(Month.AUGUST, 21);

MonthDay value = deserialize(MonthDay.class, "\"--08-21\"");

assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", monthDay, value);
public void testDeserialization_Value2() throws Exception {
MonthDay md = deserialize(MonthDay.class, "\"--08-21\"");
assertEquals(MonthDay.of(Month.AUGUST, 21), md);
}

@Test
public void testDeserialization03() throws IOException {
Bean1 bean1 = deserialize(Bean1.class, "a: \"x\"\n" +
"c:\n" +
" monthDay: --08-21");
assertEquals(MonthDay.of(Month.AUGUST, 21), bean1.c.monthDay);
public void testDeserialization_Object() throws IOException {
Bean md = deserialize(Bean.class, "monthDay: --08-21");
assertEquals(MonthDay.of(Month.AUGUST, 21), md.monthDay);
}

@Test
public void testDeserializationWithTypeInfo01() throws Exception {
MonthDay monthDay = MonthDay.of(Month.NOVEMBER, 5);
public void testDeserializationWithTypeInfo() throws Exception {

ObjectMapper mapper = createMapper();
mapper.addMixIn(TemporalAccessor.class, MockObjectConfiguration.class);
TemporalAccessor value = mapper.readValue("[\"" + MonthDay.class.getName() + "\",\"--11-05\"]", TemporalAccessor.class);

assertNotNull("The value should not be null.", value);
assertTrue("The value should be a MonthDay.", value instanceof MonthDay);
assertEquals("The value is not correct.", monthDay, value);
assertEquals(MonthDay.of(Month.NOVEMBER, 5), value);
}

static class Bean {

protected MonthDay monthDay;

public void setMonthDay(MonthDay monthDay) {
this.monthDay = monthDay;
}
}

}
Expand Up @@ -6,34 +6,33 @@
import java.time.Period;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class PeriodDeserializerIT extends DeserializerTestBase {
@Test
public void testDeserialization01() throws Exception {
Period period = Period.of(5, 2, 3);

Period value = deserialize(Period.class, "\"" + period.toString() + "\"");
@Test
public void testDeserialization_Value1() throws Exception {
Period p = deserialize(Period.class, "\"P5Y2M3D\"");
assertEquals(Period.of(5, 2, 3), p);
}

assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", period, value);
@Test
public void testDeserialization_Value2() throws Exception {
Period p = deserialize(Period.class, "\"P5Y8M3D\"");
assertEquals(Period.of(5, 8, 3), p);
}

@Test
public void testDeserialization02() throws Exception {
Period period = Period.of(5, 8, 3);
public void testDeserialization_Object() throws IOException {
Bean p = deserialize(Bean.class, "period: P5Y8M3D");
assertEquals(Period.of(5, 8, 3), p.period);
}

Period value = deserialize(Period.class, "\"P5Y8M3D\"");
static class Bean {

assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", period, value);
}
protected Period period;

@Test
public void testDeserialization03() throws IOException {
Bean1 bean1 = deserialize(Bean1.class, "a: \"x\"\n" +
"c:\n" +
" period: P5Y8M3D");
assertEquals(Period.of(5, 8, 3), bean1.c.period);
public void setPeriod(Period period) {
this.period = period;
}
}
}
26 changes: 13 additions & 13 deletions bootique/src/test/java/io/bootique/jackson/YearDeserializerIT.java
Expand Up @@ -10,23 +10,23 @@
public class YearDeserializerIT extends DeserializerTestBase {

@Test
public void testDeserialization01() throws Exception {
public void testDeserialization_Value() throws Exception {
Year value = deserialize(Year.class, "1986");
assertEquals("The value is not correct.", Year.of(1986), value);
assertEquals(Year.of(1986), value);
}

@Test
public void testDeserialization02() throws Exception {
Bean1 bean1 = deserialize(Bean1.class, "a: \"x\"\n" +
"c:\n" +
" year: 2017");
assertEquals("The value is not correct.", Year.of(2017), bean1.c.year);
public void testDeserialization_Object() throws Exception {
Bean o = deserialize(Bean.class, "year: 2017");
assertEquals(Year.of(2017), o.year);
}
@Test
public void testDeserialization03() throws Exception {
Bean1 bean1 = deserialize(Bean1.class, "a: \"x\"\n" +
"c:\n" +
" year: " + Year.of(2017).toString());
assertEquals("The value is not correct.", Year.of(2017), bean1.c.year);

static class Bean {

protected Year year;

public void setYear(Year year) {
this.year = year;
}
}
}
Expand Up @@ -9,46 +9,34 @@
import java.time.YearMonth;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;

public class YearMonthDeserializerIT extends DeserializerTestBase {

@Test
public void testDeserializationAsString01() throws Exception {
YearMonth yearMonth = YearMonth.of(1986, Month.JANUARY);
YearMonth value = deserialize(YearMonth.class, '"' + yearMonth.toString() + '"');

assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", yearMonth, value);
public void testDeserialization_Value1() throws Exception {
YearMonth ym = deserialize(YearMonth.class, "\"1986-01\"");
assertEquals(YearMonth.of(1986, Month.JANUARY), ym);
}

@Test
public void testDeserializationAsString02() throws Exception {
YearMonth yearMonth = YearMonth.of(2013, Month.AUGUST);
YearMonth value = deserialize(YearMonth.class, '"' + yearMonth.toString() + '"');

assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", yearMonth, value);
public void testDeserialization_Value2() throws Exception {
YearMonth ym = deserialize(YearMonth.class, "\"2013-08\"");
assertEquals(YearMonth.of(2013, Month.AUGUST), ym);
}

@Test
public void testDeserializationWithPattern01() throws Exception {
YearMonth yearMonth = YearMonth.of(2013, Month.AUGUST);
SimpleAggregate simpleAggregate = new SimpleAggregate(yearMonth);

SimpleAggregate value = deserialize(SimpleAggregate.class, "{\"yearMonth\":\"1308\"}");

assertNotNull("The value should not be null.", value);
assertEquals("The value is not correct.", simpleAggregate.yearMonth, value.yearMonth);
public void testDeserialization_Pattern() throws Exception {
YM_Pattern ym = deserialize(YM_Pattern.class, "yearMonth: \"1308\"");
assertEquals(YearMonth.of(2013, Month.AUGUST), ym.yearMonth);
}

private static class SimpleAggregate {
private static class YM_Pattern {
@JsonProperty("yearMonth")
@JsonFormat(pattern = "yyMM")
final YearMonth yearMonth;

@JsonCreator
SimpleAggregate(@JsonProperty("yearMonth") YearMonth yearMonth) {
YM_Pattern(@JsonProperty("yearMonth") YearMonth yearMonth) {
this.yearMonth = yearMonth;
}
}
Expand Down

0 comments on commit 49d475d

Please sign in to comment.