Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow executing dynamic tests/test template invocations by unique ID
Resolves #1025.
- Loading branch information
1 parent
7eea254
commit fbbd70b
Showing
15 changed files
with
572 additions
and
94 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
58 changes: 58 additions & 0 deletions
58
...ter-engine/src/main/java/org/junit/jupiter/engine/descriptor/DynamicDescendantFilter.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,58 @@ | |||
/* | |||
* Copyright 2015-2018 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 v2.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v20.html | |||
*/ | |||
|
|||
package org.junit.jupiter.engine.descriptor; | |||
|
|||
import static org.apiguardian.api.API.Status.INTERNAL; | |||
|
|||
import java.util.HashSet; | |||
import java.util.Set; | |||
import java.util.function.Predicate; | |||
|
|||
import org.apiguardian.api.API; | |||
import org.junit.platform.engine.TestDescriptor; | |||
import org.junit.platform.engine.UniqueId; | |||
|
|||
/** | |||
* Filter for dynamic descendants of {@link TestDescriptor TestDescriptors} that | |||
* implement {@link Filterable}. | |||
* | |||
* @since 5.1 | |||
* @see Filterable | |||
*/ | |||
@API(status = INTERNAL, since = "5.1") | |||
public class DynamicDescendantFilter implements Predicate<UniqueId> { | |||
|
|||
private final Set<UniqueId> allowed = new HashSet<>(); | |||
private Mode mode = Mode.EXPLICIT; | |||
|
|||
public void allow(UniqueId uniqueId) { | |||
if (this.mode == Mode.EXPLICIT) { | |||
this.allowed.add(uniqueId); | |||
} | |||
} | |||
|
|||
public void allowAll() { | |||
this.mode = Mode.ALLOW_ALL; | |||
this.allowed.clear(); | |||
} | |||
|
|||
public boolean test(UniqueId uniqueId) { | |||
return allowed.isEmpty() || allowed.stream().anyMatch(allowedUniqueId -> isAllowed(uniqueId, allowedUniqueId)); | |||
} | |||
|
|||
private boolean isAllowed(UniqueId currentUniqueId, UniqueId allowedUniqueId) { | |||
return allowedUniqueId.hasPrefix(currentUniqueId) || currentUniqueId.hasPrefix(allowedUniqueId); | |||
} | |||
|
|||
private enum Mode { | |||
EXPLICIT, ALLOW_ALL | |||
} | |||
} |
30 changes: 30 additions & 0 deletions
30
junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/descriptor/Filterable.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 | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,30 @@ | |||
/* | |||
* Copyright 2015-2018 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 v2.0 which | |||
* accompanies this distribution and is available at | |||
* | |||
* http://www.eclipse.org/legal/epl-v20.html | |||
*/ | |||
|
|||
package org.junit.jupiter.engine.descriptor; | |||
|
|||
import static org.apiguardian.api.API.Status.INTERNAL; | |||
|
|||
import org.apiguardian.api.API; | |||
|
|||
/** | |||
* {@code Filterable} is implemented by | |||
* {@link org.junit.platform.engine.TestDescriptor TestDescriptors} that may | |||
* register dynamic tests during execution and support selective test execution. | |||
* | |||
* @since 5.1 | |||
* @see DynamicDescendantFilter | |||
*/ | |||
@API(status = INTERNAL, since = "5.1") | |||
public interface Filterable { | |||
|
|||
DynamicDescendantFilter getDynamicDescendantFilter(); | |||
|
|||
} |
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
Oops, something went wrong.