Skip to content

Commit 7d63504

Browse files
authored
adapt to core StringUtils (openhab#15781)
Signed-off-by: Leo Siepel <[email protected]>
1 parent bf0cc2b commit 7d63504

File tree

3 files changed

+14
-61
lines changed

3 files changed

+14
-61
lines changed

bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/util/StringUtil.java

-47
This file was deleted.

bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/TestUtils.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
package org.openhab.binding.bluetooth;
1414

1515
import org.eclipse.jdt.annotation.NonNullByDefault;
16-
import org.openhab.binding.bluetooth.util.StringUtil;
1716
import org.openhab.core.thing.ThingUID;
17+
import org.openhab.core.util.StringUtils;
1818

1919
/**
2020
* Contains general utilities used for bluetooth tests
@@ -27,14 +27,14 @@ public class TestUtils {
2727
public static BluetoothAddress randomAddress() {
2828
StringBuilder builder = new StringBuilder();
2929
for (int i = 0; i < 5; i++) {
30-
builder.append(StringUtil.randomHex(2));
30+
builder.append(StringUtils.getRandomHex(2));
3131
builder.append(":");
3232
}
33-
builder.append(StringUtil.randomHex(2));
33+
builder.append(StringUtils.getRandomHex(2));
3434
return new BluetoothAddress(builder.toString());
3535
}
3636

3737
public static ThingUID randomThingUID() {
38-
return new ThingUID(BluetoothBindingConstants.BINDING_ID, StringUtil.randomAlphabetic(6));
38+
return new ThingUID(BluetoothBindingConstants.BINDING_ID, StringUtils.getRandomAlphabetic(6));
3939
}
4040
}

bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,12 @@
4747
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryDevice;
4848
import org.openhab.binding.bluetooth.discovery.BluetoothDiscoveryParticipant;
4949
import org.openhab.binding.bluetooth.notification.BluetoothConnectionStatusNotification;
50-
import org.openhab.binding.bluetooth.util.StringUtil;
5150
import org.openhab.core.config.discovery.DiscoveryListener;
5251
import org.openhab.core.config.discovery.DiscoveryResult;
5352
import org.openhab.core.config.discovery.DiscoveryResultBuilder;
5453
import org.openhab.core.thing.ThingTypeUID;
5554
import org.openhab.core.thing.ThingUID;
55+
import org.openhab.core.util.StringUtils;
5656

5757
/**
5858
* Tests {@link BluetoothDiscoveryService}.
@@ -196,7 +196,7 @@ public void connectionParticipantTest() {
196196

197197
MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
198198
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(address);
199-
String deviceName = StringUtil.randomAlphanummeric(10);
199+
String deviceName = StringUtils.getRandomAlphanumeric(10);
200200
mockDevice.setDeviceName(deviceName);
201201

202202
BluetoothDevice device = Mockito.spy(mockDevice);
@@ -223,7 +223,7 @@ public void multiDiscoverySingleConnectionTest() {
223223
MockBluetoothAdapter mockAdapter2 = new MockBluetoothAdapter();
224224
MockBluetoothDevice mockDevice1 = mockAdapter1.getDevice(address);
225225
MockBluetoothDevice mockDevice2 = mockAdapter2.getDevice(address);
226-
String deviceName = StringUtil.randomAlphanummeric(10);
226+
String deviceName = StringUtils.getRandomAlphanumeric(10);
227227
mockDevice1.setDeviceName(deviceName);
228228
mockDevice2.setDeviceName(deviceName);
229229

@@ -261,7 +261,7 @@ public void multiDiscoverySingleConnectionTest() {
261261
public void nonConnectionParticipantTest() {
262262
MockBluetoothAdapter mockAdapter1 = new MockBluetoothAdapter();
263263
MockBluetoothDevice mockDevice = mockAdapter1.getDevice(TestUtils.randomAddress());
264-
String deviceName = StringUtil.randomAlphanummeric(10);
264+
String deviceName = StringUtils.getRandomAlphanumeric(10);
265265
mockDevice.setDeviceName(deviceName);
266266

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

423423
MockDiscoveryParticipant participant2 = new MockDiscoveryParticipant() {
424424
@Override
@@ -534,7 +534,7 @@ private class MockDiscoveryParticipant implements BluetoothDiscoveryParticipant
534534
private ThingTypeUID typeUID;
535535

536536
public MockDiscoveryParticipant() {
537-
this.typeUID = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, StringUtil.randomAlphabetic(6));
537+
this.typeUID = new ThingTypeUID(BluetoothBindingConstants.BINDING_ID, StringUtils.getRandomAlphabetic(6));
538538
}
539539

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

545545
@Override
546546
public @Nullable DiscoveryResult createResult(BluetoothDiscoveryDevice device) {
547-
String repProp = StringUtil.randomAlphabetic(6);
547+
String repProp = StringUtils.getRandomAlphabetic(6);
548548
ThingUID thingUID = getThingUID(device);
549549
if (thingUID == null) {
550550
return null;
551551
}
552-
return DiscoveryResultBuilder.create(thingUID).withLabel(StringUtil.randomAlphabetic(6))
553-
.withProperty(repProp, StringUtil.randomAlphabetic(6)).withRepresentationProperty(repProp)
552+
return DiscoveryResultBuilder.create(thingUID).withLabel(StringUtils.getRandomAlphabetic(6))
553+
.withProperty(repProp, StringUtils.getRandomAlphabetic(6)).withRepresentationProperty(repProp)
554554
.withBridge(device.getAdapter().getUID()).build();
555555
}
556556

557557
@Override
558558
public @Nullable ThingUID getThingUID(BluetoothDiscoveryDevice device) {
559559
String deviceName = device.getName();
560-
String id = deviceName != null ? deviceName : StringUtil.randomAlphabetic(6);
560+
String id = deviceName != null ? deviceName : StringUtils.getRandomAlphabetic(6);
561561
return new ThingUID(typeUID, device.getAdapter().getUID(), id);
562562
}
563563
}

0 commit comments

Comments
 (0)