diff --git a/src/main/java/com/ziro/espresso/fluent/exceptions/AbstractFluentExceptionSupport.java b/src/main/java/com/ziro/espresso/fluent/exceptions/AbstractFluentExceptionSupport.java index fa2d2fc..9dd7c47 100644 --- a/src/main/java/com/ziro/espresso/fluent/exceptions/AbstractFluentExceptionSupport.java +++ b/src/main/java/com/ziro/espresso/fluent/exceptions/AbstractFluentExceptionSupport.java @@ -140,20 +140,6 @@ public ExceptionDetailsStage message(Supplier messageSupplier) { return this; } - /** - * Throws the configured exception if the specified condition is true. - * This is a convenience method for conditional exception throwing. - * - * @param condition the condition to evaluate - * @throws T the configured exception if the condition is true - */ - @Override - public void throwIf(boolean condition) throws T { - if (condition) { - throw exception(); - } - } - /** * Creates and returns the exception instance with all configured properties. * If no message was set, use the default message. diff --git a/src/main/java/com/ziro/espresso/fluent/exceptions/ExceptionDetailsStage.java b/src/main/java/com/ziro/espresso/fluent/exceptions/ExceptionDetailsStage.java index ae15ef8..5b86dc3 100644 --- a/src/main/java/com/ziro/espresso/fluent/exceptions/ExceptionDetailsStage.java +++ b/src/main/java/com/ziro/espresso/fluent/exceptions/ExceptionDetailsStage.java @@ -16,6 +16,4 @@ public interface ExceptionDetailsStage { ExceptionDetailsStage message(Supplier messageSupplier); T exception(); - - void throwIf(boolean condition) throws T; } diff --git a/src/main/java/com/ziro/espresso/okhttp3/JwtTokenFactory.java b/src/main/java/com/ziro/espresso/okhttp3/JwtTokenFactory.java index c7fe284..1706c64 100644 --- a/src/main/java/com/ziro/espresso/okhttp3/JwtTokenFactory.java +++ b/src/main/java/com/ziro/espresso/okhttp3/JwtTokenFactory.java @@ -84,12 +84,14 @@ public static String createAccessToken(String scope, String clientId, String cli ResponseBody responseBody = Objects.requireNonNull(response.body(), "responseBody should not be null"); String responseAsString = new String(responseBody.bytes()); - SystemUnhandledException.asRootCause() - .message( - "Failed to obtain access token from Authorization Server. " - + "The Authorization Server returned [status_code=%s, response=%s].", - response.code(), responseAsString) - .throwIf(response.code() != SUCCESS_STATUS_CODE); + if (response.code() != SUCCESS_STATUS_CODE) { + throw SystemUnhandledException.asRootCause() + .message( + "Failed to obtain access token from Authorization Server. " + + "The Authorization Server returned [status_code=%s, response=%s].", + response.code(), responseAsString) + .exception(); + } JsonNode jwtJsonObject = OBJECT_MAPPER.readTree(responseAsString); return jwtJsonObject.get("access_token").asText(); diff --git a/src/test/java/com/ziro/espresso/fluent/exceptions/SystemUnhandledExceptionTest.java b/src/test/java/com/ziro/espresso/fluent/exceptions/SystemUnhandledExceptionTest.java index 9fc9bd9..ec1f8c9 100644 --- a/src/test/java/com/ziro/espresso/fluent/exceptions/SystemUnhandledExceptionTest.java +++ b/src/test/java/com/ziro/espresso/fluent/exceptions/SystemUnhandledExceptionTest.java @@ -1,7 +1,6 @@ package com.ziro.espresso.fluent.exceptions; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; import org.junit.jupiter.api.Test; @@ -29,20 +28,6 @@ void whenUsingAsRootCauseThenExceptionHasNoCause() { assertThat(exception.getCause()).isNull(); } - @Test - void whenUsingWithCauseAndThrowIfThenThrowsExceptionWhenConditionTrue() { - RuntimeException originalCause = new RuntimeException("Original error"); - - assertThatThrownBy(() -> { - SystemUnhandledException.withCause(originalCause) - .message("Something went wrong") - .throwIf(true); - }) - .isInstanceOf(SystemUnhandledException.class) - .hasMessage("Something went wrong") - .hasCause(originalCause); - } - @Test void whenUsingMessageWithFormatting_thenFormatsCorrectly() { SystemUnhandledException exception = SystemUnhandledException.asRootCause() diff --git a/version.txt b/version.txt index 831446c..09b254e 100644 --- a/version.txt +++ b/version.txt @@ -1 +1 @@ -5.1.0 +6.0.0