Skip to content

Commit eb995d9

Browse files
committed
test: Add validation tests for setRetryableStatusCodes to ensure proper exception handling for invalid HTTP status codes
1 parent f2839e5 commit eb995d9

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

src/test/java/com/contentstack/sdk/RetryOptionsTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,45 @@ void testFluentMethodChaining() {
262262
// toString() Tests
263263
// ===========================
264264

265+
@Test
266+
@DisplayName("Test setRetryableStatusCodes with code below 100 throws exception")
267+
void testSetRetryableStatusCodesWithCodeBelow100() {
268+
IllegalArgumentException exception = assertThrows(
269+
IllegalArgumentException.class,
270+
() -> retryOptions.setRetryableStatusCodes(99),
271+
"Should throw exception for status code < 100"
272+
);
273+
assertTrue(exception.getMessage().contains("Invalid HTTP status code: 99"),
274+
"Exception message should mention invalid code 99");
275+
assertTrue(exception.getMessage().contains("Must be between 100 and 599"),
276+
"Exception message should mention valid range");
277+
}
278+
279+
@Test
280+
@DisplayName("Test setRetryableStatusCodes with code above 599 throws exception")
281+
void testSetRetryableStatusCodesWithCodeAbove599() {
282+
IllegalArgumentException exception = assertThrows(
283+
IllegalArgumentException.class,
284+
() -> retryOptions.setRetryableStatusCodes(600),
285+
"Should throw exception for status code > 599"
286+
);
287+
assertTrue(exception.getMessage().contains("Invalid HTTP status code: 600"),
288+
"Exception message should mention invalid code 600");
289+
assertTrue(exception.getMessage().contains("Must be between 100 and 599"),
290+
"Exception message should mention valid range");
291+
}
292+
293+
@Test
294+
@DisplayName("Test setRetryableStatusCodes with mixed valid and invalid codes")
295+
void testSetRetryableStatusCodesWithMixedCodes() {
296+
// Should throw on first invalid code encountered
297+
assertThrows(
298+
IllegalArgumentException.class,
299+
() -> retryOptions.setRetryableStatusCodes(200, 50, 503),
300+
"Should throw exception when encountering invalid code in array"
301+
);
302+
}
303+
265304
@Test
266305
@DisplayName("Test toString contains all configuration")
267306
void testToStringContainsConfiguration() {

0 commit comments

Comments
 (0)