]> git.basschouten.com Git - openhab-addons.git/commitdiff
adapt to core StringUtils (#15781)
authorlsiepel <leosiepel@gmail.com>
Sat, 21 Oct 2023 10:03:26 +0000 (12:03 +0200)
committerGitHub <noreply@github.com>
Sat, 21 Oct 2023 10:03:26 +0000 (12:03 +0200)
Signed-off-by: Leo Siepel <leosiepel@gmail.com>
bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/util/StringUtil.java [deleted file]
bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/TestUtils.java
bundles/org.openhab.binding.bluetooth/src/test/java/org/openhab/binding/bluetooth/discovery/internal/BluetoothDiscoveryServiceTest.java

diff --git a/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/util/StringUtil.java b/bundles/org.openhab.binding.bluetooth/src/main/java/org/openhab/binding/bluetooth/util/StringUtil.java
deleted file mode 100644 (file)
index 6365665..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-/**
- * 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");
-    }
-}
index 0303ba6818fb8dd56f45d15926ccd19b08ee2247..3b3bc11b138a1b2ad11868acf6977105d9f42f97 100644 (file)
@@ -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
@@ -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));
     }
 }
index aae70b1e8595cc1e32ba87160ab56db9b5b05d39..2c94607f06f44c8ab63a157498c439a3b214808a 100644 (file)
@@ -47,12 +47,12 @@ import org.openhab.binding.bluetooth.TestUtils;
 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}.
@@ -196,7 +196,7 @@ public class BluetoothDiscoveryServiceTest {
 
         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);
@@ -223,7 +223,7 @@ public class BluetoothDiscoveryServiceTest {
         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);
 
@@ -261,7 +261,7 @@ public class BluetoothDiscoveryServiceTest {
     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);
@@ -418,7 +418,7 @@ public class BluetoothDiscoveryServiceTest {
         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
@@ -534,7 +534,7 @@ public class BluetoothDiscoveryServiceTest {
         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
@@ -544,20 +544,20 @@ public class BluetoothDiscoveryServiceTest {
 
         @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);
         }
     }