]> git.basschouten.com Git - openhab-addons.git/blob
1fbae8e4ea585ba9c01a35a83e35b70682a57df5
[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.lametrictime.internal.api.local.dto;
14
15 import static org.junit.jupiter.api.Assertions.assertEquals;
16
17 import java.io.FileReader;
18
19 import org.junit.jupiter.api.BeforeAll;
20 import org.junit.jupiter.api.Test;
21 import org.openhab.binding.lametrictime.internal.api.common.impl.GsonGenerator;
22 import org.openhab.binding.lametrictime.internal.api.test.AbstractTest;
23
24 import com.google.gson.Gson;
25
26 /**
27  * bluetooth test.
28  *
29  * @author Gregory Moyer - Initial contribution
30  */
31 public class BluetoothTest extends AbstractTest {
32     private static Gson gson;
33
34     @BeforeAll
35     public static void setUpBeforeClass() {
36         gson = GsonGenerator.create(true);
37     }
38
39     @Test
40     public void testSerializeAllFields() throws Exception {
41         Bluetooth bluetooth = new Bluetooth().withActive(false).withAvailable(true).withDiscoverable(false)
42                 .withMac("AA:AA:AA:AA:AA:AA").withName("LM9999").withPairable(true);
43         assertEquals(readJson("bluetooth-mac-address.json"), gson.toJson(bluetooth));
44     }
45
46     @Test
47     public void testDeserializeMac() throws Exception {
48         try (FileReader reader = new FileReader(getTestDataFile("bluetooth-mac.json"))) {
49             Bluetooth bluetooth = gson.fromJson(reader, Bluetooth.class);
50             assertEquals(false, bluetooth.isActive());
51             assertEquals(true, bluetooth.isAvailable());
52             assertEquals(false, bluetooth.isDiscoverable());
53             assertEquals("AA:AA:AA:AA:AA:AA", bluetooth.getMac());
54             assertEquals("LM9999", bluetooth.getName());
55             assertEquals(true, bluetooth.isPairable());
56         }
57     }
58
59     @Test
60     public void testDeserializeAddress() throws Exception {
61         try (FileReader reader = new FileReader(getTestDataFile("bluetooth-address.json"))) {
62             Bluetooth bluetooth = gson.fromJson(reader, Bluetooth.class);
63             assertEquals(false, bluetooth.isActive());
64             assertEquals(true, bluetooth.isAvailable());
65             assertEquals(false, bluetooth.isDiscoverable());
66             assertEquals("AA:AA:AA:AA:AA:AA", bluetooth.getMac());
67             assertEquals("LM9999", bluetooth.getName());
68             assertEquals(true, bluetooth.isPairable());
69         }
70     }
71 }