Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/641 revised #834

Closed
wants to merge 19 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions archunit-example/example-junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ plugins {
id 'archunit.java-examples-conventions'
}

repositories {
flatDir {
dirs "${rootDir}/inlineDeps/"
}
}

ext.moduleName = 'com.tngtech.archunit.example.junit5'
ext.minimumJavaVersion = JavaVersion.VERSION_1_8

Expand Down
6 changes: 6 additions & 0 deletions archunit-integration-test/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ plugins {
id 'archunit.java-conventions'
}

repositories {
flatDir {
dirs "${rootDir}/inlineDeps/"
}
}

ext.moduleName = 'com.tngtech.archunit.integrationtest'

ext.minimumJavaVersion = JavaVersion.VERSION_1_8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.lang.reflect.Field;

import com.tngtech.archunit.core.domain.JavaClasses;
import org.junit.AssumptionViolatedException;
import org.junit.runner.Description;
import org.junit.runner.notification.Failure;
import org.junit.runner.notification.RunNotifier;
Expand Down Expand Up @@ -78,4 +79,19 @@ void notify(RunNotifier notifier) {
notifier.fireTestFailure(new Failure(description, failure));
}
}

static class AbortedResult extends Result {
private final Description description;
private final AssumptionViolatedException failedAssumption;

AbortedResult(Description description, AssumptionViolatedException failedAssumption) {
this.description = description;
this.failedAssumption = failedAssumption;
}

@Override
void notify(RunNotifier notifier) {
notifier.fireTestAssumptionFailed(new Failure(description, failedAssumption));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.util.Arrays;

import com.tngtech.archunit.core.domain.JavaClasses;
import org.junit.AssumptionViolatedException;
import org.junit.runner.Description;

import static com.tngtech.archunit.junit.DisplayNameResolver.determineDisplayName;
Expand All @@ -37,6 +38,8 @@ Result evaluateOn(JavaClasses classes) {
try {
executeTestMethod(classes);
return new PositiveResult();
} catch (AssumptionViolatedException failedAssumption) {
return new AbortedResult(describeSelf(), failedAssumption);
} catch (Throwable failure) {
return new NegativeResult(describeSelf(), failure);
}
Expand Down
6 changes: 6 additions & 0 deletions archunit-junit/junit5/aggregator/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ plugins {
id 'archunit.java-release-conventions'
}

repositories {
flatDir {
dirs "${rootDir}/inlineDeps/"
}
}

ext.moduleName = 'com.tngtech.archunit.junit5'

ext.minimumJavaVersion = JavaVersion.VERSION_1_8
Expand Down
3 changes: 2 additions & 1 deletion archunit-junit/junit5/api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ dependencies {
api project(path: ':archunit')
api project(path: ':archunit-junit', configuration: 'archJunitApi')
api dependency.junitPlatformCommons
api dependency.junit5JupiterApi
}

javadoc {
Expand All @@ -33,4 +34,4 @@ def configureDependencies = { deps ->
dep.scope.text() != 'compile' || !(dep.artifactId.text() in ['archunit'])
}
}
this.with project(':archunit-junit').configureJUnitArchive(configureDependencies)
this.with project(':archunit-junit').configureJUnitArchive(configureDependencies)
Original file line number Diff line number Diff line change
@@ -0,0 +1,262 @@
/*
* Copyright 2014-2022 TNG Technology Consulting GmbH
*
* 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
*
* http://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 com.tngtech.archunit.junit.conditions;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import com.tngtech.archunit.PublicAPI;
import com.tngtech.archunit.PublicAPI.State;
import com.tngtech.archunit.PublicAPI.Usage;
import com.tngtech.archunit.junit.internal.AdapterFor;
import com.tngtech.archunit.junit.ArchTest;
import org.junit.jupiter.api.condition.JRE;
import org.junit.jupiter.api.condition.OS;


/**
* A collection of wrappers for declaring {@code DisabledIfXxx} annotations on {@link ArchTest} annotated fields
*/
@Target({ })
@Retention(RetentionPolicy.RUNTIME)
@Documented
public @interface Conditions {

@Target(ElementType.FIELD)
Copy link
Contributor Author

@crizzis crizzis Mar 14, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that for method-flavored ArchUnit tests, the default org.junit.jupiter.api.condition annotations now work just fine.

The annotations in this file are only needed for field-flavored tests, because the original JUnit annotations fail to declare FIELDs as annotation targets.

@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable.class)
@interface DisabledIfEnvironmentVariable {
String named();

/**
* @see org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable#matches()
*/
String matches();

/**
* @see org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable.class)
@interface EnabledIfEnvironmentVariable {
/**
* @see org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable#named()
*/
String named();

/**
* @see org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable#matches()
*/
String matches();

/**
* @see org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.EnabledIfSystemProperty.class)
@interface EnabledIfSystemProperty {

/**
* @see org.junit.jupiter.api.condition.EnabledIfSystemProperty#named()
*/
String named();

/**
* @see org.junit.jupiter.api.condition.EnabledIfSystemProperty#matches()
*/
String matches();

/**
* @see org.junit.jupiter.api.condition.EnabledIfSystemProperty#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.DisabledIfSystemProperty.class)
@interface DisabledIfSystemProperty {

/**
* @see org.junit.jupiter.api.condition.DisabledIfSystemProperty#named()
*/
String named();

/**
* @see org.junit.jupiter.api.condition.DisabledIfSystemProperty#matches()
*/
String matches();

/**
* @see org.junit.jupiter.api.condition.DisabledIfSystemProperty#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.EnabledOnJre.class)
@interface EnabledOnJre {

/**
* @see org.junit.jupiter.api.condition.EnabledOnJre#value()
*/
JRE[] value();

/**
* @see org.junit.jupiter.api.condition.EnabledOnJre#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.DisabledOnJre.class)
@interface DisabledOnJre {
/**
* @see org.junit.jupiter.api.condition.DisabledOnJre#value()
*/
JRE[] value();

/**
* @see org.junit.jupiter.api.condition.DisabledOnJre#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.EnabledForJreRange.class)
@interface EnabledForJreRange {
/**
* @see org.junit.jupiter.api.condition.EnabledForJreRange#min()
*/
JRE min() default JRE.JAVA_8;

/**
* @see org.junit.jupiter.api.condition.EnabledForJreRange#max()
*/
JRE max() default JRE.OTHER;

/**
* @see org.junit.jupiter.api.condition.EnabledForJreRange#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.DisabledForJreRange.class)
@interface DisabledForJreRange {
/**
* @see org.junit.jupiter.api.condition.DisabledForJreRange#min()
*/
JRE min() default JRE.JAVA_8;

/**
* @see org.junit.jupiter.api.condition.DisabledForJreRange#max()
*/
JRE max() default JRE.OTHER;

/**
* @see org.junit.jupiter.api.condition.DisabledForJreRange#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.EnabledOnOs.class)
@interface EnabledOnOs {
/**
* @see org.junit.jupiter.api.condition.EnabledOnOs#value()
*/
OS[] value();

/**
* @see org.junit.jupiter.api.condition.EnabledOnOs#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.DisabledOnOs.class)
@interface DisabledOnOs {
/**
* @see org.junit.jupiter.api.condition.DisabledOnOs#value()
*/
OS[] value();

/**
* @see org.junit.jupiter.api.condition.DisabledOnOs#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.EnabledIf.class)
@interface EnabledIf {
/**
* @see org.junit.jupiter.api.condition.EnabledIf#value()
*/
String value();

/**
* @see org.junit.jupiter.api.condition.EnabledIf#disabledReason()
*/
String disabledReason() default "";
}

@Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME)
@PublicAPI(usage = Usage.ACCESS, state = State.EXPERIMENTAL)
@AdapterFor(org.junit.jupiter.api.condition.DisabledIf.class)
@interface DisabledIf {
/**
* @see org.junit.jupiter.api.condition.DisabledIf#value()
*/
String value();

/**
* @see org.junit.jupiter.api.condition.DisabledIf#disabledReason()
*/
String disabledReason() default "";
}
}
2 changes: 1 addition & 1 deletion archunit-junit/junit5/engine-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ dependencies {
implementation project(path: ':archunit')
dependency.addGuava { dependencyNotation, config -> implementation(dependencyNotation, config) }
implementation dependency.slf4j
implementation dependency.junit5JupiterApi

testImplementation project(path: ':archunit-junit5-api')
testImplementation project(path: ':archunit', configuration: 'tests')
testImplementation dependency.assertj
testImplementation dependency.mockito
testImplementation dependency.junit5JupiterApi

testRuntimeOnly dependency.junit5JupiterEngine
}
Expand Down
Loading