Skip to content

Commit dc4b365

Browse files
committed
Support @⁠Nullable reasons in ConditionEvaluationResult APIs
Closes #4698 Closes #4699
1 parent aff6755 commit dc4b365

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

junit-jupiter-api/src/main/java/org/junit/jupiter/api/extension/ConditionEvaluationResult.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Optional;
1616

1717
import org.apiguardian.api.API;
18+
import org.jspecify.annotations.Nullable;
1819
import org.junit.platform.commons.util.StringUtils;
1920
import org.junit.platform.commons.util.ToStringBuilder;
2021

@@ -35,7 +36,7 @@ public class ConditionEvaluationResult {
3536
* or an <em>empty</em> reason if the reason is unknown
3637
* @see StringUtils#isBlank(String)
3738
*/
38-
public static ConditionEvaluationResult enabled(String reason) {
39+
public static ConditionEvaluationResult enabled(@Nullable String reason) {
3940
return new ConditionEvaluationResult(true, reason);
4041
}
4142

@@ -48,7 +49,7 @@ public static ConditionEvaluationResult enabled(String reason) {
4849
* or an <em>empty</em> reason if the reason is unknown
4950
* @see StringUtils#isBlank(String)
5051
*/
51-
public static ConditionEvaluationResult disabled(String reason) {
52+
public static ConditionEvaluationResult disabled(@Nullable String reason) {
5253
return new ConditionEvaluationResult(false, reason);
5354
}
5455

@@ -69,7 +70,8 @@ public static ConditionEvaluationResult disabled(String reason) {
6970
* @see StringUtils#isBlank(String)
7071
*/
7172
@API(status = STABLE, since = "5.7")
72-
public static ConditionEvaluationResult disabled(String reason, String customReason) {
73+
@SuppressWarnings("NullAway") // StringUtils.isBlank() does not yet have a nullability @Contract
74+
public static ConditionEvaluationResult disabled(@Nullable String reason, @Nullable String customReason) {
7375
if (StringUtils.isBlank(reason)) {
7476
return disabled(customReason);
7577
}
@@ -84,7 +86,7 @@ public static ConditionEvaluationResult disabled(String reason, String customRea
8486
private final Optional<String> reason;
8587

8688
@SuppressWarnings("NullAway") // StringUtils.isNotBlank() does not yet have a nullability @Contract
87-
private ConditionEvaluationResult(boolean enabled, String reason) {
89+
private ConditionEvaluationResult(boolean enabled, @Nullable String reason) {
8890
this.enabled = enabled;
8991
this.reason = StringUtils.isNotBlank(reason) ? Optional.of(reason.strip()) : Optional.empty();
9092
}

jupiter-tests/src/test/java/org/junit/jupiter/api/condition/ConditionEvaluationResultTests.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ void enabledWithReason() {
4141

4242
@BlankReasonsTest
4343
void enabledWithBlankReason(@Nullable String reason) {
44-
@SuppressWarnings("NullAway")
4544
var result = ConditionEvaluationResult.enabled(reason);
4645

4746
assertThat(result.isDisabled()).isFalse();
@@ -62,7 +61,6 @@ void disabledWithDefaultReason() {
6261

6362
@BlankReasonsTest
6463
void disabledWithBlankDefaultReason(@Nullable String reason) {
65-
@SuppressWarnings("NullAway")
6664
var result = ConditionEvaluationResult.disabled(reason);
6765

6866
assertThat(result.isDisabled()).isTrue();
@@ -73,7 +71,6 @@ void disabledWithBlankDefaultReason(@Nullable String reason) {
7371

7472
@BlankReasonsTest
7573
void disabledWithDefaultReasonAndBlankCustomReason(@Nullable String customReason) {
76-
@SuppressWarnings("NullAway")
7774
var result = ConditionEvaluationResult.disabled("default", customReason);
7875

7976
assertThat(result.isDisabled()).isTrue();
@@ -84,7 +81,6 @@ void disabledWithDefaultReasonAndBlankCustomReason(@Nullable String customReason
8481

8582
@BlankReasonsTest
8683
void disabledWithBlankDefaultReasonAndCustomReason(@Nullable String reason) {
87-
@SuppressWarnings("NullAway")
8884
var result = ConditionEvaluationResult.disabled(reason, "custom");
8985

9086
assertThat(result.isDisabled()).isTrue();
@@ -95,7 +91,6 @@ void disabledWithBlankDefaultReasonAndCustomReason(@Nullable String reason) {
9591
@BlankReasonsTest
9692
void disabledWithBlankDefaultReasonAndBlankCustomReason(@Nullable String reason) {
9793
// We intentionally use the reason as both the default and custom reason.
98-
@SuppressWarnings("NullAway")
9994
var result = ConditionEvaluationResult.disabled(reason, reason);
10095

10196
assertThat(result.isDisabled()).isTrue();

0 commit comments

Comments
 (0)