2 * Copyright (c) 2010-2023 Contributors to the openHAB project
4 * See the NOTICE file(s) distributed with this work for additional
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
11 * SPDX-License-Identifier: EPL-2.0
13 package org.openhab.binding.bluetooth.bluez.internal;
15 import static org.junit.jupiter.api.Assertions.*;
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;
25 * @author Benjamin Lafois - Initial Contribution
26 * @author Connor Petty - Added additional test cases
29 public class BlueZEventTest {
32 public void testDbusPathParser0() {
33 BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dsqdsq/ds/dd");
34 assertEquals("hci0", event.getAdapterName());
35 assertNull(event.getDevice());
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());
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());
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());
60 public void testDbusPathParser4() {
61 BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_");
62 assertEquals("hci0", event.getAdapterName());
63 assertNull(event.getDevice());
67 public void testDbusPathParser5() {
68 BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_/");
69 assertEquals("hci0", event.getAdapterName());
70 assertNull(event.getDevice());
74 public void testDbusPathParser6() {
75 BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0");
76 assertEquals("hci0", event.getAdapterName());
77 assertNull(event.getDevice());
80 private static class DummyBlueZEvent extends BlueZEvent {
82 public DummyBlueZEvent(String dbusPath) {
87 public void dispatch(BlueZEventListener listener) {
88 listener.onDBusBlueZEvent(this);