]> git.basschouten.com Git - openhab-addons.git/blob
f298661cbce4a65a9bc1063f22d77f86fc09d6a8
[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.bluetooth.bluez.internal;
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 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 @NonNullByDefault
29 public class BlueZEventTest {
30
31     @Test
32     public void testDbusPathParser0() {
33         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dsqdsq/ds/dd");
34         assertEquals("hci0", event.getAdapterName());
35         assertNull(event.getDevice());
36     }
37
38     @Test
39     public void testDbusPathParser1() {
40         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_00_CC_3F_B2_7E_60");
41         assertEquals("hci0", event.getAdapterName());
42         assertEquals(new BluetoothAddress("00:CC:3F:B2:7E:60"), event.getDevice());
43     }
44
45     @Test
46     public void testDbusPathParser2() {
47         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_A4_34_D9_ED_D3_74/service0026/char0027");
48         assertEquals("hci0", event.getAdapterName());
49         assertEquals(new BluetoothAddress("A4:34:D9:ED:D3:74"), event.getDevice());
50     }
51
52     @Test
53     public void testDbusPathParser3() {
54         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_00_CC_3F_B2_7E_60/");
55         assertEquals("hci0", event.getAdapterName());
56         assertEquals(new BluetoothAddress("00:CC:3F:B2:7E:60"), event.getDevice());
57     }
58
59     @Test
60     public void testDbusPathParser4() {
61         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_");
62         assertEquals("hci0", event.getAdapterName());
63         assertNull(event.getDevice());
64     }
65
66     @Test
67     public void testDbusPathParser5() {
68         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_/");
69         assertEquals("hci0", event.getAdapterName());
70         assertNull(event.getDevice());
71     }
72
73     @Test
74     public void testDbusPathParser6() {
75         BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0");
76         assertEquals("hci0", event.getAdapterName());
77         assertNull(event.getDevice());
78     }
79
80     private static class DummyBlueZEvent extends BlueZEvent {
81
82         public DummyBlueZEvent(String dbusPath) {
83             super(dbusPath);
84         }
85
86         @Override
87         public void dispatch(BlueZEventListener listener) {
88             listener.onDBusBlueZEvent(this);
89         }
90     }
91 }