From 3612434af6f1fa5bbedd37400861330db46f3e71 Mon Sep 17 00:00:00 2001 From: Atanas Atanasov Date: Tue, 17 Dec 2024 14:43:53 +0200 Subject: [PATCH] fix test error messages to check for Signed-off-by: Atanas Atanasov --- .../block/common/utils/PreconditionsTest.java | 53 +++++++++---------- 1 file changed, 24 insertions(+), 29 deletions(-) diff --git a/common/src/test/java/com/hedera/block/common/utils/PreconditionsTest.java b/common/src/test/java/com/hedera/block/common/utils/PreconditionsTest.java index e9f0846d5..de044a883 100644 --- a/common/src/test/java/com/hedera/block/common/utils/PreconditionsTest.java +++ b/common/src/test/java/com/hedera/block/common/utils/PreconditionsTest.java @@ -117,12 +117,11 @@ void testRequireWholeFail(final int toTest) { .isThrownBy(() -> Preconditions.requireWhole(toTest)) .withMessage(DEFAULT_REQUIRE_WHOLE_MESSAGE.formatted(toTest)); - final String testErrorMessage = DEFAULT_REQUIRE_WHOLE_MESSAGE - .concat(" custom test error message") - .formatted(toTest); + final String testMessage = DEFAULT_REQUIRE_WHOLE_MESSAGE.concat(" custom test error message"); + final String expectedTestMessage = testMessage.formatted(toTest); assertThatIllegalArgumentException() - .isThrownBy(() -> Preconditions.requireWhole(toTest, testErrorMessage)) - .withMessage(testErrorMessage); + .isThrownBy(() -> Preconditions.requireWhole(toTest, testMessage)) + .withMessage(expectedTestMessage); } /** @@ -159,11 +158,11 @@ void testRequireGreaterOrEqualFail(final long toTest, final long base) { .isThrownBy(() -> Preconditions.requireGreaterOrEqual(toTest, base)) .withMessage(DEFAULT_GT_OR_EQ_MESSAGE.formatted(toTest, base)); - final String testErrorMessage = - DEFAULT_GT_OR_EQ_MESSAGE.concat(" custom test error message").formatted(toTest, base); + final String testMessage = DEFAULT_GT_OR_EQ_MESSAGE.concat(" custom test error message"); + final String expectedTestMessage = testMessage.formatted(toTest, base); assertThatIllegalArgumentException() - .isThrownBy(() -> Preconditions.requireGreaterOrEqual(toTest, base, testErrorMessage)) - .withMessage(testErrorMessage); + .isThrownBy(() -> Preconditions.requireGreaterOrEqual(toTest, base, testMessage)) + .withMessage(expectedTestMessage); } /** @@ -201,12 +200,11 @@ void testRequirePositiveFail(final int toTest) { .isThrownBy(() -> Preconditions.requirePositive(toTest)) .withMessage(DEFAULT_REQUIRE_POSITIVE_MESSAGE.formatted(toTest)); - final String testErrorMessage = DEFAULT_REQUIRE_POSITIVE_MESSAGE - .concat(" custom test error message") - .formatted(toTest); + final String testMessage = DEFAULT_REQUIRE_POSITIVE_MESSAGE.concat(" custom test error message"); + final String expectedTestMessage = testMessage.formatted(toTest); assertThatIllegalArgumentException() - .isThrownBy(() -> Preconditions.requirePositive(toTest, testErrorMessage)) - .withMessage(testErrorMessage); + .isThrownBy(() -> Preconditions.requirePositive(toTest, testMessage)) + .withMessage(expectedTestMessage); } /** @@ -243,12 +241,11 @@ void testRequirePositiveLongFail(final long toTest) { .isThrownBy(() -> Preconditions.requirePositive(toTest)) .withMessage(DEFAULT_REQUIRE_POSITIVE_MESSAGE.formatted(toTest)); - final String testErrorMessage = DEFAULT_REQUIRE_POSITIVE_MESSAGE - .concat(" custom test error message") - .formatted(toTest); + final String testMessage = DEFAULT_REQUIRE_POSITIVE_MESSAGE.concat(" custom test error message"); + final String expectedTestMessage = testMessage.formatted(toTest); assertThatIllegalArgumentException() - .isThrownBy(() -> Preconditions.requirePositive(toTest, testErrorMessage)) - .withMessage(testErrorMessage); + .isThrownBy(() -> Preconditions.requirePositive(toTest, testMessage)) + .withMessage(expectedTestMessage); } /** @@ -290,12 +287,11 @@ void testRequirePowerOfTwoFail(final int toTest) { .isThrownBy(() -> Preconditions.requirePowerOfTwo(toTest)) .withMessage(DEFAULT_REQUIRE_POWER_OF_TWO_MESSAGE.formatted(toTest)); - final String testErrorMessage = DEFAULT_REQUIRE_POWER_OF_TWO_MESSAGE - .concat(" custom test error message") - .formatted(toTest); + final String testMessage = DEFAULT_REQUIRE_POWER_OF_TWO_MESSAGE.concat(" custom test error message"); + final String expectedTestMessage = testMessage.formatted(toTest); assertThatIllegalArgumentException() - .isThrownBy(() -> Preconditions.requirePowerOfTwo(toTest, testErrorMessage)) - .withMessage(testErrorMessage); + .isThrownBy(() -> Preconditions.requirePowerOfTwo(toTest, testMessage)) + .withMessage(expectedTestMessage); } /** @@ -339,12 +335,11 @@ void testRequireInRangeFail(final int toTest, final int lowerBoundary, final int .isThrownBy(() -> Preconditions.requireInRange(toTest, lowerBoundary, upperBoundary)) .withMessage(DEFAULT_REQUIRE_IN_RANGE_MESSAGE.formatted(toTest, lowerBoundary, upperBoundary)); - final String testErrorMessage = DEFAULT_REQUIRE_IN_RANGE_MESSAGE - .concat(" custom test error message") - .formatted(toTest, lowerBoundary, upperBoundary); + final String testMessage = DEFAULT_REQUIRE_IN_RANGE_MESSAGE.concat(" custom test error message"); + final String expectedTestMessage = testMessage.formatted(toTest, lowerBoundary, upperBoundary); assertThatIllegalArgumentException() - .isThrownBy(() -> Preconditions.requireInRange(toTest, lowerBoundary, upperBoundary, testErrorMessage)) - .withMessage(testErrorMessage); + .isThrownBy(() -> Preconditions.requireInRange(toTest, lowerBoundary, upperBoundary, testMessage)) + .withMessage(expectedTestMessage); } private static Stream validRequireInRangeValues() {