From c2b53479fbebf744c3b191e60835cd9522043e94 Mon Sep 17 00:00:00 2001 From: Oleksandra Matviienko Date: Fri, 15 Mar 2024 12:08:45 +0100 Subject: [PATCH] UPD. Refactoring and changes according to comments. Signed-off-by: Oleksandra Matviienko --- .../server/dao/service/Validator.java | 17 +---------------- .../server/dao/service/ValidatorTest.java | 17 ++--------------- 2 files changed, 3 insertions(+), 31 deletions(-) diff --git a/dao/src/main/java/org/thingsboard/server/dao/service/Validator.java b/dao/src/main/java/org/thingsboard/server/dao/service/Validator.java index be56414a33..ff11c3de81 100644 --- a/dao/src/main/java/org/thingsboard/server/dao/service/Validator.java +++ b/dao/src/main/java/org/thingsboard/server/dao/service/Validator.java @@ -193,9 +193,8 @@ public class Validator { if (ids == null || ids.isEmpty()) { throw new IncorrectParameterException(errorMessageFunction.apply(ids)); } else { - Supplier errorMessageSupplier = () -> errorMessageFunction.apply(ids); for (UUIDBased id : ids) { - validateId(id, errorMessageSupplier); + validateId(id, errorMessageFunction.apply(ids)); } } } @@ -245,18 +244,4 @@ public class Validator { throw new IncorrectParameterException(errorMessage); } } - - /** - * This method validate list of UUIDBased ids. If at least one of the ids is null than throw - * IncorrectParameterException exception - * - * @param reference the list of ids - * @param errorMessageFunction the error message for exception that applies reference - */ - public static void checkNotNull(Object reference, Function errorMessageFunction) { - if (reference == null) { - throw new IncorrectParameterException(errorMessageFunction.apply(reference)); - } - } - } diff --git a/dao/src/test/java/org/thingsboard/server/dao/service/ValidatorTest.java b/dao/src/test/java/org/thingsboard/server/dao/service/ValidatorTest.java index 0372d6ba80..7a6fa231b2 100644 --- a/dao/src/test/java/org/thingsboard/server/dao/service/ValidatorTest.java +++ b/dao/src/test/java/org/thingsboard/server/dao/service/ValidatorTest.java @@ -105,11 +105,9 @@ class ValidatorTest { } @Test - void validateIds() { - + void validateIdsTest() { List list = List.of(goodDeviceId); Validator.validateIds( list, ids -> "Incorrect Id " + ids); - Validator.validateId(list.get(0), id -> "Incorrect Id " + id); assertThatThrownBy(() -> Validator.validateIds(null, id -> "Incorrect Ids " + id)) .as("Ids are null") @@ -134,6 +132,7 @@ class ValidatorTest { .hasMessageContaining("null"); } + @Test void validateIdSupplier() { Validator.validateId(TenantId.SYS_TENANT_ID, () -> "Incorrect Id null"); @@ -149,16 +148,4 @@ class ValidatorTest { .isInstanceOf(IncorrectParameterException.class) .hasMessageContaining("Incorrect Id null"); } - - @Test - void checkNotNullTest() { - Validator.checkNotNull("notnull", reference -> "Incorrect reference " + reference); - - assertThatThrownBy(() -> Validator.checkNotNull(null, reference -> "Incorrect reference " + reference)) - .as("Reference is null") - .isInstanceOf(IncorrectParameterException.class) - .hasMessageContaining("Incorrect reference null"); - - } - }