Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#40: Resolve single UniqueIdSpecification for method
------------------------------------------------------------------------ On behalf of the community, the JUnit Lambda Team thanks Klarna AB (http://www.klarna.com) for supporting the JUnit crowdfunding campaign! ------------------------------------------------------------------------
- Loading branch information
1 parent
441f64b
commit eb487e9
Showing
6 changed files
with
157 additions
and
12 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
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
40 changes: 40 additions & 0 deletions
40
...src/main/java/org/junit/gen5/engine/junit4/discovery/RunnerTestDescriptorAwareFilter.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,40 @@ | ||
/* | ||
* Copyright 2015-2016 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.junit4.discovery; | ||
|
||
import org.junit.gen5.engine.junit4.descriptor.RunnerTestDescriptor; | ||
import org.junit.runner.Description; | ||
import org.junit.runner.manipulation.Filter; | ||
|
||
abstract class RunnerTestDescriptorAwareFilter extends Filter { | ||
|
||
abstract void initialize(RunnerTestDescriptor runnerTestDescriptor); | ||
|
||
static RunnerTestDescriptorAwareFilter adapter(Filter filter) { | ||
return new RunnerTestDescriptorAwareFilter() { | ||
@Override | ||
void initialize(RunnerTestDescriptor runnerTestDescriptor) { | ||
// do nothing | ||
} | ||
|
||
@Override | ||
public boolean shouldRun(Description description) { | ||
return filter.shouldRun(description); | ||
} | ||
|
||
@Override | ||
public String describe() { | ||
return filter.describe(); | ||
} | ||
}; | ||
} | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
junit4-engine/src/main/java/org/junit/gen5/engine/junit4/discovery/UniqueIdFilter.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,52 @@ | ||
/* | ||
* Copyright 2015-2016 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.junit4.discovery; | ||
|
||
import java.util.Deque; | ||
import java.util.LinkedList; | ||
import java.util.Optional; | ||
|
||
import org.junit.gen5.engine.TestDescriptor; | ||
import org.junit.gen5.engine.junit4.descriptor.JUnit4TestDescriptor; | ||
import org.junit.gen5.engine.junit4.descriptor.RunnerTestDescriptor; | ||
import org.junit.runner.Description; | ||
|
||
class UniqueIdFilter extends RunnerTestDescriptorAwareFilter { | ||
|
||
private final String uniqueId; | ||
|
||
private Deque<Description> path; | ||
|
||
public UniqueIdFilter(String uniqueId) { | ||
this.uniqueId = uniqueId; | ||
} | ||
|
||
@Override | ||
void initialize(RunnerTestDescriptor runnerTestDescriptor) { | ||
Optional<? extends TestDescriptor> identifiedTestDescriptor = runnerTestDescriptor.findByUniqueId(uniqueId); | ||
path = new LinkedList<>(); | ||
while (identifiedTestDescriptor.isPresent() && !identifiedTestDescriptor.get().equals(runnerTestDescriptor)) { | ||
path.addFirst(((JUnit4TestDescriptor) identifiedTestDescriptor.get()).getDescription()); | ||
identifiedTestDescriptor = identifiedTestDescriptor.get().getParent(); | ||
} | ||
} | ||
|
||
@Override | ||
public boolean shouldRun(Description description) { | ||
return path.contains(description); | ||
} | ||
|
||
@Override | ||
public String describe() { | ||
return "Unique ID " + uniqueId; | ||
} | ||
|
||
} |