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.assertEquals;
16 import static org.junit.jupiter.api.Assertions.assertNotEquals;
18 import org.eclipse.jdt.annotation.NonNullByDefault;
19 import org.junit.jupiter.api.Test;
21 import com.google.gson.Gson;
22 import com.google.gson.JsonObject;
27 * @author Christian Oeing - Initial contribution
29 class TestState extends BoschSHCServiceState {
38 * @author Christian Oeing - Initial contribution
40 class TestState2 extends BoschSHCServiceState {
47 * Unit tests for BoschSHCServiceStateTest
49 * @author Christian Oeing - Initial contribution
52 public class BoschSHCServiceStateTest {
53 private final Gson gson = new Gson();
56 public void fromJson_nullStateForDifferentType() {
57 var state = BoschSHCServiceState.fromJson(gson.fromJson("{\"@type\":\"differentState\"}", JsonObject.class),
59 assertEquals(null, state);
63 public void fromJson_stateObjectForValidJson() {
64 var state = BoschSHCServiceState.fromJson(gson.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 fromJson_stateObjectForValidJsonAfterOtherState() {
74 BoschSHCServiceState.fromJson(gson.fromJson("{\"@type\":\"testState\"}", JsonObject.class), TestState.class);
75 var state2 = BoschSHCServiceState.fromJson(gson.fromJson("{\"@type\":\"testState2\"}", JsonObject.class),
77 assertNotEquals(null, state2);