+++ /dev/null
-/**
- * Copyright (c) 2010-2023 Contributors to the openHAB project
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-package org.openhab.binding.bluetooth.util;
-
-import org.eclipse.jdt.annotation.NonNullByDefault;
-
-/**
- * This is a n string utility class
- *
- * @author Leo Siepel - Initial contribution
- *
- */
-@NonNullByDefault
-public class StringUtil {
-
- public static String randomString(int length, String charset) {
- StringBuilder sb = new StringBuilder(length);
- for (int i = 0; i < length; i++) {
- int index = (int) (charset.length() * Math.random());
- sb.append(charset.charAt(index));
- }
-
- return sb.toString();
- }
-
- public static String randomAlphabetic(int length) {
- return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvxyz");
- }
-
- public static String randomHex(int length) {
- return StringUtil.randomString(length, "0123456789ABCDEF");
- }
-
- public static String randomAlphanummeric(int length) {
- return StringUtil.randomString(length, "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvxyz");
- }
-}
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
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));
}
}
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}.
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);
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);
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);
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
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
@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);
}
}