Commit 2d7ae47f22db673d8671c4bd2a39262cfd24c8fa

Authored by AndrewVolosytnykhThingsboard
1 parent b158528c

Removed redundant function for generating random string

@@ -16,6 +16,7 @@ @@ -16,6 +16,7 @@
16 package org.thingsboard.server.dao.service; 16 package org.thingsboard.server.dao.service;
17 17
18 import com.datastax.oss.driver.api.core.uuid.Uuids; 18 import com.datastax.oss.driver.api.core.uuid.Uuids;
  19 +import org.apache.commons.lang3.RandomStringUtils;
19 import org.junit.After; 20 import org.junit.After;
20 import org.junit.Assert; 21 import org.junit.Assert;
21 import org.junit.Before; 22 import org.junit.Before;
@@ -41,7 +42,6 @@ import java.nio.ByteBuffer; @@ -41,7 +42,6 @@ import java.nio.ByteBuffer;
41 import java.util.ArrayList; 42 import java.util.ArrayList;
42 import java.util.Collections; 43 import java.util.Collections;
43 import java.util.List; 44 import java.util.List;
44 -import java.util.Random;  
45 45
46 import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; 46 import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
47 47
@@ -667,7 +667,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { @@ -667,7 +667,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
667 OtaPackageInfo firmwareInfo = new OtaPackageInfo(); 667 OtaPackageInfo firmwareInfo = new OtaPackageInfo();
668 firmwareInfo.setDeviceProfileId(deviceProfileId); 668 firmwareInfo.setDeviceProfileId(deviceProfileId);
669 firmwareInfo.setType(FIRMWARE); 669 firmwareInfo.setType(FIRMWARE);
670 - firmwareInfo.setTitle(randomStringByLength(257)); 670 + firmwareInfo.setTitle(RandomStringUtils.random(257));
671 firmwareInfo.setVersion(VERSION); 671 firmwareInfo.setVersion(VERSION);
672 firmwareInfo.setUrl(URL); 672 firmwareInfo.setUrl(URL);
673 firmwareInfo.setTenantId(tenantId); 673 firmwareInfo.setTenantId(tenantId);
@@ -687,7 +687,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { @@ -687,7 +687,7 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
687 firmwareInfo.setTenantId(tenantId); 687 firmwareInfo.setTenantId(tenantId);
688 firmwareInfo.setTitle(TITLE); 688 firmwareInfo.setTitle(TITLE);
689 689
690 - firmwareInfo.setVersion(randomStringByLength(257)); 690 + firmwareInfo.setVersion(RandomStringUtils.random(257));
691 thrown.expectMessage("The length of version should be equal or shorter than 255"); 691 thrown.expectMessage("The length of version should be equal or shorter than 255");
692 692
693 otaPackageService.saveOtaPackageInfo(firmwareInfo, true); 693 otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
@@ -708,18 +708,4 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { @@ -708,18 +708,4 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
708 firmware.setDataSize(DATA_SIZE); 708 firmware.setDataSize(DATA_SIZE);
709 return otaPackageService.saveOtaPackage(firmware); 709 return otaPackageService.saveOtaPackage(firmware);
710 } 710 }
711 -  
712 - private String randomStringByLength(int length) {  
713 - int leftLimit = 97;  
714 - int rightLimit = 122;  
715 - Random random = new Random();  
716 - StringBuilder buffer = new StringBuilder(length);  
717 - for (int i = 0; i < length; i++) {  
718 - int randomLimitedInt = leftLimit + (int)  
719 - (random.nextFloat() * (rightLimit - leftLimit + 1));  
720 - buffer.append((char) randomLimitedInt);  
721 - }  
722 - return buffer.toString();  
723 - }  
724 -  
725 } 711 }