From 30526afccaa596a28e9cdf0a10954700e462187c Mon Sep 17 00:00:00 2001 From: Elin Alexey Date: Wed, 12 Feb 2020 20:14:28 +0300 Subject: [PATCH] replace SideEffect1 with java.util.function.Consumer. Remove unused SideEffect2 --- .../execute/CoverageCommunicationThread.java | 4 +-- .../coverage/execute/CoverageProcess.java | 4 +-- .../execute/DefaultCoverageGenerator.java | 16 ++++++------ .../org/pitest/coverage/execute/Receive.java | 8 +++--- .../org/pitest/coverage/execute/SendData.java | 6 ++--- .../mutationtest/build/WorkerFactory.java | 4 +-- .../mutationtest/config/SettingsFactory.java | 8 +++--- .../MutationTestCommunicationThread.java | 6 ++--- .../MutationStatisticsPrecursor.java | 4 +-- .../mutationtest/tooling/EntryPoint.java | 5 ++-- .../verify/DefaultBuildVerifier.java | 4 +-- .../java/org/pitest/process/JavaProcess.java | 7 +++--- .../java/org/pitest/process/ProcessArgs.java | 18 ++++++------- .../org/pitest/util/CommunicationThread.java | 7 +++--- .../pitest/util/SocketReadingCallable.java | 9 +++---- .../java/org/pitest/util/StreamMonitor.java | 9 +++---- .../execute/CoverageProcessSystemTest.java | 6 ++--- .../pitest/coverage/execute/ReceiveTest.java | 7 +++--- .../pitest/coverage/execute/SendDataTest.java | 4 +-- .../config/SettingsFactoryTest.java | 18 ++++++------- .../pitest/process/WrappingProcessTest.java | 4 +-- .../util/SocketReadingCallableTest.java | 6 ++--- .../dependency/DependencyClassVisitor.java | 21 ++++++++-------- .../dependency/DependencyExtractor.java | 8 +++--- .../org/pitest/functional/FCollection.java | 7 +++--- .../org/pitest/functional/SideEffect1.java | 21 ---------------- .../org/pitest/functional/SideEffect2.java | 25 ------------------- .../pitest/functional/prelude/Prelude.java | 18 ++++++------- .../org/pitest/testapi/execute/Pitest.java | 2 +- .../pitest/testapi/execute/ResultType.java | 16 ++++++------ .../DependencyClassVisitorTest.java | 4 +-- .../pitest/functional/FCollectionTest.java | 3 ++- .../functional/prelude/PreludeTest.java | 2 +- .../testapi/execute/ResultTypeTest.java | 2 +- 34 files changed, 124 insertions(+), 169 deletions(-) delete mode 100644 pitest/src/main/java/org/pitest/functional/SideEffect1.java delete mode 100644 pitest/src/main/java/org/pitest/functional/SideEffect2.java diff --git a/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageCommunicationThread.java b/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageCommunicationThread.java index 00e822508..1e29bd1e6 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageCommunicationThread.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageCommunicationThread.java @@ -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 tus, - final SideEffect1 handler) { + final Consumer handler) { super(socket, new SendData(arguments, tus), new Receive(handler)); } diff --git a/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageProcess.java b/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageProcess.java index 63c322257..976ca6104 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageProcess.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/execute/CoverageProcess.java @@ -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; @@ -17,7 +17,7 @@ public class CoverageProcess { public CoverageProcess(final ProcessArgs processArgs, final CoverageOptions arguments, final ServerSocket socket, - final List testClases, final SideEffect1 handler) + final List testClases, final Consumer handler) throws IOException { this.process = new WrappingProcess(socket.getLocalPort(), processArgs, CoverageMinion.class); diff --git a/pitest-entry/src/main/java/org/pitest/coverage/execute/DefaultCoverageGenerator.java b/pitest-entry/src/main/java/org/pitest/coverage/execute/DefaultCoverageGenerator.java index 7b3c5d95b..ab854ae33 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/execute/DefaultCoverageGenerator.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/execute/DefaultCoverageGenerator.java @@ -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; @@ -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; @@ -122,7 +122,7 @@ private void gatherCoverageData(final Collection tests, final List filteredTests = FCollection .map(tests, classInfoToName()); - final SideEffect1 handler = resultProcessor(coverage); + final Consumer handler = resultProcessor(coverage); final SocketFinder sf = new SocketFinder(); final ServerSocket socket = sf.getNextAvailableServerSocket(); @@ -154,7 +154,7 @@ private static Function classInfoToName() { return a -> a.getName().asInternalName(); } - private SideEffect1 captureStandardOutIfVerbose() { + private Consumer captureStandardOutIfVerbose() { if (this.coverageOptions.isVerbose()) { return log(); } else { @@ -162,23 +162,23 @@ private SideEffect1 captureStandardOutIfVerbose() { } } - private static SideEffect1 logInfo() { + private static Consumer logInfo() { return a -> LOG.info("MINION : " + a); } - private static SideEffect1 log() { + private static Consumer log() { return a -> LOG.fine("MINION : " + a); } - private SideEffect1 resultProcessor( + private Consumer resultProcessor( final CoverageData coverage) { - return new SideEffect1() { + return new Consumer() { 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); } diff --git a/pitest-entry/src/main/java/org/pitest/coverage/execute/Receive.java b/pitest-entry/src/main/java/org/pitest/coverage/execute/Receive.java index e836d25dc..28c32aee6 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/execute/Receive.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/execute/Receive.java @@ -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; @@ -24,9 +24,9 @@ final class Receive implements ReceiveStrategy { private final Map classIdToName = new ConcurrentHashMap<>(); private final Map probeToBlock = new ConcurrentHashMap<>(); - private final SideEffect1 handler; + private final Consumer handler; - Receive(final SideEffect1 handler) { + Receive(final Consumer handler) { this.handler = handler; } @@ -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, diff --git a/pitest-entry/src/main/java/org/pitest/coverage/execute/SendData.java b/pitest-entry/src/main/java/org/pitest/coverage/execute/SendData.java index 7c6fc12f4..86ad7cfbd 100644 --- a/pitest-entry/src/main/java/org/pitest/coverage/execute/SendData.java +++ b/pitest-entry/src/main/java/org/pitest/coverage/execute/SendData.java @@ -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 { +final class SendData implements Consumer { private static final Logger LOG = Log.getLogger(); private final CoverageOptions arguments; private final List testClasses; @@ -18,7 +18,7 @@ final class SendData implements SideEffect1 { } @Override - public void apply(final SafeDataOutputStream dos) { + public void accept(final SafeDataOutputStream dos) { sendArguments(dos); sendTests(dos); } diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/build/WorkerFactory.java b/pitest-entry/src/main/java/org/pitest/mutationtest/build/WorkerFactory.java index bc3eed399..df2fa9a88 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/build/WorkerFactory.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/build/WorkerFactory.java @@ -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; @@ -66,7 +66,7 @@ public MutationTestProcess createWorker( return worker; } - private SideEffect1 captureStdOutIfVerbose() { + private Consumer captureStdOutIfVerbose() { if (this.verbose) { return Prelude.printWith("stdout "); } else { diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/config/SettingsFactory.java b/pitest-entry/src/main/java/org/pitest/mutationtest/config/SettingsFactory.java index 5c8177f77..74be34ecc 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/config/SettingsFactory.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/config/SettingsFactory.java @@ -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; @@ -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; @@ -85,7 +85,7 @@ public MutationGrouperFactory getMutationGrouper() { return firstOrDefault(groupers, new DefaultMutationGrouperFactory()); } - public void describeFeatures(SideEffect1 enabled, SideEffect1 disabled) { + public void describeFeatures(Consumer enabled, Consumer disabled) { final FeatureParser parser = new FeatureParser(); final Collection available = new ArrayList<>(this.plugins.findInterceptors()); final List settings = parser.parseFeatures(this.options.getFeatures()); @@ -97,14 +97,14 @@ public void describeFeatures(SideEffect1 enabled, SideEffect1 .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); } diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/execute/MutationTestCommunicationThread.java b/pitest-entry/src/main/java/org/pitest/mutationtest/execute/MutationTestCommunicationThread.java index 339099989..9fa078b0c 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/execute/MutationTestCommunicationThread.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/execute/MutationTestCommunicationThread.java @@ -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; @@ -33,7 +33,7 @@ public class MutationTestCommunicationThread extends CommunicationThread { private static final Logger LOG = Log.getLogger(); - private static class SendData implements SideEffect1 { + private static class SendData implements Consumer { private final MinionArguments arguments; SendData(final MinionArguments arguments) { @@ -41,7 +41,7 @@ private static class SendData implements SideEffect1 { } @Override - public void apply(final SafeDataOutputStream dos) { + public void accept(final SafeDataOutputStream dos) { dos.write(this.arguments); dos.flush(); } diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsPrecursor.java b/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsPrecursor.java index c5f079832..e5ebac737 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsPrecursor.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/statistics/MutationStatisticsPrecursor.java @@ -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 { @@ -18,7 +18,7 @@ public void registerResults(final Collection results) { FCollection.forEach(results, register()); } - private SideEffect1 register() { + private Consumer register() { return mr -> { MutationStatisticsPrecursor.this.numberOfTestsRun = MutationStatisticsPrecursor.this.numberOfTestsRun + mr.getNumberOfTestsRun(); diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/EntryPoint.java b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/EntryPoint.java index 79a8c3643..fce5e7f31 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/EntryPoint.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/tooling/EntryPoint.java @@ -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; @@ -153,7 +154,7 @@ private boolean junit5PluginIsOnClasspath() { } } - private SideEffect1 asInfo(final String leader) { + private Consumer asInfo(final String leader) { return a -> { Log.getLogger().info(String.format("%1$-16s",leader + a.name()) + a.description()); for (final FeatureParameter each : a.params()) { diff --git a/pitest-entry/src/main/java/org/pitest/mutationtest/verify/DefaultBuildVerifier.java b/pitest-entry/src/main/java/org/pitest/mutationtest/verify/DefaultBuildVerifier.java index bacb101ac..9e4b55c0c 100644 --- a/pitest-entry/src/main/java/org/pitest/mutationtest/verify/DefaultBuildVerifier.java +++ b/pitest-entry/src/main/java/org/pitest/mutationtest/verify/DefaultBuildVerifier.java @@ -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; @@ -62,7 +62,7 @@ private static Predicate aClassWithLineNumbers() { return a -> a.getNumberOfCodeLines() != 0; } - private SideEffect1 throwErrorIfHasNoSourceFile() { + private Consumer throwErrorIfHasNoSourceFile() { return a -> { if (a.getSourceFileName() == null) { throw new PitHelpError(Help.NO_SOURCE_FILE, a.getName().asJavaName()); diff --git a/pitest-entry/src/main/java/org/pitest/process/JavaProcess.java b/pitest-entry/src/main/java/org/pitest/process/JavaProcess.java index 2ad731c5c..dbbff0049 100644 --- a/pitest-entry/src/main/java/org/pitest/process/JavaProcess.java +++ b/pitest-entry/src/main/java/org/pitest/process/JavaProcess.java @@ -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 sysoutHandler, - SideEffect1 syserrHandler) { + public JavaProcess(Process process, Consumer sysoutHandler, + Consumer syserrHandler) { this.process = process; this.out = new StreamMonitor(process.getInputStream(), sysoutHandler); diff --git a/pitest-entry/src/main/java/org/pitest/process/ProcessArgs.java b/pitest-entry/src/main/java/org/pitest/process/ProcessArgs.java index 43b77cfa6..06db34deb 100644 --- a/pitest-entry/src/main/java/org/pitest/process/ProcessArgs.java +++ b/pitest-entry/src/main/java/org/pitest/process/ProcessArgs.java @@ -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 stdout = print(String.class); - private SideEffect1 stdErr = printTo(String.class, System.err); + private Consumer stdout = print(String.class); + private Consumer stdErr = printTo(String.class, System.err); private List jvmArgs = Collections.emptyList(); private JavaAgent javaAgentFinder; private File workingDir = null; @@ -54,12 +54,12 @@ public ProcessArgs andBaseDir(final File baseDir) { return this; } - public ProcessArgs andStdout(final SideEffect1 stdout) { + public ProcessArgs andStdout(final Consumer stdout) { this.stdout = stdout; return this; } - public ProcessArgs andStderr(final SideEffect1 stderr) { + public ProcessArgs andStderr(final Consumer stderr) { this.stdErr = stderr; return this; } @@ -68,11 +68,11 @@ public String getLaunchClassPath() { return this.launchClassPath; } - public SideEffect1 getStdout() { + public Consumer getStdout() { return this.stdout; } - public SideEffect1 getStdErr() { + public Consumer getStdErr() { return this.stdErr; } @@ -84,11 +84,11 @@ public JavaAgent getJavaAgentFinder() { return this.javaAgentFinder; } - public void setStdout(final SideEffect1 stdout) { + public void setStdout(final Consumer stdout) { this.stdout = stdout; } - public void setStdErr(final SideEffect1 stdErr) { + public void setStdErr(final Consumer stdErr) { this.stdErr = stdErr; } diff --git a/pitest-entry/src/main/java/org/pitest/util/CommunicationThread.java b/pitest-entry/src/main/java/org/pitest/util/CommunicationThread.java index bffd859de..bae52dc21 100644 --- a/pitest-entry/src/main/java/org/pitest/util/CommunicationThread.java +++ b/pitest-entry/src/main/java/org/pitest/util/CommunicationThread.java @@ -18,22 +18,21 @@ import java.net.ServerSocket; import java.util.concurrent.ExecutionException; import java.util.concurrent.FutureTask; +import java.util.function.Consumer; import java.util.logging.Level; import java.util.logging.Logger; -import org.pitest.functional.SideEffect1; - public class CommunicationThread { private static final Logger LOG = Log.getLogger(); - private final SideEffect1 sendInitialData; + private final Consumer sendInitialData; private final ReceiveStrategy receive; private final ServerSocket socket; private FutureTask future; public CommunicationThread(final ServerSocket socket, - final SideEffect1 sendInitialData, + final Consumer sendInitialData, final ReceiveStrategy receive) { this.socket = socket; this.sendInitialData = sendInitialData; diff --git a/pitest-entry/src/main/java/org/pitest/util/SocketReadingCallable.java b/pitest-entry/src/main/java/org/pitest/util/SocketReadingCallable.java index 4c0d375f2..454bb833f 100644 --- a/pitest-entry/src/main/java/org/pitest/util/SocketReadingCallable.java +++ b/pitest-entry/src/main/java/org/pitest/util/SocketReadingCallable.java @@ -6,17 +6,16 @@ import java.net.ServerSocket; import java.net.Socket; import java.util.concurrent.Callable; - -import org.pitest.functional.SideEffect1; +import java.util.function.Consumer; class SocketReadingCallable implements Callable { - private final SideEffect1 sendInitialData; + private final Consumer sendInitialData; private final ReceiveStrategy receive; private final ServerSocket socket; SocketReadingCallable(final ServerSocket socket, - final SideEffect1 sendInitialData, + final Consumer sendInitialData, final ReceiveStrategy receive) { this.socket = socket; this.sendInitialData = sendInitialData; @@ -48,7 +47,7 @@ public ExitCode call() throws Exception { private void sendDataToMinion(final Socket clientSocket) throws IOException { final OutputStream os = clientSocket.getOutputStream(); final SafeDataOutputStream dos = new SafeDataOutputStream(os); - this.sendInitialData.apply(dos); + this.sendInitialData.accept(dos); } private ExitCode receiveResults(final SafeDataInputStream is) { diff --git a/pitest-entry/src/main/java/org/pitest/util/StreamMonitor.java b/pitest-entry/src/main/java/org/pitest/util/StreamMonitor.java index e81ec7823..56c740935 100644 --- a/pitest-entry/src/main/java/org/pitest/util/StreamMonitor.java +++ b/pitest-entry/src/main/java/org/pitest/util/StreamMonitor.java @@ -16,19 +16,18 @@ import java.io.IOException; import java.io.InputStream; +import java.util.function.Consumer; import java.util.logging.Logger; -import org.pitest.functional.SideEffect1; - public class StreamMonitor extends Thread implements Monitor { private static final Logger LOG = Log.getLogger(); private final byte[] buf = new byte[256]; private final InputStream in; - private final SideEffect1 inputHandler; + private final Consumer inputHandler; public StreamMonitor(final InputStream in, - final SideEffect1 inputHandler) { + final Consumer inputHandler) { super("PIT Stream Monitor"); this.in = in; this.inputHandler = inputHandler; @@ -61,7 +60,7 @@ private void readFromStream() { int i; while ((i = this.in.read(this.buf, 0, this.buf.length)) != -1) { final String output = new String(this.buf, 0, i); - this.inputHandler.apply(output); + this.inputHandler.accept(output); } } catch (final IOException e) { diff --git a/pitest-entry/src/test/java/org/pitest/coverage/execute/CoverageProcessSystemTest.java b/pitest-entry/src/test/java/org/pitest/coverage/execute/CoverageProcessSystemTest.java index d150e0490..b31a79436 100644 --- a/pitest-entry/src/test/java/org/pitest/coverage/execute/CoverageProcessSystemTest.java +++ b/pitest-entry/src/test/java/org/pitest/coverage/execute/CoverageProcessSystemTest.java @@ -15,6 +15,7 @@ import java.util.Arrays; import java.util.List; import java.util.concurrent.ExecutionException; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.stream.Collectors; @@ -26,7 +27,6 @@ import org.pitest.coverage.BlockLocation; import org.pitest.coverage.CoverageResult; import org.pitest.functional.FCollection; -import org.pitest.functional.SideEffect1; import org.pitest.mutationtest.config.TestPluginArguments; import org.pitest.mutationtest.engine.Location; import org.pitest.mutationtest.engine.MethodName; @@ -297,7 +297,7 @@ public void shouldNotCorruptedTheSystemNewLineProperty() throws Exception { @Test public void shouldFailWithExitCode() throws Exception { - final SideEffect1 noOpHandler = a -> { + final Consumer noOpHandler = a -> { }; final CoverageOptions sa = new CoverageOptions(coverOnlyTestees(), excludeTests(), TestPluginArguments.defaults(), true, -1); @@ -340,7 +340,7 @@ private List runCoverageForTest(final Class test) private void runCoverageProcess(final Class test, final List coveredClasses) throws IOException, InterruptedException { - final SideEffect1 handler = a -> coveredClasses.add(a); + final Consumer handler = a -> coveredClasses.add(a); final CoverageOptions sa = new CoverageOptions(coverOnlyTestees(), excludeTests(), TestPluginArguments.defaults(), true, -1); diff --git a/pitest-entry/src/test/java/org/pitest/coverage/execute/ReceiveTest.java b/pitest-entry/src/test/java/org/pitest/coverage/execute/ReceiveTest.java index e2c9c7712..2667fb619 100644 --- a/pitest-entry/src/test/java/org/pitest/coverage/execute/ReceiveTest.java +++ b/pitest-entry/src/test/java/org/pitest/coverage/execute/ReceiveTest.java @@ -9,19 +9,20 @@ import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.pitest.coverage.CoverageResult; -import org.pitest.functional.SideEffect1; import org.pitest.testapi.Description; import org.pitest.util.Id; import org.pitest.util.SafeDataInputStream; import sun.pitest.CodeCoverageStore; +import java.util.function.Consumer; + // does this test add any value? public class ReceiveTest { private Receive testee; - private SideEffect1 handler; + private Consumer handler; private CoverageResult result; @@ -38,7 +39,7 @@ public void setUp() { this.description = new Description("foo", "bar"); } - private SideEffect1 stubHandler() { + private Consumer stubHandler() { return a -> ReceiveTest.this.result = a; } diff --git a/pitest-entry/src/test/java/org/pitest/coverage/execute/SendDataTest.java b/pitest-entry/src/test/java/org/pitest/coverage/execute/SendDataTest.java index 52ce09958..8af6d6bf2 100644 --- a/pitest-entry/src/test/java/org/pitest/coverage/execute/SendDataTest.java +++ b/pitest-entry/src/test/java/org/pitest/coverage/execute/SendDataTest.java @@ -32,7 +32,7 @@ public void setUp() { @Test public void shouldSendArgumentsToMinion() { - this.testee.apply(this.os); + this.testee.accept(this.os); verify(this.os).write(this.arguments); } @@ -40,7 +40,7 @@ public void shouldSendArgumentsToMinion() { public void shouldSendTestClassesToMinion() { this.testClasses.add("foo"); this.testClasses.add("bar"); - this.testee.apply(this.os); + this.testee.accept(this.os); verify(this.os).writeInt(this.testClasses.size()); verify(this.os).writeString("foo"); verify(this.os).writeString("bar"); diff --git a/pitest-entry/src/test/java/org/pitest/mutationtest/config/SettingsFactoryTest.java b/pitest-entry/src/test/java/org/pitest/mutationtest/config/SettingsFactoryTest.java index 5756970f1..2153503fd 100644 --- a/pitest-entry/src/test/java/org/pitest/mutationtest/config/SettingsFactoryTest.java +++ b/pitest-entry/src/test/java/org/pitest/mutationtest/config/SettingsFactoryTest.java @@ -10,13 +10,13 @@ import java.io.File; import java.util.Arrays; import java.util.Collections; +import java.util.function.Consumer; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; import org.pitest.coverage.execute.CoverageOptions; import org.pitest.coverage.export.NullCoverageExporter; -import org.pitest.functional.SideEffect1; import org.pitest.mutationtest.engine.gregor.config.GregorEngineFactory; import org.pitest.plugin.Feature; import org.pitest.testapi.TestGroupConfig; @@ -105,26 +105,26 @@ public void shouldNotAllowUserToCalculateCoverageForCoverageImplementation() { @Test public void shouldDescribeActiveFeatures() { - final SideEffect1 disabled = Mockito.mock(SideEffect1.class); - final SideEffect1 enabled = Mockito.mock(SideEffect1.class); + final Consumer disabled = Mockito.mock(Consumer.class); + final Consumer enabled = Mockito.mock(Consumer.class); this.options.setFeatures(Arrays.asList("+FSTATINIT")); this.testee.describeFeatures(enabled, disabled); - verify(enabled).apply(Feature.named("FSTATINIT")); - verify(disabled, never()).apply(Feature.named("FSTATINIT")); + verify(enabled).accept(Feature.named("FSTATINIT")); + verify(disabled, never()).accept(Feature.named("FSTATINIT")); } @Test public void shouldDescribeDisabledFeatures() { - final SideEffect1 disabled = Mockito.mock(SideEffect1.class); - final SideEffect1 enabled = Mockito.mock(SideEffect1.class); + final Consumer disabled = Mockito.mock(Consumer.class); + final Consumer enabled = Mockito.mock(Consumer.class); this.options.setFeatures(Arrays.asList("-FSTATINIT")); this.testee.describeFeatures(enabled, disabled); - verify(enabled, never()).apply(Feature.named("FSTATINIT")); - verify(disabled).apply(Feature.named("FSTATINIT")); + verify(enabled, never()).accept(Feature.named("FSTATINIT")); + verify(disabled).accept(Feature.named("FSTATINIT")); } } diff --git a/pitest-entry/src/test/java/org/pitest/process/WrappingProcessTest.java b/pitest-entry/src/test/java/org/pitest/process/WrappingProcessTest.java index 6292502cd..6d1009974 100644 --- a/pitest-entry/src/test/java/org/pitest/process/WrappingProcessTest.java +++ b/pitest-entry/src/test/java/org/pitest/process/WrappingProcessTest.java @@ -7,10 +7,10 @@ import java.io.IOException; import java.util.Collections; import java.util.HashMap; +import java.util.function.Consumer; import org.junit.Test; import org.pitest.classpath.ClassPath; -import org.pitest.functional.SideEffect1; import org.pitest.util.NullJavaAgent; public class WrappingProcessTest { @@ -51,7 +51,7 @@ public void waitToDieShouldReturnProcessExitCode() throws IOException, assertEquals(EXIT_CODE, process.waitToDie()); } - private SideEffect1 nullHandler() { + private Consumer nullHandler() { return a -> { }; diff --git a/pitest-entry/src/test/java/org/pitest/util/SocketReadingCallableTest.java b/pitest-entry/src/test/java/org/pitest/util/SocketReadingCallableTest.java index fb8a73661..a26d0a25f 100644 --- a/pitest-entry/src/test/java/org/pitest/util/SocketReadingCallableTest.java +++ b/pitest-entry/src/test/java/org/pitest/util/SocketReadingCallableTest.java @@ -13,12 +13,12 @@ import java.io.IOException; import java.net.ServerSocket; import java.net.Socket; +import java.util.function.Consumer; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; import org.mockito.MockitoAnnotations; -import org.pitest.functional.SideEffect1; public class SocketReadingCallableTest { @@ -28,7 +28,7 @@ public class SocketReadingCallableTest { private ServerSocket socket; @Mock - private SideEffect1 sendDataSideEffect; + private Consumer sendDataSideEffect; @Mock private ReceiveStrategy receiveStrategy; @@ -59,7 +59,7 @@ public void shouldReportTheExitCodeSentByTheMinionProcess() throws Exception { public void shouldSendInitialDataToMinion() throws Exception { mockClientSocketToSendExitCode(ExitCode.TIMEOUT); this.testee.call(); - verify(this.sendDataSideEffect).apply(any(SafeDataOutputStream.class)); + verify(this.sendDataSideEffect).accept(any(SafeDataOutputStream.class)); } @Test diff --git a/pitest/src/main/java/org/pitest/dependency/DependencyClassVisitor.java b/pitest/src/main/java/org/pitest/dependency/DependencyClassVisitor.java index 82c2adaa3..02bc5cb6a 100644 --- a/pitest/src/main/java/org/pitest/dependency/DependencyClassVisitor.java +++ b/pitest/src/main/java/org/pitest/dependency/DependencyClassVisitor.java @@ -18,24 +18,25 @@ import org.objectweb.asm.MethodVisitor; import org.pitest.bytecode.ASMVersion; import org.pitest.dependency.DependencyAccess.Member; -import org.pitest.functional.SideEffect1; + +import java.util.function.Consumer; class DependencyClassVisitor extends ClassVisitor { - private final SideEffect1 typeReceiver; + private final Consumer typeReceiver; private String className; protected DependencyClassVisitor(final ClassVisitor visitor, - final SideEffect1 typeReceiver) { + final Consumer typeReceiver) { super(ASMVersion.ASM_VERSION, visitor); this.typeReceiver = filterOutJavaLangObject(typeReceiver); } - private SideEffect1 filterOutJavaLangObject( - final SideEffect1 child) { + private Consumer filterOutJavaLangObject( + final Consumer child) { return a -> { if (!a.getDest().getOwner().equals("java/lang/Object")) { - child.apply(a); + child.accept(a); } }; @@ -61,11 +62,11 @@ public MethodVisitor visitMethod(final int access, final String name, private static class DependencyAnalysisMethodVisitor extends MethodVisitor { private final Member member; - private final SideEffect1 typeReceiver; + private final Consumer typeReceiver; DependencyAnalysisMethodVisitor(final Member member, final MethodVisitor methodVisitor, - final SideEffect1 typeReceiver) { + final Consumer typeReceiver) { super(ASMVersion.ASM_VERSION, methodVisitor); this.typeReceiver = typeReceiver; this.member = member; @@ -74,7 +75,7 @@ private static class DependencyAnalysisMethodVisitor extends MethodVisitor { @Override public void visitMethodInsn(final int opcode, final String owner, final String name, final String desc, boolean itf) { - this.typeReceiver.apply(new DependencyAccess(this.member, new Member( + this.typeReceiver.accept(new DependencyAccess(this.member, new Member( owner, name))); this.mv.visitMethodInsn(opcode, owner, name, desc, itf); } @@ -82,7 +83,7 @@ public void visitMethodInsn(final int opcode, final String owner, @Override public void visitFieldInsn(final int opcode, final String owner, final String name, final String desc) { - this.typeReceiver.apply(new DependencyAccess(this.member, new Member( + this.typeReceiver.accept(new DependencyAccess(this.member, new Member( owner, name))); this.mv.visitFieldInsn(opcode, owner, name, desc); } diff --git a/pitest/src/main/java/org/pitest/dependency/DependencyExtractor.java b/pitest/src/main/java/org/pitest/dependency/DependencyExtractor.java index eb60816c4..6c285623f 100644 --- a/pitest/src/main/java/org/pitest/dependency/DependencyExtractor.java +++ b/pitest/src/main/java/org/pitest/dependency/DependencyExtractor.java @@ -28,6 +28,7 @@ import java.util.Set; import java.util.TreeSet; import java.util.function.BiFunction; +import java.util.function.Consumer; import java.util.function.Predicate; import java.util.logging.Logger; @@ -36,7 +37,6 @@ import org.pitest.classinfo.ClassByteArraySource; import org.pitest.functional.FCollection; import java.util.Optional; -import org.pitest.functional.SideEffect1; import org.pitest.util.Functions; import org.pitest.util.Log; @@ -147,7 +147,7 @@ private List extract(final String clazz, final ClassReader reader = new ClassReader(bytes.get()); final List dependencies = new ArrayList<>(); - final SideEffect1 se = constructCollectingSideEffectForVisitor( + final Consumer se = constructCollectingSideEffectForVisitor( dependencies, and(nameIsEqual(clazz).negate(), filter)); final DependencyClassVisitor dcv = new DependencyClassVisitor( new NullVisitor(), se); @@ -188,10 +188,10 @@ private static Predicate nameIsEqual(final String clazz) { return a -> a.getDest().getOwner().equals(clazz); } - private static SideEffect1 constructCollectingSideEffectForVisitor( + private static Consumer constructCollectingSideEffectForVisitor( final List dependencies, final Predicate predicate) { - final SideEffect1 se = a -> { + final Consumer se = a -> { if (predicate.test(a)) { dependencies.add(a); } diff --git a/pitest/src/main/java/org/pitest/functional/FCollection.java b/pitest/src/main/java/org/pitest/functional/FCollection.java index 4ccddbe4d..cbfdd74f9 100644 --- a/pitest/src/main/java/org/pitest/functional/FCollection.java +++ b/pitest/src/main/java/org/pitest/functional/FCollection.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.Map; import java.util.function.BiFunction; +import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; @@ -29,10 +30,8 @@ public abstract class FCollection { public static void forEach(final Iterable as, - final SideEffect1 e) { - for (final A a : as) { - e.apply(a); - } + final Consumer e) { + as.forEach(e); } public static void mapTo(final Iterable as, diff --git a/pitest/src/main/java/org/pitest/functional/SideEffect1.java b/pitest/src/main/java/org/pitest/functional/SideEffect1.java deleted file mode 100644 index 88f47efe5..000000000 --- a/pitest/src/main/java/org/pitest/functional/SideEffect1.java +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright 2010 Henry Coles - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - */ -package org.pitest.functional; - -public interface SideEffect1 { - - void apply(A a); - -} diff --git a/pitest/src/main/java/org/pitest/functional/SideEffect2.java b/pitest/src/main/java/org/pitest/functional/SideEffect2.java deleted file mode 100644 index 8d6287b36..000000000 --- a/pitest/src/main/java/org/pitest/functional/SideEffect2.java +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2010 Henry Coles - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and limitations under the License. - */ -package org.pitest.functional; - -/** - * @author henry - * - */ -public interface SideEffect2 { - - void apply(A a, B b); - -} diff --git a/pitest/src/main/java/org/pitest/functional/prelude/Prelude.java b/pitest/src/main/java/org/pitest/functional/prelude/Prelude.java index 85393e1a3..bbb7a8c6b 100644 --- a/pitest/src/main/java/org/pitest/functional/prelude/Prelude.java +++ b/pitest/src/main/java/org/pitest/functional/prelude/Prelude.java @@ -19,10 +19,10 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; +import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; -import org.pitest.functional.SideEffect1; import org.pitest.functional.predicate.And; import org.pitest.functional.predicate.Or; @@ -54,13 +54,13 @@ public static final Or or(final Iterable> ps) { return new Or<>(ps); } - public static final SideEffect1 accumulateTo( + public static final Consumer accumulateTo( final Collection collection) { return a -> collection.add(a); } - public static SideEffect1 putToMap(final Map map, + public static Consumer putToMap(final Map map, final B value) { return key -> map.put(key, value); } @@ -73,24 +73,24 @@ public static final Function id(final Class type) { return id(); } - public static final SideEffect1 print() { + public static final Consumer print() { return printTo(System.out); } - public static final SideEffect1 print(final Class type) { + public static final Consumer print(final Class type) { return print(); } - public static final SideEffect1 printTo(final Class type, + public static final Consumer printTo(final Class type, final PrintStream stream) { return printTo(stream); } - public static final SideEffect1 printTo(final PrintStream stream) { + public static final Consumer printTo(final PrintStream stream) { return a -> stream.print(a); } - public static SideEffect1 printWith(final T t) { + public static Consumer printWith(final T t) { return a -> System.out.print(t + " : " + a); } @@ -114,7 +114,7 @@ public static Function> asList(final Class type) { return a -> Collections.singletonList(a); } - public static SideEffect1 noSideEffect(final Class clazz) { + public static Consumer noSideEffect(final Class clazz) { return a -> { }; } diff --git a/pitest/src/main/java/org/pitest/testapi/execute/Pitest.java b/pitest/src/main/java/org/pitest/testapi/execute/Pitest.java index a84368fc6..6d2b2e6d4 100644 --- a/pitest/src/main/java/org/pitest/testapi/execute/Pitest.java +++ b/pitest/src/main/java/org/pitest/testapi/execute/Pitest.java @@ -76,7 +76,7 @@ private void run(final Container container, final Configuration config, private void processResults(final List results) { for (final TestResult result : results) { final ResultType classifiedResult = classify(result); - classifiedResult.getListenerFunction(result).apply(this.listener); + classifiedResult.getListenerFunction(result).accept(this.listener); } } diff --git a/pitest/src/main/java/org/pitest/testapi/execute/ResultType.java b/pitest/src/main/java/org/pitest/testapi/execute/ResultType.java index d74459a6a..c69da7a8f 100644 --- a/pitest/src/main/java/org/pitest/testapi/execute/ResultType.java +++ b/pitest/src/main/java/org/pitest/testapi/execute/ResultType.java @@ -14,9 +14,9 @@ */ package org.pitest.testapi.execute; +import java.util.function.Consumer; import java.util.function.Function; -import org.pitest.functional.SideEffect1; import org.pitest.testapi.TestListener; import org.pitest.testapi.TestResult; @@ -35,32 +35,32 @@ public enum ResultType { STARTED(a -> started(a)); private interface ResultToListenerSideEffect extends - Function> { + Function> { }; ResultType(final ResultToListenerSideEffect f) { this.function = f; } - private final Function> function; + private final Function> function; - public SideEffect1 getListenerFunction(final TestResult result) { + public Consumer getListenerFunction(final TestResult result) { return this.function.apply(result); }; - public static SideEffect1 success(final TestResult result) { + public static Consumer success(final TestResult result) { return a -> a.onTestSuccess(result); } - public static SideEffect1 failure(final TestResult result) { + public static Consumer failure(final TestResult result) { return a -> a.onTestFailure(result); } - public static SideEffect1 skipped(final TestResult result) { + public static Consumer skipped(final TestResult result) { return a -> a.onTestSkipped(result); } - public static SideEffect1 started(final TestResult result) { + public static Consumer started(final TestResult result) { return a -> a.onTestStart(result.getDescription()); } diff --git a/pitest/src/test/java/org/pitest/dependency/DependencyClassVisitorTest.java b/pitest/src/test/java/org/pitest/dependency/DependencyClassVisitorTest.java index d8630fb33..5d22f64f4 100644 --- a/pitest/src/test/java/org/pitest/dependency/DependencyClassVisitorTest.java +++ b/pitest/src/test/java/org/pitest/dependency/DependencyClassVisitorTest.java @@ -21,6 +21,7 @@ import java.util.Arrays; import java.util.HashSet; import java.util.Set; +import java.util.function.Consumer; import java.util.function.Function; import org.junit.Before; @@ -30,7 +31,6 @@ import org.pitest.classpath.ClassPath; import org.pitest.dependency.DependencyAccess.Member; import org.pitest.functional.FCollection; -import org.pitest.functional.SideEffect1; public class DependencyClassVisitorTest { @@ -41,7 +41,7 @@ public class DependencyClassVisitorTest { @Before public void setUp() { - final SideEffect1 se = a -> { + final Consumer se = a -> { DependencyClassVisitorTest.this.gatheredAccess.add(a); DependencyClassVisitorTest.this.gatheredDependencies.add(a.getDest() .getOwner()); diff --git a/pitest/src/test/java/org/pitest/functional/FCollectionTest.java b/pitest/src/test/java/org/pitest/functional/FCollectionTest.java index 5cdcb8160..60358b041 100644 --- a/pitest/src/test/java/org/pitest/functional/FCollectionTest.java +++ b/pitest/src/test/java/org/pitest/functional/FCollectionTest.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Map; import java.util.function.BiFunction; +import java.util.function.Consumer; import java.util.function.Function; import java.util.function.Predicate; @@ -57,7 +58,7 @@ public void shouldReturnOnlyMatchesToPredicate() { @Test public void shouldApplyForEachToAllItems() { final List actual = new ArrayList<>(); - final SideEffect1 e = a -> actual.add(a); + final Consumer e = a -> actual.add(a); FCollection.forEach(this.is, e); diff --git a/pitest/src/test/java/org/pitest/functional/prelude/PreludeTest.java b/pitest/src/test/java/org/pitest/functional/prelude/PreludeTest.java index 7d826e40f..bc2971e60 100644 --- a/pitest/src/test/java/org/pitest/functional/prelude/PreludeTest.java +++ b/pitest/src/test/java/org/pitest/functional/prelude/PreludeTest.java @@ -49,7 +49,7 @@ public void isNotNullShouldReturnTrueWhenNotNull() { public void printToShouldPrintValueToStream() { final Integer i = Integer.valueOf(42); final PrintStream stream = Mockito.mock(PrintStream.class); - Prelude.printTo(stream).apply(i); + Prelude.printTo(stream).accept(i); verify(stream).print(i); } diff --git a/pitest/src/test/java/org/pitest/testapi/execute/ResultTypeTest.java b/pitest/src/test/java/org/pitest/testapi/execute/ResultTypeTest.java index 1108b13d4..33ed1a1f3 100644 --- a/pitest/src/test/java/org/pitest/testapi/execute/ResultTypeTest.java +++ b/pitest/src/test/java/org/pitest/testapi/execute/ResultTypeTest.java @@ -61,6 +61,6 @@ public void shouldCallOnTestStartOnListenerWhenTypeIsStarted() { } private void callListenerFunction(final ResultType testee) { - testee.getListenerFunction(this.result).apply(this.listener); + testee.getListenerFunction(this.result).accept(this.listener); } }