Skip to content

Commit 1ddefb6

Browse files
authored
Issue #22506 - Delete throwIf method in AbstractFluentExceptionSupport (PR #12)
* Remove throwIf * Bump up version
1 parent dc648a2 commit 1ddefb6

File tree

5 files changed

+9
-38
lines changed

5 files changed

+9
-38
lines changed

src/main/java/com/ziro/espresso/fluent/exceptions/AbstractFluentExceptionSupport.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -140,20 +140,6 @@ public ExceptionDetailsStage<T> message(Supplier<String> messageSupplier) {
140140
return this;
141141
}
142142

143-
/**
144-
* Throws the configured exception if the specified condition is true.
145-
* This is a convenience method for conditional exception throwing.
146-
*
147-
* @param condition the condition to evaluate
148-
* @throws T the configured exception if the condition is true
149-
*/
150-
@Override
151-
public void throwIf(boolean condition) throws T {
152-
if (condition) {
153-
throw exception();
154-
}
155-
}
156-
157143
/**
158144
* Creates and returns the exception instance with all configured properties.
159145
* If no message was set, use the default message.

src/main/java/com/ziro/espresso/fluent/exceptions/ExceptionDetailsStage.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,4 @@ public interface ExceptionDetailsStage<T extends Throwable> {
1616
ExceptionDetailsStage<T> message(Supplier<String> messageSupplier);
1717

1818
T exception();
19-
20-
void throwIf(boolean condition) throws T;
2119
}

src/main/java/com/ziro/espresso/okhttp3/JwtTokenFactory.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,14 @@ public static String createAccessToken(String scope, String clientId, String cli
8484
ResponseBody responseBody = Objects.requireNonNull(response.body(), "responseBody should not be null");
8585
String responseAsString = new String(responseBody.bytes());
8686

87-
SystemUnhandledException.asRootCause()
88-
.message(
89-
"Failed to obtain access token from Authorization Server. "
90-
+ "The Authorization Server returned [status_code=%s, response=%s].",
91-
response.code(), responseAsString)
92-
.throwIf(response.code() != SUCCESS_STATUS_CODE);
87+
if (response.code() != SUCCESS_STATUS_CODE) {
88+
throw SystemUnhandledException.asRootCause()
89+
.message(
90+
"Failed to obtain access token from Authorization Server. "
91+
+ "The Authorization Server returned [status_code=%s, response=%s].",
92+
response.code(), responseAsString)
93+
.exception();
94+
}
9395

9496
JsonNode jwtJsonObject = OBJECT_MAPPER.readTree(responseAsString);
9597
return jwtJsonObject.get("access_token").asText();

src/test/java/com/ziro/espresso/fluent/exceptions/SystemUnhandledExceptionTest.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.ziro.espresso.fluent.exceptions;
22

33
import static org.assertj.core.api.Assertions.assertThat;
4-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
54

65
import org.junit.jupiter.api.Test;
76

@@ -29,20 +28,6 @@ void whenUsingAsRootCauseThenExceptionHasNoCause() {
2928
assertThat(exception.getCause()).isNull();
3029
}
3130

32-
@Test
33-
void whenUsingWithCauseAndThrowIfThenThrowsExceptionWhenConditionTrue() {
34-
RuntimeException originalCause = new RuntimeException("Original error");
35-
36-
assertThatThrownBy(() -> {
37-
SystemUnhandledException.withCause(originalCause)
38-
.message("Something went wrong")
39-
.throwIf(true);
40-
})
41-
.isInstanceOf(SystemUnhandledException.class)
42-
.hasMessage("Something went wrong")
43-
.hasCause(originalCause);
44-
}
45-
4631
@Test
4732
void whenUsingMessageWithFormatting_thenFormatsCorrectly() {
4833
SystemUnhandledException exception = SystemUnhandledException.asRootCause()

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5.1.0
1+
6.0.0

0 commit comments

Comments
 (0)