2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
7 * This program and the accompanying materials are made available under the
8 * terms of the Eclipse Public License 2.0 which is available at
9 * http://www.eclipse.org/legal/epl-2.0
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.surepetcare.internal.data;
15 import static org.junit.jupiter.api.Assertions.*;
17 import java.text.ParseException;
18 import java.time.ZonedDateTime;
19 import java.time.format.DateTimeFormatter;
21 import org.eclipse.jdt.annotation.NonNullByDefault;
22 import org.junit.jupiter.api.Test;
23 import org.openhab.binding.surepetcare.internal.SurePetcareConstants;
24 import org.openhab.binding.surepetcare.internal.dto.SurePetcarePetActivity;
27 * The {@link SurePetcarePetLocationTest} class implements unit test case for {@link SurePetcarePetLocation}
29 * @author Rene Scherer - Initial contribution
32 public class SurePetcarePetActivityTest {
34 private static final DateTimeFormatter FORMATTER = DateTimeFormatter.ISO_OFFSET_DATE_TIME;
37 public void testJsonDeserialize() throws ParseException {
38 String testReponse = "{\"tag_id\":60126,\"device_id\":376236,\"where\":2,\"since\":\"2019-09-11T13:09:07+00:00\"}";
39 SurePetcarePetActivity response = SurePetcareConstants.GSON.fromJson(testReponse, SurePetcarePetActivity.class);
41 if (response != null) {
42 assertEquals(Long.valueOf(60126), response.tagId);
43 assertEquals(Long.valueOf(376236), response.deviceId);
44 assertEquals(Integer.valueOf(2), response.where);
45 ZonedDateTime since = FORMATTER.parse("2019-09-11T13:09:07+00:00", ZonedDateTime::from);
46 assertEquals(since, response.since);
48 fail("GSON returned null");
53 public void testJsonFullSerialize() throws ParseException {
54 ZonedDateTime since = ZonedDateTime.parse("2019-09-11T13:09:07+00:00");
55 SurePetcarePetActivity location = new SurePetcarePetActivity(2, since);
57 String json = SurePetcareConstants.GSON.toJson(location, SurePetcarePetActivity.class);
59 assertEquals("{\"where\":2,\"since\":\"2019-09-11T13:09:07+00:00\"}", json);