| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
package org.junit.jupiter.api.extension; |
| 12 |
|
| 13 |
import static org.apiguardian.api.API.Status.STABLE; |
| 14 |
|
| 15 |
import java.util.Optional; |
| 16 |
|
| 17 |
import org.apiguardian.api.API; |
| 18 |
import org.junit.platform.commons.util.StringUtils; |
| 19 |
import org.junit.platform.commons.util.ToStringBuilder; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
@API(status = STABLE, since = "5.0") |
| 27 |
public class ConditionEvaluationResult { |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public static ConditionEvaluationResult enabled(String reason) { |
| 36 |
return new ConditionEvaluationResult(true, reason); |
| 37 |
} |
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
public static ConditionEvaluationResult disabled(String reason) { |
| 46 |
return new ConditionEvaluationResult(false, reason); |
| 47 |
} |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
@API(status = STABLE, since = "5.7") |
| 59 |
public static ConditionEvaluationResult disabled(String reason, String customReason) { |
| 60 |
if (StringUtils.isBlank(customReason)) { |
| 61 |
return disabled(reason); |
| 62 |
} |
| 63 |
return disabled(String.format("%s ==> %s", reason, customReason)); |
| 64 |
} |
| 65 |
|
| 66 |
private final boolean enabled; |
| 67 |
|
| 68 |
private final Optional<String> reason; |
| 69 |
|
| 70 |
private ConditionEvaluationResult(boolean enabled, String reason) { |
| 71 |
this.enabled = enabled; |
| 72 |
this.reason = Optional.ofNullable(reason); |
| 73 |
} |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|
| 79 |
|
| 80 |
public boolean isDisabled() { |
| 81 |
return !this.enabled; |
| 82 |
} |
| 83 |
|
| 84 |
|
| 85 |
|
| 86 |
|
| 87 |
|
| 88 |
public Optional<String> getReason() { |
| 89 |
return this.reason; |
| 90 |
} |
| 91 |
|
| 92 |
@Override |
| 93 |
public String toString() { |
| 94 |
|
| 95 |
return new ToStringBuilder(this) |
| 96 |
.append("enabled", this.enabled) |
| 97 |
.append("reason", this.reason.orElse("<unknown>")) |
| 98 |
.toString(); |
| 99 |
|
| 100 |
} |
| 101 |
|
| 102 |
} |