Skip to content

Commit

Permalink
adapt to core StringUtils (openhab#15781)
Browse files Browse the repository at this point in the history
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
Signed-off-by: Jørgen Austvik <jaustvik@acm.org>
  • Loading branch information
lsiepel authored and austvik committed Mar 27, 2024
1 parent 4cc459e commit a3e24bc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 61 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
package org.openhab.binding.bluetooth;

import org.eclipse.jdt.annotation.NonNullByDefault;
import org.openhab.binding.bluetooth.util.StringUtil;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.util.StringUtils;

/**
* Contains general utilities used for bluetooth tests
Expand All @@ -27,14 +27,14 @@ public class TestUtils {
public static BluetoothAddress randomAddress() {
StringBuilder builder = new StringBuilder();
for (int i = 0; i < 5; i++) {
builder.append(StringUtil.randomHex(2));
builder.append(StringUtils.getRandomHex(2));
builder.append(":");
}
builder.append(StringUtil.randomHex(2));
builder.append(StringUtils.getRandomHex(2));
return new BluetoothAddress(builder.toString());
}

public static ThingUID randomThingUID() {
return new ThingUID(BluetoothBindingConstants.BINDING_ID, StringUtil.randomAlphabetic(6));
return new ThingUID(BluetoothBindingConstants.BINDING_ID, StringUtils.getRandomAlphabetic(6));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryDevice;
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryParticipant;
import org.openhab.binding.bluetooth.notification.BluetoothConnectionStatusNotification;
import org.openhab.binding.bluetooth.util.StringUtil;
import org.openhab.core.config.discovery.DiscoveryListener;
import org.openhab.core.config.discovery.DiscoveryResult;
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
import org.openhab.core.thing.ThingTypeUID;
import org.openhab.core.thing.ThingUID;
import org.openhab.core.util.StringUtils;

/**
* Tests {@link BluetoothDiscoveryService}.
Expand Down Expand Up @@ -196,7 +196,7 @@ public void connectionParticipantTest() {

MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(address);
String deviceName = StringUtil.randomAlphanummeric(10);
String deviceName = StringUtils.getRandomAlphanumeric(10);
mockDevice.setDeviceName(deviceName);

BluetoothDevice device = Mockito.spy(mockDevice);
Expand All @@ -223,7 +223,7 @@ public void multiDiscoverySingleConnectionTest() {
MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);
MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);
String deviceName = StringUtil.randomAlphanummeric(10);
String deviceName = StringUtils.getRandomAlphanumeric(10);
mockDevice1.setDeviceName(deviceName);
mockDevice2.setDeviceName(deviceName);

Expand Down Expand Up @@ -261,7 +261,7 @@ public void multiDiscoverySingleConnectionTest() {
public void nonConnectionParticipantTest() {
MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(TestUtils.randomAddress());
String deviceName = StringUtil.randomAlphanummeric(10);
String deviceName = StringUtils.getRandomAlphanumeric(10);
mockDevice.setDeviceName(deviceName);

BluetoothDevice device = Mockito.spy(mockDevice);
Expand Down Expand Up @@ -418,7 +418,7 @@ public void recursiveFutureTest() throws InterruptedException {
MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();
MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);
MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);
String deviceName = StringUtil.randomAlphanummeric(10);
String deviceName = StringUtils.getRandomAlphanumeric(10);

MockDiscoveryParticipant participant2 = new MockDiscoveryParticipant() {
@Override
Expand Down Expand Up @@ -534,7 +534,7 @@ private class MockDiscoveryParticipant implements BluetoothDiscoveryParticipant
private ThingTypeUID typeUID;

public MockDiscoveryParticipant() {
this.typeUID = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, StringUtil.randomAlphabetic(6));
this.typeUID = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, StringUtils.getRandomAlphabetic(6));
}

@Override
Expand All @@ -544,20 +544,20 @@ public Set<ThingTypeUID> getSupportedThingTypeUIDs() {

@Override
public @Nullable DiscoveryResult createResult(BluetoothDiscoveryDevice device) {
String repProp = StringUtil.randomAlphabetic(6);
String repProp = StringUtils.getRandomAlphabetic(6);
ThingUID thingUID = getThingUID(device);
if (thingUID == null) {
return null;
}
return DiscoveryResultBuilder.create(thingUID).withLabel(StringUtil.randomAlphabetic(6))
.withProperty(repProp, StringUtil.randomAlphabetic(6)).withRepresentationProperty(repProp)
return DiscoveryResultBuilder.create(thingUID).withLabel(StringUtils.getRandomAlphabetic(6))
.withProperty(repProp, StringUtils.getRandomAlphabetic(6)).withRepresentationProperty(repProp)
.withBridge(device.getAdapter().getUID()).build();
}

@Override
public @Nullable ThingUID getThingUID(BluetoothDiscoveryDevice device) {
String deviceName = device.getName();
String id = deviceName != null ? deviceName : StringUtil.randomAlphabetic(6);
String id = deviceName != null ? deviceName : StringUtils.getRandomAlphabetic(6);
return new ThingUID(typeUID, device.getAdapter().getUID(), id);
}
}
Expand Down

0 comments on commit a3e24bc

Please sign in to comment.