Merge branch '2.7.x' into 3.0.x
This commit is contained in:
@@ -37,16 +37,22 @@ import org.junit.jupiter.api.extension.ExtendWith;
|
||||
public @interface DisabledOnOs {
|
||||
|
||||
/**
|
||||
* See {@link org.junit.jupiter.api.condition.DisabledOnOs#value()}.
|
||||
* @return os
|
||||
* The operating systems on which the annotated class or method should be disabled.
|
||||
* @return the operating systems where the test is disabled
|
||||
*/
|
||||
OS[] os();
|
||||
OS[] value() default {};
|
||||
|
||||
/**
|
||||
* Architecture of the operating system.
|
||||
* @return architecture
|
||||
* The operating systems on which the annotated class or method should be disabled.
|
||||
* @return the operating systems where the test is disabled
|
||||
*/
|
||||
String architecture();
|
||||
OS[] os() default {};
|
||||
|
||||
/**
|
||||
* The architectures on which the annotated class or method should be disabled.
|
||||
* @return the architectures where the test is disabled
|
||||
*/
|
||||
String[] architecture() default {};
|
||||
|
||||
/**
|
||||
* See {@link org.junit.jupiter.api.condition.DisabledOnOs#disabledReason()}.
|
||||
|
||||
@@ -16,42 +16,49 @@
|
||||
|
||||
package org.springframework.boot.testsupport.junit;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.junit.jupiter.api.condition.OS;
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition;
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.platform.commons.util.AnnotationUtils;
|
||||
|
||||
import org.springframework.core.annotation.MergedAnnotation;
|
||||
import org.springframework.core.annotation.MergedAnnotations;
|
||||
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
|
||||
|
||||
/**
|
||||
* Evaluates {@link DisabledOnOs}.
|
||||
*
|
||||
* @author Moritz Halbritter
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class DisabledOnOsCondition implements ExecutionCondition {
|
||||
|
||||
@Override
|
||||
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
|
||||
Optional<DisabledOnOs> annotation = AnnotationUtils.findAnnotation(context.getElement(), DisabledOnOs.class);
|
||||
if (!context.getElement().isPresent()) {
|
||||
return ConditionEvaluationResult.enabled("No element for @DisabledOnOs found");
|
||||
}
|
||||
MergedAnnotation<DisabledOnOs> annotation = MergedAnnotations
|
||||
.from(context.getElement().get(), SearchStrategy.TYPE_HIERARCHY)
|
||||
.get(DisabledOnOs.class);
|
||||
if (!annotation.isPresent()) {
|
||||
return ConditionEvaluationResult.enabled("No @DisabledOnOs found");
|
||||
}
|
||||
return evaluate(annotation.get());
|
||||
return evaluate(annotation.synthesize());
|
||||
}
|
||||
|
||||
private ConditionEvaluationResult evaluate(DisabledOnOs annotation) {
|
||||
String architecture = System.getProperty("os.arch");
|
||||
String os = System.getProperty("os.name");
|
||||
if (annotation.architecture().equals(architecture)) {
|
||||
for (OS targetOs : annotation.os()) {
|
||||
if (targetOs.isCurrentOs()) {
|
||||
String reason = annotation.disabledReason().isEmpty()
|
||||
? String.format("Disabled on OS = %s, architecture = %s", os, architecture)
|
||||
: annotation.disabledReason();
|
||||
return ConditionEvaluationResult.disabled(reason);
|
||||
}
|
||||
}
|
||||
boolean onDisabledOs = Arrays.stream(annotation.os()).anyMatch(OS::isCurrentOs);
|
||||
boolean onDisabledArchitecture = Arrays.stream(annotation.architecture()).anyMatch(architecture::equals);
|
||||
if (onDisabledOs && onDisabledArchitecture) {
|
||||
String reason = annotation.disabledReason().isEmpty()
|
||||
? String.format("Disabled on OS = %s, architecture = %s", os, architecture)
|
||||
: annotation.disabledReason();
|
||||
return ConditionEvaluationResult.disabled(reason);
|
||||
}
|
||||
return ConditionEvaluationResult
|
||||
.enabled(String.format("Enabled on OS = %s, architecture = %s", os, architecture));
|
||||
|
||||
Reference in New Issue
Block a user