2 * Copyright (c) 2010-2022 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.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;
25 * @author Benjamin Lafois - Initial Contribution
26 * @author Connor Petty - Added additional test cases
28 public class BlueZEventTest {
31 public void testDbusPathParser0() {
32 BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dsqdsq/ds/dd");
33 assertEquals("hci0", event.getAdapterName());
34 assertNull(event.getDevice());
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());
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());
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());
59 public void testDbusPathParser4() {
60 BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_");
61 assertEquals("hci0", event.getAdapterName());
62 assertNull(event.getDevice());
66 public void testDbusPathParser5() {
67 BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0/dev_/");
68 assertEquals("hci0", event.getAdapterName());
69 assertNull(event.getDevice());
73 public void testDbusPathParser6() {
74 BlueZEvent event = new DummyBlueZEvent("/org/bluez/hci0");
75 assertEquals("hci0", event.getAdapterName());
76 assertNull(event.getDevice());
79 private static class DummyBlueZEvent extends BlueZEvent {
81 public DummyBlueZEvent(String dbusPath) {
86 public void dispatch(@NonNull BlueZEventListener listener) {
87 listener.onDBusBlueZEvent(this);