From 84e4c8f2312c107ca834e8ae8b988cfdfb637a91 Mon Sep 17 00:00:00 2001 From: Oleksandra Matviienko Date: Mon, 6 Mar 2023 13:49:01 +0100 Subject: [PATCH] junit5: BaseRuleChainServiceTest annotation exceptions refactoring --- .../dao/service/BaseRuleChainServiceTest.java | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/BaseRuleChainServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/BaseRuleChainServiceTest.java index 18c6e110d5..16901119a6 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/BaseRuleChainServiceTest.java +++ b/dao/src/test/java/org/thingsboard/server/dao/service/BaseRuleChainServiceTest.java @@ -21,6 +21,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.StringUtils; import org.thingsboard.server.common.data.Tenant; import org.thingsboard.server.common.data.edge.Edge; @@ -86,19 +87,23 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { ruleChainService.deleteRuleChainById(tenantId, savedRuleChain.getId()); } - @Test(expected = DataValidationException.class) + @Test public void testSaveRuleChainWithEmptyName() { RuleChain ruleChain = new RuleChain(); ruleChain.setTenantId(tenantId); - ruleChainService.saveRuleChain(ruleChain); + Assertions.assertThrows(DataValidationException.class, () -> { + ruleChainService.saveRuleChain(ruleChain); + }); } - @Test(expected = DataValidationException.class) + @Test public void testSaveRuleChainWithInvalidTenant() { RuleChain ruleChain = new RuleChain(); ruleChain.setName("My RuleChain"); ruleChain.setTenantId(TenantId.fromUUID(Uuids.timeBased())); - ruleChainService.saveRuleChain(ruleChain); + Assertions.assertThrows(DataValidationException.class, () -> { + ruleChainService.saveRuleChain(ruleChain); + }); } @Test @@ -321,14 +326,18 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { ruleChainService.deleteRuleChainById(tenantId, savedRuleChainMetaData.getRuleChainId()); } - @Test(expected = DataValidationException.class) - public void testUpdateRuleChainMetaDataWithCirclingRelation() throws Exception { - ruleChainService.saveRuleChainMetaData(tenantId, createRuleChainMetadataWithCirclingRelation()); + @Test + public void testUpdateRuleChainMetaDataWithCirclingRelation() { + Assertions.assertThrows(DataValidationException.class, () -> { + ruleChainService.saveRuleChainMetaData(tenantId, createRuleChainMetadataWithCirclingRelation()); + }); } - @Test(expected = DataValidationException.class) - public void testUpdateRuleChainMetaDataWithCirclingRelation2() throws Exception { - ruleChainService.saveRuleChainMetaData(tenantId, createRuleChainMetadataWithCirclingRelation2()); + @Test + public void testUpdateRuleChainMetaDataWithCirclingRelation2() { + Assertions.assertThrows(DataValidationException.class, () -> { + ruleChainService.saveRuleChainMetaData(tenantId, createRuleChainMetadataWithCirclingRelation2()); + }); } @Test