Simplify @EneabledIfRuntimeHintsAgent support

Since the RuntimeHintsAgentCondition is based solely on the result of
invoking a boolean static method, there is no need to implement a custom
ExecutionCondition. For such use cases, the @EnabledIf support in JUnit
Jupiter is sufficient.

This commit therefore replaces the custom RuntimeHintsAgentCondition
with use of @EnabledIf as a meta-annotation.
This commit is contained in:
Sam Brannen 2022-07-03 20:31:31 +02:00 committed by Brian Clozel
parent f5503298fb
commit c34ccfdb81
2 changed files with 4 additions and 52 deletions

View File

@ -22,8 +22,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.condition.EnabledIf;
import org.springframework.aot.agent.RuntimeHintsAgent;
@ -51,13 +50,13 @@ import org.springframework.aot.agent.RuntimeHintsAgent;
* </pre>
*
* @author Brian Clozel
* @author Sam Brannen
* @since 6.0
*/
@Target({ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME)
@Documented
@ExtendWith(RuntimeHintsAgentCondition.class)
@Tag("RuntimeHintsTests")
@EnabledIf(value = "org.springframework.aot.agent.RuntimeHintsAgent#isLoaded",
disabledReason = "RuntimeHintsAgent is not loaded on the current JVM")
public @interface EnabledIfRuntimeHintsAgent {
}

View File

@ -1,47 +0,0 @@
/*
* Copyright 2002-2022 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.aot.test.agent;
import org.junit.jupiter.api.extension.ConditionEvaluationResult;
import org.junit.jupiter.api.extension.ExecutionCondition;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.springframework.aot.agent.RuntimeHintsAgent;
import static org.junit.platform.commons.support.AnnotationSupport.findAnnotation;
/**
* {@link ExecutionCondition} for {@link EnabledIfRuntimeHintsAgent @EnabledIfRuntimeHintsAgent}.
*
* @author Brian Clozel
* @since 6.0
*/
class RuntimeHintsAgentCondition implements ExecutionCondition {
@Override
public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext context) {
return findAnnotation(context.getElement(), EnabledIfRuntimeHintsAgent.class)
.map(annotation -> checkRuntimeHintsAgentPresence())
.orElse(ConditionEvaluationResult.enabled("@EnabledIfRuntimeHintsAgent is not present"));
}
static ConditionEvaluationResult checkRuntimeHintsAgentPresence() {
return RuntimeHintsAgent.isLoaded() ? ConditionEvaluationResult.enabled("RuntimeHintsAgent is loaded")
: ConditionEvaluationResult.disabled("RuntimeHintsAgent is not loaded on the current JVM");
}
}