Skip to content

Commit

Permalink
Merge pull request #734 from AlexElin/replace_SideEffect1
Browse files Browse the repository at this point in the history
replace SideEffect1 with java.util.function.Consumer.
  • Loading branch information
hcoles authored Feb 12, 2020
2 parents 5e6eedc + 30526af commit be8342e
Show file tree
Hide file tree
Showing 34 changed files with 124 additions and 169 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

import java.net.ServerSocket;
import java.util.List;
import java.util.function.Consumer;

import org.pitest.coverage.CoverageResult;
import org.pitest.functional.SideEffect1;
import org.pitest.util.CommunicationThread;

public class CoverageCommunicationThread extends CommunicationThread {

public CoverageCommunicationThread(final ServerSocket socket,
final CoverageOptions arguments, final List<String> tus,
final SideEffect1<CoverageResult> handler) {
final Consumer<CoverageResult> handler) {
super(socket, new SendData(arguments, tus), new Receive(handler));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
import java.io.IOException;
import java.net.ServerSocket;
import java.util.List;
import java.util.function.Consumer;

import org.pitest.coverage.CoverageResult;
import org.pitest.functional.SideEffect1;
import org.pitest.process.ProcessArgs;
import org.pitest.process.WrappingProcess;
import org.pitest.util.ExitCode;
Expand All @@ -17,7 +17,7 @@ public class CoverageProcess {

public CoverageProcess(final ProcessArgs processArgs,
final CoverageOptions arguments, final ServerSocket socket,
final List<String> testClases, final SideEffect1<CoverageResult> handler)
final List<String> testClases, final Consumer<CoverageResult> handler)
throws IOException {
this.process = new WrappingProcess(socket.getLocalPort(), processArgs,
CoverageMinion.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.util.Collection;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.logging.Logger;
import java.util.stream.Collectors;
Expand All @@ -33,7 +34,6 @@
import org.pitest.coverage.CoverageResult;
import org.pitest.coverage.analysis.LineMapper;
import org.pitest.functional.FCollection;
import org.pitest.functional.SideEffect1;
import org.pitest.functional.prelude.Prelude;
import org.pitest.help.Help;
import org.pitest.help.PitHelpError;
Expand Down Expand Up @@ -122,7 +122,7 @@ private void gatherCoverageData(final Collection<ClassInfo> tests,
final List<String> filteredTests = FCollection
.map(tests, classInfoToName());

final SideEffect1<CoverageResult> handler = resultProcessor(coverage);
final Consumer<CoverageResult> handler = resultProcessor(coverage);

final SocketFinder sf = new SocketFinder();
final ServerSocket socket = sf.getNextAvailableServerSocket();
Expand Down Expand Up @@ -154,31 +154,31 @@ private static Function<ClassInfo, String> classInfoToName() {
return a -> a.getName().asInternalName();
}

private SideEffect1<String> captureStandardOutIfVerbose() {
private Consumer<String> captureStandardOutIfVerbose() {
if (this.coverageOptions.isVerbose()) {
return log();
} else {
return Prelude.noSideEffect(String.class);
}
}

private static SideEffect1<String> logInfo() {
private static Consumer<String> logInfo() {
return a -> LOG.info("MINION : " + a);
}

private static SideEffect1<String> log() {
private static Consumer<String> log() {
return a -> LOG.fine("MINION : " + a);
}

private SideEffect1<CoverageResult> resultProcessor(
private Consumer<CoverageResult> resultProcessor(
final CoverageData coverage) {
return new SideEffect1<CoverageResult>() {
return new Consumer<CoverageResult>() {
private final String[] spinner = new String[] { "\u0008/", "\u0008-",
"\u0008\\", "\u0008|" };
int i = 0;

@Override
public void apply(final CoverageResult cr) {
public void accept(final CoverageResult cr) {
if (cr.isGreenTest() || !coverageOptions.getPitConfig().skipFailingTests()) {
coverage.calculateClassCoverage(cr);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Consumer;

import org.pitest.classinfo.ClassName;
import org.pitest.coverage.BlockLocation;
import org.pitest.coverage.CoverageResult;
import org.pitest.functional.SideEffect1;
import org.pitest.mutationtest.engine.Location;
import org.pitest.mutationtest.engine.MethodName;
import org.pitest.testapi.Description;
Expand All @@ -24,9 +24,9 @@ final class Receive implements ReceiveStrategy {
private final Map<Integer, ClassName> classIdToName = new ConcurrentHashMap<>();
private final Map<Long, BlockLocation> probeToBlock = new ConcurrentHashMap<>();

private final SideEffect1<CoverageResult> handler;
private final Consumer<CoverageResult> handler;

Receive(final SideEffect1<CoverageResult> handler) {
Receive(final Consumer<CoverageResult> handler) {
this.handler = handler;
}

Expand Down Expand Up @@ -75,7 +75,7 @@ private void handleTestEnd(final SafeDataInputStream is) {
readProbeHit(is, hits);
}

this.handler.apply(createCoverageResult(is, d, hits));
this.handler.accept(createCoverageResult(is, d, hits));
}

private void readProbeHit(final SafeDataInputStream is,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package org.pitest.coverage.execute;

import java.util.List;
import java.util.function.Consumer;
import java.util.logging.Logger;

import org.pitest.functional.SideEffect1;
import org.pitest.util.Log;
import org.pitest.util.SafeDataOutputStream;

final class SendData implements SideEffect1<SafeDataOutputStream> {
final class SendData implements Consumer<SafeDataOutputStream> {
private static final Logger LOG = Log.getLogger();
private final CoverageOptions arguments;
private final List<String> testClasses;
Expand All @@ -18,7 +18,7 @@ final class SendData implements SideEffect1<SafeDataOutputStream> {
}

@Override
public void apply(final SafeDataOutputStream dos) {
public void accept(final SafeDataOutputStream dos) {
sendArguments(dos);
sendTests(dos);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

import java.io.File;
import java.util.Collection;
import java.util.function.Consumer;

import org.pitest.classinfo.ClassName;
import org.pitest.functional.SideEffect1;
import org.pitest.functional.prelude.Prelude;
import org.pitest.mutationtest.EngineArguments;
import org.pitest.mutationtest.MutationConfig;
Expand Down Expand Up @@ -66,7 +66,7 @@ public MutationTestProcess createWorker(
return worker;
}

private SideEffect1<String> captureStdOutIfVerbose() {
private Consumer<String> captureStdOutIfVerbose() {
if (this.verbose) {
return Prelude.printWith("stdout ");
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Collectors;
Expand All @@ -13,7 +14,6 @@
import org.pitest.coverage.export.DefaultCoverageExporter;
import org.pitest.coverage.export.NullCoverageExporter;
import org.pitest.functional.FCollection;
import org.pitest.functional.SideEffect1;
import org.pitest.mutationtest.MutationEngineFactory;
import org.pitest.mutationtest.MutationResultListenerFactory;
import org.pitest.mutationtest.build.CompoundInterceptorFactory;
Expand Down Expand Up @@ -85,7 +85,7 @@ public MutationGrouperFactory getMutationGrouper() {
return firstOrDefault(groupers, new DefaultMutationGrouperFactory());
}

public void describeFeatures(SideEffect1<Feature> enabled, SideEffect1<Feature> disabled) {
public void describeFeatures(Consumer<Feature> enabled, Consumer<Feature> disabled) {
final FeatureParser parser = new FeatureParser();
final Collection<ProvidesFeature> available = new ArrayList<>(this.plugins.findInterceptors());
final List<FeatureSetting> settings = parser.parseFeatures(this.options.getFeatures());
Expand All @@ -97,14 +97,14 @@ public void describeFeatures(SideEffect1<Feature> enabled, SideEffect1<Feature>
.sorted(byName())
.collect(Collectors.toList());

enabledFeatures.stream().forEach(each -> enabled.apply(each));
enabledFeatures.forEach(enabled);

available.stream()
.map(toFeature())
.distinct()
.sorted(byName())
.filter(f -> !enabledFeatures.contains(f))
.forEach(each -> disabled.apply(each));
.forEach(disabled);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@

import java.net.ServerSocket;
import java.util.Map;
import java.util.function.Consumer;
import java.util.logging.Logger;

import org.pitest.functional.SideEffect1;
import org.pitest.mutationtest.DetectionStatus;
import org.pitest.mutationtest.MutationStatusTestPair;
import org.pitest.mutationtest.engine.MutationIdentifier;
Expand All @@ -33,15 +33,15 @@ public class MutationTestCommunicationThread extends CommunicationThread {

private static final Logger LOG = Log.getLogger();

private static class SendData implements SideEffect1<SafeDataOutputStream> {
private static class SendData implements Consumer<SafeDataOutputStream> {
private final MinionArguments arguments;

SendData(final MinionArguments arguments) {
this.arguments = arguments;
}

@Override
public void apply(final SafeDataOutputStream dos) {
public void accept(final SafeDataOutputStream dos) {
dos.write(this.arguments);
dos.flush();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
import java.util.HashMap;
import java.util.Map;
import java.util.function.BiFunction;
import java.util.function.Consumer;
import java.util.function.Function;

import org.pitest.functional.FCollection;
import org.pitest.functional.SideEffect1;
import org.pitest.mutationtest.MutationResult;

class MutationStatisticsPrecursor {
Expand All @@ -18,7 +18,7 @@ public void registerResults(final Collection<MutationResult> results) {
FCollection.forEach(results, register());
}

private SideEffect1<MutationResult> register() {
private Consumer<MutationResult> register() {
return mr -> {
MutationStatisticsPrecursor.this.numberOfTestsRun = MutationStatisticsPrecursor.this.numberOfTestsRun
+ mr.getNumberOfTestsRun();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
import org.pitest.coverage.execute.CoverageOptions;
import org.pitest.coverage.execute.DefaultCoverageGenerator;
import java.util.Optional;
import org.pitest.functional.SideEffect1;
import java.util.function.Consumer;

import org.pitest.mutationtest.HistoryStore;
import org.pitest.mutationtest.MutationResultListenerFactory;
import org.pitest.mutationtest.config.PluginServices;
Expand Down Expand Up @@ -153,7 +154,7 @@ private boolean junit5PluginIsOnClasspath() {
}
}

private SideEffect1<Feature> asInfo(final String leader) {
private Consumer<Feature> asInfo(final String leader) {
return a -> {
Log.getLogger().info(String.format("%1$-16s",leader + a.name()) + a.description());
for (final FeatureParameter each : a.params()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@
*/

import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.Predicate;

import org.pitest.classinfo.ClassInfo;
import org.pitest.classpath.CodeSource;
import org.pitest.functional.FCollection;
import org.pitest.functional.SideEffect1;
import org.pitest.help.Help;
import org.pitest.help.PitHelpError;

Expand Down Expand Up @@ -62,7 +62,7 @@ private static Predicate<ClassInfo> aClassWithLineNumbers() {
return a -> a.getNumberOfCodeLines() != 0;
}

private SideEffect1<ClassInfo> throwErrorIfHasNoSourceFile() {
private Consumer<ClassInfo> throwErrorIfHasNoSourceFile() {
return a -> {
if (a.getSourceFileName() == null) {
throw new PitHelpError(Help.NO_SOURCE_FILE, a.getName().asJavaName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,19 @@
*/
package org.pitest.process;

import org.pitest.functional.SideEffect1;
import org.pitest.util.Monitor;
import org.pitest.util.StreamMonitor;

import java.util.function.Consumer;

public class JavaProcess {

private final Process process;
private final Monitor out;
private final Monitor err;

public JavaProcess(Process process, SideEffect1<String> sysoutHandler,
SideEffect1<String> syserrHandler) {
public JavaProcess(Process process, Consumer<String> sysoutHandler,
Consumer<String> syserrHandler) {
this.process = process;

this.out = new StreamMonitor(process.getInputStream(), sysoutHandler);
Expand Down
18 changes: 9 additions & 9 deletions pitest-entry/src/main/java/org/pitest/process/ProcessArgs.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.function.Consumer;

import org.pitest.classpath.ClassPath;
import org.pitest.functional.SideEffect1;

public final class ProcessArgs {

private final String launchClassPath;
private SideEffect1<String> stdout = print(String.class);
private SideEffect1<String> stdErr = printTo(String.class, System.err);
private Consumer<String> stdout = print(String.class);
private Consumer<String> stdErr = printTo(String.class, System.err);
private List<String> jvmArgs = Collections.emptyList();
private JavaAgent javaAgentFinder;
private File workingDir = null;
Expand All @@ -54,12 +54,12 @@ public ProcessArgs andBaseDir(final File baseDir) {
return this;
}

public ProcessArgs andStdout(final SideEffect1<String> stdout) {
public ProcessArgs andStdout(final Consumer<String> stdout) {
this.stdout = stdout;
return this;
}

public ProcessArgs andStderr(final SideEffect1<String> stderr) {
public ProcessArgs andStderr(final Consumer<String> stderr) {
this.stdErr = stderr;
return this;
}
Expand All @@ -68,11 +68,11 @@ public String getLaunchClassPath() {
return this.launchClassPath;
}

public SideEffect1<String> getStdout() {
public Consumer<String> getStdout() {
return this.stdout;
}

public SideEffect1<String> getStdErr() {
public Consumer<String> getStdErr() {
return this.stdErr;
}

Expand All @@ -84,11 +84,11 @@ public JavaAgent getJavaAgentFinder() {
return this.javaAgentFinder;
}

public void setStdout(final SideEffect1<String> stdout) {
public void setStdout(final Consumer<String> stdout) {
this.stdout = stdout;
}

public void setStdErr(final SideEffect1<String> stdErr) {
public void setStdErr(final Consumer<String> stdErr) {
this.stdErr = stdErr;
}

Expand Down
Loading

0 comments on commit be8342e

Please sign in to comment.