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.boschshc.internal.services.dto;
15 import static org.junit.jupiter.api.Assertions.*;
17 import org.eclipse.jdt.annotation.NonNullByDefault;
18 import org.junit.jupiter.api.Test;
20 import com.google.gson.Gson;
21 import com.google.gson.JsonObject;
26 * @author Christian Oeing - Initial contribution
28 class TestState extends BoschSHCServiceState {
37 * @author Christian Oeing - Initial contribution
39 class TestState2 extends BoschSHCServiceState {
46 * Unit tests for BoschSHCServiceStateTest
48 * @author Christian Oeing - Initial contribution
51 public class BoschSHCServiceStateTest {
52 private final Gson gson = new Gson();
55 public void fromJsonNullStateForDifferentType() {
56 var state = BoschSHCServiceState.fromJson(gson.fromJson("{\"@type\":\"differentState\"}", JsonObject.class),
58 assertEquals(null, state);
62 public void fromJsonStateObjectForValidJson() {
63 var state = BoschSHCServiceState.fromJson(gson.fromJson("{\"@type\":\"testState\"}", JsonObject.class),
65 assertNotEquals(null, state);
69 * This checks for a bug we had where the expected type stayed the same for different state classes
72 public void fromJsonStateObjectForValidJsonAfterOtherState() {
73 BoschSHCServiceState.fromJson(gson.fromJson("{\"@type\":\"testState\"}", JsonObject.class), TestState.class);
74 var state2 = BoschSHCServiceState.fromJson(gson.fromJson("{\"@type\":\"testState2\"}", JsonObject.class),
76 assertNotEquals(null, state2);