Skip to content

Commit

Permalink
fix test error messages to check for
Browse files Browse the repository at this point in the history
Signed-off-by: Atanas Atanasov <[email protected]>
  • Loading branch information
ata-nas committed Dec 17, 2024
1 parent 809c5fb commit 3612434
Showing 1 changed file with 24 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -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<Arguments> validRequireInRangeValues() {
Expand Down

0 comments on commit 3612434

Please sign in to comment.