diff --git a/pitest-entry/src/test/java/com/example/systemtest/EatsMemoryWhenMutated.java b/pitest-entry/src/test/java/com/example/systemtest/EatsMemoryWhenMutated.java new file mode 100644 index 000000000..a25189bdf --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/EatsMemoryWhenMutated.java @@ -0,0 +1,21 @@ +package com.example.systemtest; + +import java.util.ArrayList; +import java.util.List; + +public class EatsMemoryWhenMutated { + public static int loop() throws InterruptedException { + int i = 1; + final List vals = new ArrayList<>(); + Thread.sleep(1500); + do { + i++; + vals.add(new String[9999999]); + vals.add(new String[9999999]); + vals.add(new String[9999999]); + vals.add(new String[9999999]); + } while (i < 1); + i++; + return i; + } +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/FailingTest.java b/pitest-entry/src/test/java/com/example/systemtest/FailingTest.java new file mode 100644 index 000000000..20b35f5c1 --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/FailingTest.java @@ -0,0 +1,12 @@ +package com.example.systemtest; + +import org.pitest.simpletest.TestAnnotationForTesting; + +import static org.junit.Assert.assertEquals; + +public class FailingTest { + @TestAnnotationForTesting + public void fail() { + assertEquals(1, 2); + } +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/InfiniteLoop.java b/pitest-entry/src/test/java/com/example/systemtest/InfiniteLoop.java new file mode 100644 index 000000000..051082d18 --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/InfiniteLoop.java @@ -0,0 +1,17 @@ +package com.example.systemtest; + +public class InfiniteLoop { + public static int loop() { + int i = 1; + do { + i++; + try { + Thread.sleep(1); + } catch (final InterruptedException e) { + e.printStackTrace(); + } + } while (i < 1); + i++; + return i; + } +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/NoMutations.java b/pitest-entry/src/test/java/com/example/systemtest/NoMutations.java new file mode 100644 index 000000000..8390b924b --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/NoMutations.java @@ -0,0 +1,5 @@ +package com.example.systemtest; + +public class NoMutations { + +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/NoMutationsTest.java b/pitest-entry/src/test/java/com/example/systemtest/NoMutationsTest.java new file mode 100644 index 000000000..4546312f2 --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/NoMutationsTest.java @@ -0,0 +1,10 @@ +package com.example.systemtest; + +import org.pitest.simpletest.TestAnnotationForTesting; + +public class NoMutationsTest { + @TestAnnotationForTesting + public void pass() { + + } +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/NoTests.java b/pitest-entry/src/test/java/com/example/systemtest/NoTests.java new file mode 100644 index 000000000..4837cd972 --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/NoTests.java @@ -0,0 +1,5 @@ +package com.example.systemtest; + +public class NoTests { + +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/OneMutationFullTest.java b/pitest-entry/src/test/java/com/example/systemtest/OneMutationFullTest.java new file mode 100644 index 000000000..d45afdf9d --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/OneMutationFullTest.java @@ -0,0 +1,12 @@ +package com.example.systemtest; + +import org.pitest.simpletest.TestAnnotationForTesting; + +import static org.junit.Assert.assertEquals; + +public class OneMutationFullTest { + @TestAnnotationForTesting + public void testReturnOne() { + assertEquals(1, OneMutationOnly.returnOne()); + } +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/OneMutationFullTestWithSystemPropertyDependency.java b/pitest-entry/src/test/java/com/example/systemtest/OneMutationFullTestWithSystemPropertyDependency.java new file mode 100644 index 000000000..c85271b21 --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/OneMutationFullTestWithSystemPropertyDependency.java @@ -0,0 +1,14 @@ +package com.example.systemtest; + +import org.pitest.simpletest.TestAnnotationForTesting; + +import static org.junit.Assert.assertEquals; + +public class OneMutationFullTestWithSystemPropertyDependency { + @TestAnnotationForTesting + public void testReturnOne() { + if (System.getProperty("foo").equals("foo")) { + assertEquals(1, OneMutationOnly.returnOne()); + } + } +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/OneMutationOnly.java b/pitest-entry/src/test/java/com/example/systemtest/OneMutationOnly.java new file mode 100644 index 000000000..e7738b8a3 --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/OneMutationOnly.java @@ -0,0 +1,7 @@ +package com.example.systemtest; + +public class OneMutationOnly { + public static int returnOne() { + return 1; + } +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/OneMutationTest.java b/pitest-entry/src/test/java/com/example/systemtest/OneMutationTest.java new file mode 100644 index 000000000..20b31f3f6 --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/OneMutationTest.java @@ -0,0 +1,5 @@ +package com.example.systemtest; + +public class OneMutationTest { + +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/ThreeMutations.java b/pitest-entry/src/test/java/com/example/systemtest/ThreeMutations.java new file mode 100644 index 000000000..fcbcdade0 --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/ThreeMutations.java @@ -0,0 +1,15 @@ +package com.example.systemtest; + +public class ThreeMutations { + public static int returnOne() { + return 1; + } + + public static int returnTwo() { + return 2; + } + + public static int returnThree() { + return 3; + } +} diff --git a/pitest-entry/src/test/java/com/example/systemtest/ThreeMutationsTwoMeaningfullTests.java b/pitest-entry/src/test/java/com/example/systemtest/ThreeMutationsTwoMeaningfullTests.java new file mode 100644 index 000000000..9bc992761 --- /dev/null +++ b/pitest-entry/src/test/java/com/example/systemtest/ThreeMutationsTwoMeaningfullTests.java @@ -0,0 +1,22 @@ +package com.example.systemtest; + +import org.pitest.simpletest.TestAnnotationForTesting; + +import static org.junit.Assert.assertEquals; + +public class ThreeMutationsTwoMeaningfullTests { + @TestAnnotationForTesting + public void testReturnOne() { + assertEquals(1, ThreeMutations.returnOne()); + } + + @TestAnnotationForTesting + public void testReturnTwo() { + assertEquals(2, ThreeMutations.returnTwo()); + } + + @TestAnnotationForTesting + public void coverButDoNotTestReturnThree() { + ThreeMutations.returnThree(); + } +} 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 918e58f96..ff080c54c 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 @@ -62,7 +62,7 @@ public void shouldRecordSomeCoverage() throws Exception { // check all the specialised implementations broadly work @Test public void shouldCalculateCoverageForSingleBlockMethods() - throws IOException, InterruptedException, ExecutionException { + throws IOException, InterruptedException { final List coveredClasses = runCoverageForTest(TestsForMultiBlockCoverage.class); assertCoverage(coveredClasses, "test1", 1); } @@ -74,8 +74,7 @@ public void shouldCalculateCoverageFor3BlockMethods() throws Exception { } @Test - public void shouldCalculateCoverageForConstructors() throws IOException, - InterruptedException, ExecutionException { + public void shouldCalculateCoverageForConstructors() throws Exception { final List coveredClasses = runCoverageForTest(TesteeWithComplexConstructorsTest.class); assertTrue(coversBlock(coveredClasses, "testHigh", 0)); assertTrue(coversBlock(coveredClasses, "testHigh", 1)); @@ -88,22 +87,19 @@ public void shouldCalculateCoverageForConstructors() throws IOException, } @Test - public void shouldCalculateCoverageFor4BlockMethods() throws IOException, - InterruptedException, ExecutionException { + public void shouldCalculateCoverageFor4BlockMethods() throws Exception { final List coveredClasses = runCoverageForTest(TestsForMultiBlockCoverage.class); assertCoverage(coveredClasses, "test4", 2); } @Test - public void shouldCalculateCoverageFor5BlockMethods() throws IOException, - InterruptedException, ExecutionException { + public void shouldCalculateCoverageFor5BlockMethods() throws Exception { final List coveredClasses = runCoverageForTest(TestsForMultiBlockCoverage.class); assertCoverage(coveredClasses, "test5", 2); } @Test - public void shouldCalculateCoverageForBlockMethods() throws IOException, - InterruptedException, ExecutionException { + public void shouldCalculateCoverageForBlockMethods() throws Exception { final List coveredClasses = runCoverageForTest(TestsForMultiBlockCoverage.class); assertCoverage(coveredClasses, "test6", 2); } @@ -171,7 +167,7 @@ public void shouldCalculateCoverageForLargeBlockMethods() throws Exception { @Test public void shouldCalculateCoverageForAllRelevantClasses() - throws Exception{ + throws Exception { final List coveredClasses = runCoverageForTest(Tests.class); @@ -215,7 +211,7 @@ public void shouldCalculateCoverageForMethodThatThrowsExceptionWithFinallyBlock( @Test public void shouldCalculateCoverageForLargeMethodThatThrowsException() - throws IOException, InterruptedException { + throws Exception { final List coveredClasses = runCoverageForTest(TestThrowsExceptionFromLargeMethodTestee.class); final ClassName clazz = ClassName diff --git a/pitest-entry/src/test/java/org/pitest/mutationtest/TestMutationTesting.java b/pitest-entry/src/test/java/org/pitest/mutationtest/TestMutationTesting.java index 3ea209cb7..7646eb5f9 100644 --- a/pitest-entry/src/test/java/org/pitest/mutationtest/TestMutationTesting.java +++ b/pitest-entry/src/test/java/org/pitest/mutationtest/TestMutationTesting.java @@ -23,7 +23,6 @@ import static org.pitest.mutationtest.DetectionStatus.SURVIVED; import static org.pitest.mutationtest.DetectionStatus.TIMED_OUT; -import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; @@ -32,6 +31,16 @@ import java.util.Set; import java.util.function.Predicate; +import com.example.systemtest.EatsMemoryWhenMutated; +import com.example.systemtest.InfiniteLoop; +import com.example.systemtest.NoMutations; +import com.example.systemtest.NoMutationsTest; +import com.example.systemtest.NoTests; +import com.example.systemtest.OneMutationFullTest; +import com.example.systemtest.OneMutationFullTestWithSystemPropertyDependency; +import com.example.systemtest.OneMutationOnly; +import com.example.systemtest.ThreeMutations; +import com.example.systemtest.ThreeMutationsTwoMeaningfullTests; import org.junit.Before; import org.junit.Ignore; import org.junit.Test; @@ -97,37 +106,6 @@ public void setUp() { . singletonList(this.metaDataExtractor)); } - public static class NoMutations { - - } - - public static class OneMutationOnly { - public static int returnOne() { - return 1; - } - } - - public static class ThreeMutations { - public static int returnOne() { - return 1; - } - - public static int returnTwo() { - return 2; - } - - public static int returnThree() { - return 3; - } - } - - public static class OneMutationFullTest { - @TestAnnotationForTesting - public void testReturnOne() { - assertEquals(1, OneMutationOnly.returnOne()); - } - } - @Test public void shouldKillAllCoveredMutations() { run(OneMutationOnly.class, OneMutationFullTest.class, @@ -135,23 +113,6 @@ public void shouldKillAllCoveredMutations() { verifyResults(KILLED); } - public static class ThreeMutationsTwoMeaningfullTests { - @TestAnnotationForTesting - public void testReturnOne() { - assertEquals(1, ThreeMutations.returnOne()); - } - - @TestAnnotationForTesting - public void testReturnTwo() { - assertEquals(2, ThreeMutations.returnTwo()); - } - - @TestAnnotationForTesting - public void coverButDoNotTestReturnThree() { - ThreeMutations.returnThree(); - } - } - @Test public void shouldDetectedMixOfSurvivingAndKilledMutations() { run(ThreeMutations.class, ThreeMutationsTwoMeaningfullTests.class, @@ -159,56 +120,18 @@ public void shouldDetectedMixOfSurvivingAndKilledMutations() { verifyResults(SURVIVED, KILLED, KILLED); } - public static class FailingTest { - @TestAnnotationForTesting - public void fail() { - assertEquals(1, 2); - } - } - - public static class NoMutationsTest { - @TestAnnotationForTesting - public void pass() { - - } - } - @Test public void shouldReportNoResultsIfNoMutationsPossible() { run(NoMutations.class, NoMutationsTest.class, "RETURN_VALS"); verifyResults(); } - public static class NoTests { - - } - @Test public void shouldReportStatusOfNoCoverageWhenNoTestsAvailable() { run(ThreeMutations.class, NoTests.class, "RETURN_VALS"); verifyResults(NO_COVERAGE, NO_COVERAGE, NO_COVERAGE); } - public static class OneMutationTest { - - } - - public static class InfiniteLoop { - public static int loop() { - int i = 1; - do { - i++; - try { - Thread.sleep(1); - } catch (final InterruptedException e) { - e.printStackTrace(); - } - } while (i < 1); - i++; - return i; - } - } - public static class InfiniteLoopTest { @TestAnnotationForTesting() public void pass() { @@ -223,15 +146,6 @@ public void shouldDetectAndEscapeFromInfiniteLoopsCausedByMutations() { verifyResults(KILLED, TIMED_OUT); } - public static class OneMutationFullTestWithSystemPropertyDependency { - @TestAnnotationForTesting - public void testReturnOne() { - if (System.getProperty("foo").equals("foo")) { - assertEquals(1, OneMutationOnly.returnOne()); - } - } - } - @Test public void shouldExportSystemPropertiesToMinionProcess() { // System.setProperty("foo", "foo"); @@ -259,23 +173,6 @@ public void shouldDetectUnviableMutations() { } - public static class EatsMemoryWhenMutated { - public static int loop() throws InterruptedException { - int i = 1; - final List vals = new ArrayList<>(); - Thread.sleep(1500); - do { - i++; - vals.add(new String[9999999]); - vals.add(new String[9999999]); - vals.add(new String[9999999]); - vals.add(new String[9999999]); - } while (i < 1); - i++; - return i; - } - } - public static class EatsMemoryTest { @TestAnnotationForTesting() public void pass() throws InterruptedException { 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 303c071e1..b4cff87b7 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 @@ -91,9 +91,9 @@ public void shouldReturnSpecifiedJavaExecutableWhenOneSet() { @Test public void shouldNotAllowUserToCalculateCoverageForCoreClasses() { this.options.setTargetClasses(Collections - .singleton("java/Integer")); + .singleton("java.Integer")); final CoverageOptions actual = this.testee.createCoverageOptions(); - assertFalse(actual.getFilter().test("java/Integer")); + assertFalse(actual.getFilter().test("java.Integer")); } @Test diff --git a/pitest/src/main/java/org/pitest/coverage/execute/CoverageOptions.java b/pitest/src/main/java/org/pitest/coverage/execute/CoverageOptions.java index 65cccc47f..b6e315b6c 100644 --- a/pitest/src/main/java/org/pitest/coverage/execute/CoverageOptions.java +++ b/pitest/src/main/java/org/pitest/coverage/execute/CoverageOptions.java @@ -67,13 +67,15 @@ public int getDependencyAnalysisMaxDistance() { private static Predicate commonClasses() { return Prelude.or( - glob("java/*"), - glob("sun/*"), - glob("org/pitest/coverage/*"), - glob("org/pitest/reloc/*"), - glob("org/pitest/boot/*")); + glob("org.pitest.*"), + glob("java.*"), + glob("javax.*"), + glob("com.sun*"), + glob("org.junit*"), + glob("sun.*")); } + private static Glob glob(String match) { return new Glob(match); } diff --git a/pitest/src/test/java/org/pitest/coverage/execute/CoverageOptionsTest.java b/pitest/src/test/java/org/pitest/coverage/execute/CoverageOptionsTest.java index 197f6cdef..0c994d5f0 100644 --- a/pitest/src/test/java/org/pitest/coverage/execute/CoverageOptionsTest.java +++ b/pitest/src/test/java/org/pitest/coverage/execute/CoverageOptionsTest.java @@ -16,47 +16,47 @@ public class CoverageOptionsTest { @Test public void shouldIncludeTargettedClasses() { - this.testee = new CoverageOptions(Collections.singletonList("com/example/*"), Collections.emptyList(), this.pitConfig, DEFAULT, 0); + this.testee = new CoverageOptions(Collections.singletonList("com.example.*"), Collections.emptyList(), this.pitConfig, DEFAULT, 0); - assertThat(this.testee.getFilter().test("com/example/Foo")).isTrue(); + assertThat(this.testee.getFilter().test("com.example.Foo")).isTrue(); } @Test public void shouldExcludeExcludedClasses() { - this.testee = new CoverageOptions(Collections.singletonList("com/example/*"), Collections.singletonList("com/example/NotMe"), this.pitConfig, DEFAULT, 0); + this.testee = new CoverageOptions(Collections.singletonList("com.example.*"), Collections.singletonList("com.example.NotMe"), this.pitConfig, DEFAULT, 0); - assertThat(this.testee.getFilter().test("com/example/Foo")).isTrue(); - assertThat(this.testee.getFilter().test("com/example/NotMe")).isFalse(); + assertThat(this.testee.getFilter().test("com.example.Foo")).isTrue(); + assertThat(this.testee.getFilter().test("com.example.NotMe")).isFalse(); } @Test public void shouldNotCoverJDKClassesWhenFilterIsBroad() { - assertThat(this.testee.getFilter().test("java/lang/Integer")).isFalse(); + assertThat(this.testee.getFilter().test("java.lang.Integer")).isFalse(); } @Test public void shouldNotCoverSunClassesWhenFilterIsBroad() { - assertThat(this.testee.getFilter().test("sun/foo/Bar")).isFalse(); + assertThat(this.testee.getFilter().test("sun.foo.Bar")).isFalse(); } @Test public void shouldNotCoverJUnitWhenFilterIsBroad() { - assertThat(this.testee.getFilter().test("sun/foo/Bar")).isFalse(); + assertThat(this.testee.getFilter().test("sun.foo.Bar")).isFalse(); } @Test public void shouldNotCoverPitestBootWhenFilterIsBroad() { - assertThat(this.testee.getFilter().test("org/pitest/boot/HotSwapAgent")).isFalse(); + assertThat(this.testee.getFilter().test("org.pitest.boot.HotSwapAgent")).isFalse(); } @Test public void shouldNotCoverPitestCoverageWhenFilterIsBroad() { - assertThat(this.testee.getFilter().test("org/pitest/coverage/execute/Minion")).isFalse(); + assertThat(this.testee.getFilter().test("org.pitest.coverage.execute.Minion")).isFalse(); } @Test public void shouldNotCoverPitestRelocWhenFilterIsBroad() { - assertThat(this.testee.getFilter().test("org/pitest/reloc/Foo")).isFalse(); + assertThat(this.testee.getFilter().test("org.pitest.reloc.Foo")).isFalse(); } }