| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
package org.junit.jupiter.api.condition; |
| 12 |
|
| 13 |
import java.util.Arrays; |
| 14 |
|
| 15 |
import org.junit.jupiter.api.extension.ConditionEvaluationResult; |
| 16 |
import org.junit.jupiter.api.extension.ExecutionCondition; |
| 17 |
import org.junit.platform.commons.util.Preconditions; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
class EnabledOnOsCondition extends AbstractOsBasedExecutionCondition<EnabledOnOs> { |
| 26 |
|
| 27 |
EnabledOnOsCondition() { |
| 28 |
super(EnabledOnOs.class); |
| 29 |
} |
| 30 |
|
| 31 |
@Override |
| 32 |
ConditionEvaluationResult evaluateExecutionCondition(EnabledOnOs annotation) { |
| 33 |
boolean osSpecified = annotation.value().length > 0; |
| 34 |
boolean archSpecified = annotation.architectures().length > 0; |
| 35 |
Preconditions.condition(osSpecified || archSpecified, |
| 36 |
"You must declare at least one OS or architecture in @EnabledOnOs"); |
| 37 |
|
| 38 |
boolean enabled = isEnabledBasedOnOs(annotation) && isEnabledBasedOnArchitecture(annotation); |
| 39 |
String reason = createReason(enabled, osSpecified, archSpecified); |
| 40 |
|
| 41 |
return enabled ? ConditionEvaluationResult.enabled(reason) |
| 42 |
: ConditionEvaluationResult.disabled(reason, annotation.disabledReason()); |
| 43 |
} |
| 44 |
|
| 45 |
private boolean isEnabledBasedOnOs(EnabledOnOs annotation) { |
| 46 |
OS[] operatingSystems = annotation.value(); |
| 47 |
if (operatingSystems.length == 0) { |
| 48 |
return true; |
| 49 |
} |
| 50 |
return Arrays.stream(operatingSystems).anyMatch(OS::isCurrentOs); |
| 51 |
} |
| 52 |
|
| 53 |
private boolean isEnabledBasedOnArchitecture(EnabledOnOs annotation) { |
| 54 |
String[] architectures = annotation.architectures(); |
| 55 |
if (architectures.length == 0) { |
| 56 |
return true; |
| 57 |
} |
| 58 |
return Arrays.stream(architectures).anyMatch(CURRENT_ARCHITECTURE::equalsIgnoreCase); |
| 59 |
} |
| 60 |
|
| 61 |
} |