-
Notifications
You must be signed in to change notification settings - Fork 357
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Henry Coles
committed
May 19, 2021
1 parent
cba9290
commit 283f387
Showing
9 changed files
with
328 additions
and
11 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
71 changes: 71 additions & 0 deletions
71
pitest/src/main/java/org/pitest/mutationtest/config/PrioritisingTestConfiguration.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,71 @@ | ||
package org.pitest.mutationtest.config; | ||
|
||
import org.pitest.help.PitHelpError; | ||
import org.pitest.testapi.Configuration; | ||
import org.pitest.testapi.TestSuiteFinder; | ||
import org.pitest.testapi.TestUnitFinder; | ||
|
||
import java.util.Comparator; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
class PrioritisingTestConfiguration implements Configuration { | ||
private final List<Configuration> children; | ||
private final TestUnitFinder finder; | ||
private final TestSuiteFinder suiteFinder; | ||
|
||
PrioritisingTestConfiguration(List<Configuration> children) { | ||
this.children = pickChildren(children); | ||
this.finder = makeFinder(this.children); | ||
this.suiteFinder = makeSuiteFinder(this.children); | ||
} | ||
|
||
@Override | ||
public TestUnitFinder testUnitFinder() { | ||
return finder; | ||
} | ||
|
||
@Override | ||
public TestSuiteFinder testSuiteFinder() { | ||
return suiteFinder; | ||
} | ||
|
||
@Override | ||
public Optional<PitHelpError> verifyEnvironment() { | ||
return children.stream() | ||
.map(Configuration::verifyEnvironment) | ||
.findFirst() | ||
.get(); | ||
} | ||
|
||
private static List<Configuration> pickChildren(List<Configuration> configs) { | ||
List<Configuration> working = configs.stream() | ||
.filter(c -> !c.verifyEnvironment().isPresent()) | ||
.sorted(byPriority()) | ||
.collect(Collectors.toList()); | ||
// We don't have a working config, let it report errors later | ||
if (working.isEmpty()) { | ||
return configs; | ||
} | ||
return working; | ||
} | ||
|
||
private static Comparator<Configuration> byPriority() { | ||
return Comparator.comparingInt(Configuration::priority); | ||
} | ||
|
||
private TestUnitFinder makeFinder(List<Configuration> children) { | ||
List<TestUnitFinder> finders = children.stream() | ||
.map(Configuration::testUnitFinder) | ||
.collect(Collectors.toList()); | ||
return new PrioritisingTestUnitFinder(finders); | ||
} | ||
|
||
private TestSuiteFinder makeSuiteFinder(List<Configuration> children) { | ||
List<TestSuiteFinder> finders = children.stream() | ||
.map(Configuration::testSuiteFinder) | ||
.collect(Collectors.toList()); | ||
return new PrioritisingTestSuiteFinder(finders); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
pitest/src/main/java/org/pitest/mutationtest/config/PrioritisingTestSuiteFinder.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,25 @@ | ||
package org.pitest.mutationtest.config; | ||
|
||
import org.pitest.testapi.TestSuiteFinder; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
class PrioritisingTestSuiteFinder implements TestSuiteFinder { | ||
private final List<TestSuiteFinder> orderedChildren; | ||
|
||
PrioritisingTestSuiteFinder(List<TestSuiteFinder> orderedChildren) { | ||
this.orderedChildren = orderedChildren; | ||
} | ||
|
||
@Override | ||
public List<Class<?>> apply(Class<?> clazz) { | ||
for (TestSuiteFinder each : orderedChildren) { | ||
List<Class<?>> found = each.apply(clazz); | ||
if (!found.isEmpty()) { | ||
return found; | ||
} | ||
} | ||
return Collections.emptyList(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
pitest/src/main/java/org/pitest/mutationtest/config/PrioritisingTestUnitFinder.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,26 @@ | ||
package org.pitest.mutationtest.config; | ||
|
||
import org.pitest.testapi.TestUnit; | ||
import org.pitest.testapi.TestUnitFinder; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
class PrioritisingTestUnitFinder implements TestUnitFinder { | ||
private final List<TestUnitFinder> orderedChildren; | ||
|
||
PrioritisingTestUnitFinder(List<TestUnitFinder> orderedChildren) { | ||
this.orderedChildren = orderedChildren; | ||
} | ||
|
||
@Override | ||
public List<TestUnit> findTestUnits(Class<?> clazz) { | ||
for (TestUnitFinder each : orderedChildren) { | ||
List<TestUnit> found = each.findTestUnits(clazz); | ||
if (!found.isEmpty()) { | ||
return found; | ||
} | ||
} | ||
return Collections.emptyList(); | ||
} | ||
} |
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.