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 org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.surepetcare.internal.SurePetcareConstants;
20 import org.openhab.binding.surepetcare.internal.dto.SurePetcareBaseObject;
23 * The {@link SurePetcareBaseObjectTest} class implements unit test case for {@link SurePetcareBaseObject}
25 * @author Rene Scherer - Initial contribution
28 public class SurePetcareBaseObjectTest {
31 public void testNotNullFromJson() {
32 String testResponse = "{\"id\":2491083182,\"version\":\"MA==\",\"created_at\":\"2019-09-18T16:09:30+00:00\",\"updated_at\":\"2019-09-18T16:09:30+00:00\"}";
33 SurePetcareBaseObject response = SurePetcareConstants.GSON.fromJson(testResponse, SurePetcareBaseObject.class);
34 if (response != null) {
35 assertEquals(Long.valueOf(2491083182L), response.id);
36 assertEquals("MA==", response.version);
37 assertNotNull(response.createdAt);
38 assertNotNull(response.updatedAt);
40 fail("GSON returned null");
45 public void testNullAttributesFromJson() {
46 String testResponse = "{\"id\":33421}";
47 SurePetcareBaseObject response = SurePetcareConstants.GSON.fromJson(testResponse, SurePetcareBaseObject.class);
49 if (response != null) {
50 assertEquals(Long.valueOf(33421), response.id);
51 assertEquals("", response.version);
52 assertNotNull(response.createdAt);
53 assertNotNull(response.updatedAt);
55 fail("GSON returned null");