]> git.basschouten.com Git - openhab-addons.git/blob
46076bfa3044f8a932703e09ab12245c100b6774
[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.mielecloud.internal.webservice.api.json;
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
20 import com.google.gson.Gson;
21
22 /**
23  * @author Björn Lange - Initial contribution
24  */
25 @NonNullByDefault
26 public class StatusTest {
27     @Test
28     public void testParseStatusWithUnknownRawValue() {
29         // given:
30         String json = "{ \"key_localized\": \"State\", \"value_raw\": 99, \"value_localized\": \"Booting\" }";
31
32         // when:
33         Status status = new Gson().fromJson(json, Status.class);
34
35         // then:
36         assertNotNull(status);
37         assertEquals("State", status.getKeyLocalized().get());
38         assertEquals(Integer.valueOf(99), status.getValueRaw().get());
39         assertEquals("Booting", status.getValueLocalized().get());
40     }
41
42     @Test
43     public void testParseStatusWithKnownRawValue() {
44         // given:
45         String json = "{ \"key_localized\": \"State\", \"value_raw\": 1, \"value_localized\": \"Off\" }";
46
47         // when:
48         Status status = new Gson().fromJson(json, Status.class);
49
50         // then:
51         assertNotNull(status);
52         assertEquals("State", status.getKeyLocalized().get());
53         assertEquals(Integer.valueOf(StateType.OFF.getCode()), status.getValueRaw().get());
54         assertEquals("Off", status.getValueLocalized().get());
55     }
56 }