diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetServiceTest.java index 9fe9752a85..108fcb70d9 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetServiceTest.java +++ b/dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetServiceTest.java @@ -20,6 +20,7 @@ import org.junit.After; import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.Assertions; import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.StringUtils; @@ -83,63 +84,73 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest { assetService.deleteAsset(tenantId, savedAsset.getId()); } - @Test(expected = DataValidationException.class) + @Test public void testSaveAssetWithEmptyName() { Asset asset = new Asset(); asset.setTenantId(tenantId); asset.setType("default"); - assetService.saveAsset(asset); + Assertions.assertThrows(DataValidationException.class, () -> { + assetService.saveAsset(asset); + }); } - @Test(expected = DataValidationException.class) + @Test public void testSaveAssetWithEmptyTenant() { Asset asset = new Asset(); asset.setName("My asset"); asset.setType("default"); - assetService.saveAsset(asset); + Assertions.assertThrows(DataValidationException.class, () -> { + assetService.saveAsset(asset); + }); } - @Test(expected = DataValidationException.class) + @Test public void testSaveAssetWithInvalidTenant() { Asset asset = new Asset(); asset.setName("My asset"); asset.setType("default"); asset.setTenantId(TenantId.fromUUID(Uuids.timeBased())); - assetService.saveAsset(asset); + Assertions.assertThrows(DataValidationException.class, () -> { + assetService.saveAsset(asset); + }); } - @Test(expected = DataValidationException.class) + @Test public void testAssignAssetToNonExistentCustomer() { Asset asset = new Asset(); asset.setName("My asset"); asset.setType("default"); asset.setTenantId(tenantId); - asset = assetService.saveAsset(asset); + Asset savedAsset = assetService.saveAsset(asset); try { - assetService.assignAssetToCustomer(tenantId, asset.getId(), new CustomerId(Uuids.timeBased())); + Assertions.assertThrows(DataValidationException.class, () -> { + assetService.assignAssetToCustomer(tenantId, savedAsset.getId(), new CustomerId(Uuids.timeBased())); + }); } finally { - assetService.deleteAsset(tenantId, asset.getId()); + assetService.deleteAsset(tenantId, savedAsset.getId()); } } - @Test(expected = DataValidationException.class) + @Test public void testAssignAssetToCustomerFromDifferentTenant() { Asset asset = new Asset(); asset.setName("My asset"); asset.setType("default"); asset.setTenantId(tenantId); - asset = assetService.saveAsset(asset); + Asset savedAsset = assetService.saveAsset(asset); Tenant tenant = new Tenant(); tenant.setTitle("Test different tenant"); tenant = tenantService.saveTenant(tenant); Customer customer = new Customer(); customer.setTenantId(tenant.getId()); customer.setTitle("Test different customer"); - customer = customerService.saveCustomer(customer); + Customer savedCustomer = customerService.saveCustomer(customer); try { - assetService.assignAssetToCustomer(tenantId, asset.getId(), customer.getId()); + Assertions.assertThrows(DataValidationException.class, () -> { + assetService.assignAssetToCustomer(tenantId, savedAsset.getId(), savedCustomer.getId()); + }); } finally { - assetService.deleteAsset(tenantId, asset.getId()); + assetService.deleteAsset(tenantId, savedAsset.getId()); tenantService.deleteTenant(tenant.getId()); } }