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;
19 import org.openhab.binding.boschshc.internal.serialization.GsonUtils;
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 {
54 public void fromJsonNullStateForDifferentType() {
55 var state = BoschSHCServiceState.fromJson(
56 GsonUtils.DEFAULT_GSON_INSTANCE.fromJson("{\"@type\":\"differentState\"}", JsonObject.class),
58 assertEquals(null, state);
62 public void fromJsonStateObjectForValidJson() {
63 var state = BoschSHCServiceState.fromJson(
64 GsonUtils.DEFAULT_GSON_INSTANCE.fromJson("{\"@type\":\"testState\"}", JsonObject.class),
66 assertNotEquals(null, state);
70 * This checks for a bug we had where the expected type stayed the same for different state classes
73 public void fromJsonStateObjectForValidJsonAfterOtherState() {
74 BoschSHCServiceState.fromJson(
75 GsonUtils.DEFAULT_GSON_INSTANCE.fromJson("{\"@type\":\"testState\"}", JsonObject.class),
77 var state2 = BoschSHCServiceState.fromJson(
78 GsonUtils.DEFAULT_GSON_INSTANCE.fromJson("{\"@type\":\"testState2\"}", JsonObject.class),
80 assertNotEquals(null, state2);