|
14 | 14 |
|
15 | 15 | import static org.junit.jupiter.api.Assertions.*;
|
16 | 16 |
|
| 17 | +import java.time.ZoneOffset; |
| 18 | +import java.time.ZonedDateTime; |
| 19 | + |
17 | 20 | import org.eclipse.jdt.annotation.NonNullByDefault;
|
18 | 21 | import org.junit.jupiter.api.Test;
|
19 | 22 | import org.openhab.binding.surepetcare.internal.SurePetcareConstants;
|
@@ -78,4 +81,49 @@ public void testGetUserNull() {
|
78 | 81 | fail("GSON returned null");
|
79 | 82 | }
|
80 | 83 | }
|
| 84 | + |
| 85 | + @Test |
| 86 | + public void testDateFormats() { |
| 87 | + String testResponse = """ |
| 88 | + { |
| 89 | + "devices": [], |
| 90 | + "households": [ |
| 91 | + { |
| 92 | + "id": 0, |
| 93 | + "name": "***", |
| 94 | + "share_code": "***", |
| 95 | + "created_user_id": 0, |
| 96 | + "timezone_id": 374, |
| 97 | + "version": "MTE=", |
| 98 | + "created_at": "2021-04-24T11:41:15+00:00", |
| 99 | + "updated_at": "2023-12-16T21:08:19.637892+00:00", |
| 100 | + "invites": [], |
| 101 | + "users": [], |
| 102 | + "timezone": { |
| 103 | + "id": 374, |
| 104 | + "name": "(UTC+02:00) Europe/Zurich", |
| 105 | + "timezone": "Europe/Zurich", |
| 106 | + "utc_offset": 7200, |
| 107 | + "created_at": "2017-08-03T08:35:34+00:00", |
| 108 | + "updated_at": "2017-08-03T08:37:15+00:00" |
| 109 | + } |
| 110 | + } |
| 111 | + ], |
| 112 | + "pets": [], |
| 113 | + "photos": [], |
| 114 | + "tags": [], |
| 115 | + "user": {} |
| 116 | + } |
| 117 | + """; |
| 118 | + |
| 119 | + SurePetcareTopology response = SurePetcareConstants.GSON.fromJson(testResponse, SurePetcareTopology.class); |
| 120 | + |
| 121 | + assertNotNull(response); |
| 122 | + assertNotNull(response.households); |
| 123 | + assertEquals(1, response.households.size()); |
| 124 | + assertEquals(ZonedDateTime.of(2021, 4, 24, 11, 41, 15, 0, ZoneOffset.UTC), |
| 125 | + response.households.get(0).createdAt); |
| 126 | + assertEquals(ZonedDateTime.of(2023, 12, 16, 21, 8, 19, 637892000, ZoneOffset.UTC), |
| 127 | + response.households.get(0).updatedAt); |
| 128 | + } |
81 | 129 | }
|
0 commit comments