Skip to content

Support @Nullable reasons in ConditionEvaluationResult APIs #4699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ repository on GitHub.
==== Deprecations and Breaking Changes

* Discontinue `junit-platform-suite-commons` which is now integrated into
`junit-platform-suite`
`junit-platform-suite`.

[[release-notes-6.0.0-M2-junit-platform-new-features-and-improvements]]
==== New Features and Improvements
Expand All @@ -47,7 +47,8 @@ repository on GitHub.
[[release-notes-6.0.0-M2-junit-jupiter-new-features-and-improvements]]
==== New Features and Improvements

* ❓
* Reason strings supplied to `ConditionEvaluationResult` APIs are now officially declared
as `@Nullable`.


[[release-notes-6.0.0-M2-junit-vintage]]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Optional;

import org.apiguardian.api.API;
import org.jspecify.annotations.Nullable;
import org.junit.platform.commons.util.StringUtils;
import org.junit.platform.commons.util.ToStringBuilder;

Expand All @@ -35,7 +36,7 @@ public class ConditionEvaluationResult {
* or an <em>empty</em> reason if the reason is unknown
* @see StringUtils#isBlank(String)
*/
public static ConditionEvaluationResult enabled(String reason) {
public static ConditionEvaluationResult enabled(@Nullable String reason) {
return new ConditionEvaluationResult(true, reason);
}

Expand All @@ -48,7 +49,7 @@ public static ConditionEvaluationResult enabled(String reason) {
* or an <em>empty</em> reason if the reason is unknown
* @see StringUtils#isBlank(String)
*/
public static ConditionEvaluationResult disabled(String reason) {
public static ConditionEvaluationResult disabled(@Nullable String reason) {
return new ConditionEvaluationResult(false, reason);
}

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

@SuppressWarnings("NullAway") // StringUtils.isNotBlank() does not yet have a nullability @Contract
private ConditionEvaluationResult(boolean enabled, String reason) {
private ConditionEvaluationResult(boolean enabled, @Nullable String reason) {
this.enabled = enabled;
this.reason = StringUtils.isNotBlank(reason) ? Optional.of(reason.strip()) : Optional.empty();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ void enabledWithReason() {

@BlankReasonsTest
void enabledWithBlankReason(@Nullable String reason) {
@SuppressWarnings("NullAway")
var result = ConditionEvaluationResult.enabled(reason);

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

@BlankReasonsTest
void disabledWithBlankDefaultReason(@Nullable String reason) {
@SuppressWarnings("NullAway")
var result = ConditionEvaluationResult.disabled(reason);

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

@BlankReasonsTest
void disabledWithDefaultReasonAndBlankCustomReason(@Nullable String customReason) {
@SuppressWarnings("NullAway")
var result = ConditionEvaluationResult.disabled("default", customReason);

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

@BlankReasonsTest
void disabledWithBlankDefaultReasonAndCustomReason(@Nullable String reason) {
@SuppressWarnings("NullAway")
var result = ConditionEvaluationResult.disabled(reason, "custom");

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

assertThat(result.isDisabled()).isTrue();
Expand Down