From 7e2dabdfc437e7e892b8954aa73b4f48166a6dae Mon Sep 17 00:00:00 2001 From: Oleksandra Matviienko Date: Mon, 6 Mar 2023 14:58:56 +0100 Subject: [PATCH] junit5: BaseCustomerServiceTest annotation exceptions refactoring --- .../dao/service/BaseCustomerServiceTest.java | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/BaseCustomerServiceTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/BaseCustomerServiceTest.java index 11d82ad963..18bf036495 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/BaseCustomerServiceTest.java +++ b/dao/src/test/java/org/thingsboard/server/dao/service/BaseCustomerServiceTest.java @@ -24,6 +24,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.common.util.ThingsBoardExecutors; import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.StringUtils; @@ -99,35 +100,43 @@ public abstract class BaseCustomerServiceTest extends AbstractServiceTest { customerService.deleteCustomer(tenantId, savedCustomer.getId()); } - @Test(expected = DataValidationException.class) + @Test public void testSaveCustomerWithEmptyTitle() { Customer customer = new Customer(); customer.setTenantId(tenantId); - customerService.saveCustomer(customer); + Assertions.assertThrows(DataValidationException.class, () -> { + customerService.saveCustomer(customer); + }); } - @Test(expected = DataValidationException.class) + @Test public void testSaveCustomerWithEmptyTenant() { Customer customer = new Customer(); customer.setTitle("My customer"); - customerService.saveCustomer(customer); + Assertions.assertThrows(DataValidationException.class, () -> { + customerService.saveCustomer(customer); + }); } - @Test(expected = DataValidationException.class) + @Test public void testSaveCustomerWithInvalidTenant() { Customer customer = new Customer(); customer.setTitle("My customer"); customer.setTenantId(TenantId.fromUUID(Uuids.timeBased())); - customerService.saveCustomer(customer); + Assertions.assertThrows(DataValidationException.class, () -> { + customerService.saveCustomer(customer); + }); } - @Test(expected = DataValidationException.class) + @Test public void testSaveCustomerWithInvalidEmail() { Customer customer = new Customer(); customer.setTenantId(tenantId); customer.setTitle("My customer"); customer.setEmail("invalid@mail"); - customerService.saveCustomer(customer); + Assertions.assertThrows(DataValidationException.class, () -> { + customerService.saveCustomer(customer); + }); } @Test