1 package com.atlassian.marketplace.client.impl;
2
3 import org.joda.time.DateTime;
4 import org.joda.time.DateTimeZone;
5 import org.joda.time.LocalDate;
6 import org.junit.Test;
7
8 import static org.hamcrest.MatcherAssert.assertThat;
9 import static org.hamcrest.Matchers.equalTo;
10
11 public class DateTimeJsonTest extends BaseJsonTests
12 {
13 @Test
14 public void dateTimeIsDecoded() throws Exception
15 {
16 assertThat(decode("{\"x\":\"2014-05-24T18:00:00.000Z\"}", HasDateTime.class).x,
17 equalTo(new DateTime(2014, 05, 24, 18, 00, 00, 000, DateTimeZone.UTC)));
18 }
19
20 @Test
21 public void localDateIsDecoded() throws Exception
22 {
23 assertThat(decode("{\"x\":\"2014-05-24\"}", HasLocalDate.class).x,
24 equalTo(new LocalDate(2014, 05, 24)));
25 }
26
27 @Test
28 public void localDateIsEncoded() throws Exception
29 {
30 HasLocalDate o = new HasLocalDate();
31 o.x = new LocalDate(2014, 05, 24);
32 assertThat(encode(o), equalTo("{\"x\":\"2014-05-24\"}"));
33 }
34
35 static final class HasDateTime
36 {
37 DateTime x;
38 }
39
40 static final class HasLocalDate
41 {
42 LocalDate x;
43 }
44 }