]> git.basschouten.com Git - openhab-addons.git/blob
513091fc427db47559a224d128db0a36f63d6085
[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 TypeTest {
27     @Test
28     public void testParseTypeWithUnknownRawValue() {
29         // given:
30         String json = "{ \"key_localized\": \"Devicetype\", \"value_raw\": 99, \"value_localized\": \"Car Vaccuum Robot\" }";
31
32         // when:
33         Type type = new Gson().fromJson(json, Type.class);
34
35         // then:
36         assertNotNull(type);
37         assertEquals("Devicetype", type.getKeyLocalized().get());
38         assertEquals(DeviceType.UNKNOWN, type.getValueRaw());
39         assertEquals("Car Vaccuum Robot", type.getValueLocalized().get());
40     }
41
42     @Test
43     public void testParseTypeWithKnownRawValue() {
44         // given:
45         String json = "{ \"key_localized\": \"Devicetype\", \"value_raw\": 1, \"value_localized\": \"Washing Machine\" }";
46
47         // when:
48         Type type = new Gson().fromJson(json, Type.class);
49
50         // then:
51         assertNotNull(type);
52         assertEquals("Devicetype", type.getKeyLocalized().get());
53         assertEquals(DeviceType.WASHING_MACHINE, type.getValueRaw());
54         assertEquals("Washing Machine", type.getValueLocalized().get());
55     }
56 }