mirror of
https://codeberg.org/PGPainless/sop-java.git
synced 2025-09-07 17:29:44 +02:00
Migrate AbortOnUnsupportedOption annotation back to java
This commit is contained in:
parent
cddc92bd92
commit
a2a3bda2b3
4 changed files with 44 additions and 33 deletions
|
@ -0,0 +1,18 @@
|
|||
// SPDX-FileCopyrightText: 2025 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Inherited;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target(ElementType.TYPE)
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Inherited
|
||||
public @interface AbortOnUnsupportedOption {
|
||||
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
// SPDX-FileCopyrightText: 2025 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtensionContext;
|
||||
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler;
|
||||
import sop.exception.SOPGPException;
|
||||
|
||||
import java.lang.annotation.Annotation;
|
||||
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
public class AbortOnUnsupportedOptionExtension implements TestExecutionExceptionHandler {
|
||||
|
||||
@Override
|
||||
public void handleTestExecutionException(ExtensionContext extensionContext, Throwable throwable) throws Throwable {
|
||||
Class<?> testClass = extensionContext.getRequiredTestClass();
|
||||
Annotation annotation = testClass.getAnnotation(AbortOnUnsupportedOption.class);
|
||||
if (annotation != null && throwable instanceof SOPGPException.UnsupportedOption) {
|
||||
assumeTrue(false, "Test aborted due to: " + throwable.getMessage());
|
||||
}
|
||||
throw throwable;
|
||||
}
|
||||
}
|
|
@ -1,12 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite
|
||||
|
||||
import java.lang.annotation.Inherited
|
||||
|
||||
@Target(AnnotationTarget.TYPE)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@Inherited
|
||||
annotation class AbortOnUnsupportedOption
|
|
@ -1,21 +0,0 @@
|
|||
// SPDX-FileCopyrightText: 2024 Paul Schaub <vanitasvitae@fsfe.org>
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package sop.testsuite
|
||||
|
||||
import org.junit.jupiter.api.Assumptions
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
import org.junit.jupiter.api.extension.TestExecutionExceptionHandler
|
||||
import sop.exception.SOPGPException
|
||||
|
||||
class AbortOnUnsupportedOptionExtension : TestExecutionExceptionHandler {
|
||||
override fun handleTestExecutionException(context: ExtensionContext, throwable: Throwable) {
|
||||
val testClass = context.requiredTestClass
|
||||
val annotation = testClass.getAnnotation(AbortOnUnsupportedOption::class.java)
|
||||
if (annotation != null && SOPGPException.UnsupportedOption::class.isInstance(throwable)) {
|
||||
Assumptions.assumeTrue(false, "Test aborted due to: " + throwable.message)
|
||||
}
|
||||
throw throwable
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue