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/old code removal #1247

Merged
merged 2 commits into from
Aug 17, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import org.pitest.classpath.DirectoryClassPathRoot;
import org.pitest.classpath.PathFilter;
import org.pitest.classpath.ProjectClassPaths;
import org.pitest.functional.FCollection;
import org.pitest.functional.prelude.Prelude;
import org.pitest.mutationtest.config.DefaultCodePathPredicate;
import org.pitest.mutationtest.config.DefaultDependencyPathPredicate;
Expand All @@ -21,6 +20,7 @@
import java.util.HashSet;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;

class CodeSourceAggregator {

Expand Down Expand Up @@ -49,10 +49,14 @@ private Predicate<String> createClassPredicate() {
for (final File buildOutputDirectory : this.compiledCodeDirectories) {
if (buildOutputDirectory.exists()) {
final DirectoryClassPathRoot dcRoot = new DirectoryClassPathRoot(buildOutputDirectory);
classes.addAll(FCollection.map(dcRoot.classNames(), toPredicate()));
classes.addAll(dcRoot.classNames().stream()
.map(toPredicate())
.collect(Collectors.toList()));
}
}
return Prelude.or(FCollection.map(classes, Glob.toGlobPredicate()));
return Prelude.or(classes.stream()
.map(Glob.toGlobPredicate())
.collect(Collectors.toList()));
}

private Function<String, String> toPredicate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import java.util.logging.Logger;
import java.util.stream.Collectors;

import static org.pitest.functional.Streams.asStream;
import static org.pitest.mutationtest.config.ConfigOption.ARG_LINE;
import static org.pitest.mutationtest.config.ConfigOption.AVOID_CALLS;
import static org.pitest.mutationtest.config.ConfigOption.CHILD_JVM;
Expand Down Expand Up @@ -437,8 +438,9 @@ private ParseResult parseCommandLine(final ReportOptions data,
final OptionSet userArgs) {
data.setReportDir(this.reportDirSpec.value(userArgs));
data.setTargetClasses(this.targetClassesSpec.values(userArgs));
data.setTargetTests(FCollection.map(this.targetTestsSpec.values(userArgs),
Glob.toGlobPredicate()));
data.setTargetTests(asStream(this.targetTestsSpec.values(userArgs))
.map(Glob.toGlobPredicate())
.collect(Collectors.toList()));
data.setSourceDirs(asPaths(this.sourceDirSpec.values(userArgs)));
data.setMutators(this.mutators.values(userArgs));
data.setFeatures(this.features.values(userArgs));
Expand Down Expand Up @@ -467,8 +469,9 @@ private ParseResult parseCommandLine(final ReportOptions data,
data.setLoggingClasses(this.avoidCallsSpec.values(userArgs));
data.setExcludedMethods(this.excludedMethodsSpec.values(userArgs));
data.setExcludedClasses(this.excludedClassesSpec.values(userArgs));
data.setExcludedTestClasses(FCollection.map(
this.excludedTestClassesSpec.values(userArgs), Glob.toGlobPredicate()));
data.setExcludedTestClasses(asStream(this.excludedTestClassesSpec.values(userArgs)).
map(Glob.toGlobPredicate())
.collect(Collectors.toList()));
configureVerbosity(data, userArgs);

data.addOutputFormats(this.outputFormatSpec.values(userArgs));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@
import org.objectweb.asm.util.Textifier;
import org.objectweb.asm.util.TraceClassVisitor;
import org.pitest.classinfo.ClassName;
import org.pitest.functional.FCollection;
import org.pitest.mutationtest.engine.Location;

import static org.pitest.functional.Streams.asStream;

public class ClassTree {

private final ClassNode rawNode;
Expand All @@ -44,7 +45,9 @@ public List<MethodTree> methods() {
if (this.lazyMethods != null) {
return this.lazyMethods;
}
this.lazyMethods = FCollection.map(this.rawNode.methods, toTree(name()));
this.lazyMethods = asStream(this.rawNode.methods)
.map(toTree(name()))
.collect(Collectors.toList());
return this.lazyMethods;
}

Expand Down
11 changes: 7 additions & 4 deletions pitest-entry/src/main/java/org/pitest/coverage/CoverageData.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.pitest.classinfo.ClassInfo;
import org.pitest.classinfo.ClassName;
import org.pitest.classpath.CodeSource;
import org.pitest.functional.FCollection;
import org.pitest.testapi.Description;
import org.pitest.util.Log;

Expand Down Expand Up @@ -124,12 +123,16 @@ public BigInteger getCoverageIdForClass(final ClassName clazz) {
}

public List<BlockCoverage> createCoverage() {
return FCollection.map(this.blockCoverage.entrySet(), toBlockCoverage());
return this.blockCoverage.entrySet().stream()
.map(toBlockCoverage())
.collect(Collectors.toList());
}

private static Function<Entry<BlockLocation, Set<TestInfo>>, BlockCoverage> toBlockCoverage() {
return a -> new BlockCoverage(a.getKey(), FCollection.map(a.getValue(),
TestInfo.toName()));
return a -> new BlockCoverage(a.getKey(),
a.getValue().stream()
.map(TestInfo.toName())
.collect(Collectors.toList()));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ public void setStatusForMutations(
}

public List<MutationResult> createMutationResults() {
return FCollection.map(this.mutationMap.entrySet(),
detailsToMutationResults());
return this.mutationMap.entrySet().stream()
.map(detailsToMutationResults())
.collect(Collectors.toList());

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public List<MutationAnalysisUnit> createMutationTestUnits(
final Collection<ClassName> codeClasses) {
final List<MutationAnalysisUnit> tus = new ArrayList<>();

final List<MutationDetails> mutations = FCollection.flatMap(codeClasses, mutationSource::createMutations);
final List<MutationDetails> mutations = codeClasses.stream()
.flatMap(c -> mutationSource.createMutations(c).stream())
.collect(Collectors.toList());

mutations.sort(comparing(MutationDetails::getId));

Expand Down Expand Up @@ -107,8 +109,9 @@ private static Predicate<MutationResult> statusNotKnown() {
}

private static Function<MutationDetails, Iterable<ClassName>> mutationDetailsToTestClass() {
return a -> FCollection.map(a.getTestsInOrder(),
TestInfo.toDefiningClassName());
return a -> a.getTestsInOrder().stream()
.map(TestInfo.toDefiningClassName())
.collect(Collectors.toList());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.pitest.classpath.ClassPathRoot;
import org.pitest.classpath.PathFilter;
import org.pitest.classpath.ProjectClassPaths;
import org.pitest.functional.FCollection;
import org.pitest.functional.prelude.Prelude;
import org.pitest.help.Help;
import org.pitest.help.PitHelpError;
Expand Down Expand Up @@ -53,6 +52,7 @@
import java.util.function.Predicate;
import java.util.stream.Collectors;

import static org.pitest.functional.Streams.asStream;
import static org.pitest.functional.prelude.Prelude.not;
import static org.pitest.functional.prelude.Prelude.or;

Expand Down Expand Up @@ -246,8 +246,9 @@ public ClassPath getClassPath() {
}

private ClassPath createClassPathFromElements() {
return new ClassPath(
FCollection.map(this.classPathElements, File::new));
return new ClassPath(asStream(this.classPathElements)
.map(File::new)
.collect(Collectors.toList()));
}

public Collection<String> getTargetClasses() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.Set;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.stream.Collectors;

import org.pitest.classinfo.ClassName;
import org.pitest.functional.FCollection;
Expand Down Expand Up @@ -55,7 +56,9 @@ public MutationStatistics toStatistics() {
}

Iterable<Score> getScores() {
return FCollection.map(this.mutatorTotalMap.values(), ScorePrecursor::toScore);
return this.mutatorTotalMap.values().stream()
.map(ScorePrecursor::toScore)
.collect(Collectors.toList());
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Function;

import org.pitest.functional.FCollection;
import java.util.Optional;
import java.util.stream.Collectors;
import java.util.stream.Stream;
Expand All @@ -42,14 +40,15 @@ public class SmartSourceLocator implements SourceLocator {

public SmartSourceLocator(final Collection<Path> roots, Charset inputCharset) {
this.inputCharset = inputCharset;
final Collection<Path> childDirs = FCollection.flatMap(roots, collectChildren(MAX_DEPTH));
childDirs.addAll(roots);
final Collection<Path> childDirs = roots.stream()
.flatMap(r -> collectDirectories(r, MAX_DEPTH).stream())
.collect(Collectors.toList());

this.children = FCollection.map(childDirs, f -> new DirectorySourceLocator(f, this.inputCharset));
}
childDirs.addAll(roots);

private Function<Path, Collection<Path>> collectChildren(final int depth) {
return a -> collectDirectories(a, depth);
this.children = childDirs.stream()
.map(f -> new DirectorySourceLocator(f, this.inputCharset))
.collect(Collectors.toList());
}

private Collection<Path> collectDirectories(Path root, int depth) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import java.util.List;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static org.assertj.core.api.Assertions.assertThat;
Expand Down Expand Up @@ -116,7 +117,9 @@ public void shouldReturnUniqueTestsForClassWhenSomeTestsCoverClass() {
this.testee.calculateClassCoverage(makeCoverageResult("foo", "fooTest2", 0,
2));

List<String> actual = FCollection.map(this.testee.getTestsForClass(this.foo), TestInfo::getName);
List<String> actual = this.testee.getTestsForClass(this.foo).stream()
.map(TestInfo::getName)
.collect(Collectors.toList());

assertThat(actual).containsExactlyInAnyOrder("fooTest", "fooTest2");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.Collection;
import java.util.function.Function;
import java.util.stream.Collectors;

import org.pitest.functional.FCollection;
import org.pitest.mutationtest.engine.MutationDetails;
Expand All @@ -15,7 +16,9 @@ public class NullAnalyser implements MutationAnalyser {
@Override
public Collection<MutationResult> analyse(
final Collection<MutationDetails> mutationsForClasses) {
return FCollection.map(mutationsForClasses, mutationToResult());
return mutationsForClasses.stream()
.map(mutationToResult())
.collect(Collectors.toList());
}

private Function<MutationDetails, MutationResult> mutationToResult() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import static org.mockito.Mockito.when;
import static org.pitest.mutationtest.LocationMother.aLocation;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Function;
Expand All @@ -20,8 +19,9 @@
import org.pitest.coverage.BlockLocation;
import org.pitest.coverage.CoverageDatabase;
import org.pitest.coverage.TestInfo;
import org.pitest.functional.FCollection;
import java.util.Optional;
import java.util.stream.Collectors;

import org.pitest.mutationtest.engine.MutationDetails;
import org.pitest.mutationtest.engine.MutationIdentifier;

Expand Down Expand Up @@ -60,18 +60,16 @@ public void shouldPrioritiseTestsByExecutionTime() {
final List<TestInfo> actual = this.testee.assignTests(makeMutation("foo"));

assertThat(actual.stream().map(toTime())).contains(1, 100, 1000, 10000);

assertEquals(Arrays.asList(1, 100, 1000, 10000),
FCollection.map(actual, toTime()));
}

private Function<TestInfo, Integer> toTime() {
return a -> a.getTime();
}

private List<TestInfo> makeTestInfos(final Integer... times) {
return new ArrayList<>(FCollection.map(Arrays.asList(times),
timeToTestInfo()));
return Arrays.stream(times)
.map(timeToTestInfo())
.collect(Collectors.toList());
}

private Function<Integer, TestInfo> timeToTestInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
Expand Down Expand Up @@ -77,8 +78,9 @@ public void shouldAssignTestsFromPrioritiserToMutant() {
}

private List<TestInfo> makeTestInfos(final Integer... times) {
return new ArrayList<>(FCollection.map(Arrays.asList(times),
timeToTestInfo()));
return Arrays.stream(times)
.map(timeToTestInfo())
.collect(Collectors.toList());
}

private Function<Integer, TestInfo> timeToTestInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;

public class AnnotatedLineFactory {

Expand Down Expand Up @@ -55,7 +56,9 @@ private Set<Integer> findCoveredLines(Collection<ClassLines> classes, ReportCove
public List<Line> convert(final Reader source) throws IOException {
try {
final InputStreamLineIterable lines = new InputStreamLineIterable(source);
return FCollection.map(lines, stringToAnnotatedLine());
return StreamSupport.stream(lines.spliterator(), false)
.map(stringToAnnotatedLine())
.collect(Collectors.toList());
} finally {
source.close();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import org.antlr.stringtemplate.StringTemplateGroup;
import org.pitest.coverage.ClassLines;
import org.pitest.coverage.ReportCoverage;
import org.pitest.functional.FCollection;
import org.pitest.mutationtest.ClassMutationResults;
import org.pitest.mutationtest.MutationResultListener;
import org.pitest.mutationtest.SourceLocator;
Expand All @@ -41,6 +40,7 @@
import java.util.Set;
import java.util.function.Function;
import java.util.logging.Level;
import java.util.stream.Collectors;

import static java.util.Arrays.asList;

Expand Down Expand Up @@ -159,9 +159,10 @@ private List<Line> createAnnotatedSourceCodeLines(final String sourceFile,
return Collections.emptyList();
}

private Collection<String> classInfoToNames(
final Collection<ClassLines> classes) {
return FCollection.map(classes, classInfoToJavaName());
private Collection<String> classInfoToNames(Collection<ClassLines> classes) {
return classes.stream()
.map(classInfoToJavaName())
.collect(Collectors.toList());
}

private Function<ClassLines, String> classInfoToJavaName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import org.junit.Before;
import org.junit.Test;
import org.pitest.functional.FCollection;

public class InputStreamLineIterableTest {

Expand All @@ -34,7 +33,7 @@ public void setUp() {

@Test
public void shouldReadAllInput() {
assertThat(FCollection.map(testee, s -> s)).containsExactly("1", "2", "3");
assertThat(testee).containsExactly("1", "2", "3");
}

}
Loading