]> git.basschouten.com Git - openhab-addons.git/blob
6413ecd3684132ac9842a93be4c9e15b1891e0bb
[openhab-addons.git] /
1 /**
2  * Copyright (c) 2010-2022 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.bluetooth.bluez.internal;
14
15 import static org.junit.jupiter.api.Assertions.*;
16
17 import org.eclipse.jdt.annotation.NonNull;
18 import org.junit.jupiter.api.Test;
19 import org.openhab.binding.bluetooth.BluetoothAddress;
20 import org.openhab.binding.bluetooth.bluez.internal.events.BlueZEvent;
21 import org.openhab.binding.bluetooth.bluez.internal.events.BlueZEventListener;
22
23 /**
24  *
25  * @author Benjamin Lafois - Initial Contribution
26  * @author Connor Petty - Added additional test cases
27  */
28 public class BlueZEventTest {
29
30     @Test
31     public void testDbusPathParser0() {
32         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dsqdsq/ds/dd");
33         assertEquals("hci0", event.getAdapterName());
34         assertNull(event.getDevice());
35     }
36
37     @Test
38     public void testDbusPathParser1() {
39         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_00_CC_3F_B2_7E_60");
40         assertEquals("hci0", event.getAdapterName());
41         assertEquals(new BluetoothAddress("00:CC:3F:B2:7E:60"), event.getDevice());
42     }
43
44     @Test
45     public void testDbusPathParser2() {
46         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_A4_34_D9_ED_D3_74/service0026/char0027");
47         assertEquals("hci0", event.getAdapterName());
48         assertEquals(new BluetoothAddress("A4:34:D9:ED:D3:74"), event.getDevice());
49     }
50
51     @Test
52     public void testDbusPathParser3() {
53         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_00_CC_3F_B2_7E_60/");
54         assertEquals("hci0", event.getAdapterName());
55         assertEquals(new BluetoothAddress("00:CC:3F:B2:7E:60"), event.getDevice());
56     }
57
58     @Test
59     public void testDbusPathParser4() {
60         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_");
61         assertEquals("hci0", event.getAdapterName());
62         assertNull(event.getDevice());
63     }
64
65     @Test
66     public void testDbusPathParser5() {
67         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_/");
68         assertEquals("hci0", event.getAdapterName());
69         assertNull(event.getDevice());
70     }
71
72     @Test
73     public void testDbusPathParser6() {
74         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0");
75         assertEquals("hci0", event.getAdapterName());
76         assertNull(event.getDevice());
77     }
78
79     private static class DummyBlueZEvent extends BlueZEvent {
80
81         public DummyBlueZEvent(String dbusPath) {
82             super(dbusPath);
83         }
84
85         @Override
86         public void dispatch(@NonNull BlueZEventListener listener) {
87             listener.onDBusBlueZEvent(this);
88         }
89     }
90 }