]> git.basschouten.com Git - openhab-addons.git/blob
5da181cd18a492dd90bee0f2f8d749cbc0869de6
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2023 Contributors to the openHAB project
3  *
4  * See the NOTICE file(s) distributed with this work for additional
5  * information.
6  *
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
10  *
11  * SPDX-License-Identifier: EPL-2.0
12  */
13 package org.openhab.binding.surepetcare.internal.data;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
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;
21
22 /**
23  * The {@link SurePetcareBaseObjectTest} class implements unit test case for {@link SurePetcareBaseObject}
24  *
25  * @author Rene Scherer - Initial contribution
26  */
27 @NonNullByDefault
28 public class SurePetcareBaseObjectTest {
29
30     @Test
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);
39         } else {
40             fail("GSON returned null");
41         }
42     }
43
44     @Test
45     public void testNullAttributesFromJson() {
46         String testResponse = "{\"id\":33421}";
47         SurePetcareBaseObject response = SurePetcareConstants.GSON.fromJson(testResponse, SurePetcareBaseObject.class);
48
49         if (response != null) {
50             assertEquals(Long.valueOf(33421), response.id);
51             assertEquals("", response.version);
52             assertNotNull(response.createdAt);
53             assertNotNull(response.updatedAt);
54         } else {
55             fail("GSON returned null");
56         }
57     }
58 }