Skip to content
Snippets Groups Projects
Commit 0c048b52 authored by ttschol's avatar ttschol
Browse files

Made TODOs in FindDevicesManager more explicit, added further tests for manager

parent bd181f91
No related branches found
No related tags found
No related merge requests found
Pipeline #41594 passed
......@@ -8,7 +8,7 @@ import java.util.*;
// TODO: use logging instead of System.out
// TODO: add variable such as 'running' to stop searching in a graceful way
// TODO: add variable such as 'running' to stop searching earlier in a graceful way e.g. when using signal handling
/**
* A class for found Bluetooth devices
......@@ -29,7 +29,7 @@ public class FindDevicesManager {
}
// TODO: could search for devices based on information from server e.g. at least two devices
// with a certain ID should be reachable
// with a certain ID should be reachable from this machine based on MAC address
/**
* Search for Bluetooth devices until either at least one device could be found or until
......
......@@ -7,6 +7,7 @@ import tinyb.BluetoothDevice;
import tinyb.BluetoothManager;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
......@@ -43,6 +44,44 @@ public class FindDevicesManagerTest {
}
}
@Test
public void testFindDevicesNoSearchDeviceNameFilter() throws InterruptedException {
BluetoothManager bluetoothManager = Mockito.mock(BluetoothManager.class);
List<BluetoothDevice> mockDevices = utilMockDevices();
when(bluetoothManager.getDevices()).thenReturn(mockDevices);
FindDevicesManager findDevicesManager = new FindDevicesManager("");
Assert.assertNotNull(findDevicesManager);
Assert.assertTrue(findDevicesManager.findDevices(bluetoothManager));
Set<BluetoothDevice> devices = findDevicesManager.getFoundDevices();
Assert.assertNotNull(devices);
Assert.assertEquals(3, devices.size());
}
@Test
public void testFindDevicesNull() throws InterruptedException {
BluetoothManager bluetoothManager = Mockito.mock(BluetoothManager.class);
when(bluetoothManager.getDevices()).thenReturn(null);
FindDevicesManager findDevicesManager = new FindDevicesManager("TimeFlip");
Assert.assertNotNull(findDevicesManager);
Assert.assertFalse(findDevicesManager.findDevices(bluetoothManager));
}
@Test
public void testFindDevicesFoundAfterSomeTime() throws InterruptedException {
BluetoothManager bluetoothManager = Mockito.mock(BluetoothManager.class);
List<BluetoothDevice> mockDevices = utilMockDevices();
when(bluetoothManager.getDevices())
.thenReturn(Collections.emptyList())
.thenReturn(Collections.emptyList())
.thenReturn(mockDevices);
FindDevicesManager findDevicesManager = new FindDevicesManager("TimeFlip");
Assert.assertNotNull(findDevicesManager);
Assert.assertTrue(findDevicesManager.findDevices(bluetoothManager));
}
@Test
public void testFindDevicesFailed() throws InterruptedException {
BluetoothManager bluetoothManager = Mockito.mock(BluetoothManager.class);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment