Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Convert Condition to a first-class TestExtension
- Condition now extends TestExtension. - @conditional has been removed. - Conditions are now registered via @ExtendWith - DisabledCondition is now a top-level class within the JUnit 5 Engine. - DisabledCondition is now registered by default. - ConditionEvaluator now retrieves Conditions from the execution context. - Introduced example @SystemProperty support in DisabledTests.
- Loading branch information
Showing
10 changed files
with
174 additions
and
152 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 0 additions & 43 deletions
43
junit5-api/src/main/java/org/junit/gen5/api/extension/Conditional.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
junit5-engine/src/main/java/org/junit/gen5/engine/junit5/extension/DisabledCondition.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
/* | ||
* Copyright 2015 the original author or authors. | ||
* | ||
* All rights reserved. This program and the accompanying materials are | ||
* made available under the terms of the Eclipse Public License v1.0 which | ||
* accompanies this distribution and is available at | ||
* | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
|
||
package org.junit.gen5.engine.junit5.extension; | ||
|
||
import static org.junit.gen5.commons.util.AnnotationUtils.findAnnotation; | ||
|
||
import java.util.Optional; | ||
|
||
import org.junit.gen5.api.Disabled; | ||
import org.junit.gen5.api.extension.Condition; | ||
import org.junit.gen5.api.extension.TestExecutionContext; | ||
import org.junit.gen5.commons.util.StringUtils; | ||
|
||
/** | ||
* {@link Condition} that supports the {@link Disabled @Disabled} annotation. | ||
* | ||
* @author Sam Brannen | ||
* @since 5.0 | ||
* @see Disabled | ||
*/ | ||
public class DisabledCondition implements Condition { | ||
|
||
/** | ||
* Tests are disabled if {@code @Disabled} is either present on the | ||
* test class or on the test method. | ||
*/ | ||
@Override | ||
public Result evaluate(TestExecutionContext context) { | ||
|
||
// Class level? | ||
Optional<Disabled> disabled = findAnnotation(context.getTestClass(), Disabled.class); | ||
|
||
// Method level? | ||
if (!disabled.isPresent()) { | ||
disabled = findAnnotation(context.getTestMethod(), Disabled.class); | ||
} | ||
|
||
if (disabled.isPresent()) { | ||
String reason = disabled.map(Disabled::value).filter(StringUtils::isNotBlank).orElse("Test is @Disabled"); | ||
return Result.disabled(reason); | ||
} | ||
|
||
return Result.enabled("@Disabled is not present"); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.