org.pitest.mutationtest.engine.MutationDetails Java Examples
The following examples show how to use
org.pitest.mutationtest.engine.MutationDetails.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MutationTestUnit.java From pitest with Apache License 2.0 | 6 votes |
private static void correctResultForProcessExitCode( final MutationStatusMap mutations, final ExitCode exitCode) { if (!exitCode.isOk()) { final Collection<MutationDetails> unfinishedRuns = mutations .getUnfinishedRuns(); final DetectionStatus status = DetectionStatus .getForErrorExitCode(exitCode); LOG.warning("Minion exited abnormally due to " + status); LOG.fine("Setting " + unfinishedRuns.size() + " unfinished runs to " + status + " state"); mutations.setStatusForMutations(unfinishedRuns, status); } else { LOG.fine("Minion exited ok"); } }
Example #2
Source File: StaticInitializerInterceptor.java From pitest with Apache License 2.0 | 6 votes |
private void analyseClass(ClassTree tree) { final Optional<MethodTree> clinit = tree.methods().stream().filter(nameEquals(CLINIT.name())).findFirst(); if (clinit.isPresent()) { final List<Predicate<MethodTree>> selfCalls = clinit.get().instructions().stream() .flatMap(is(MethodInsnNode.class)) .filter(calls(tree.name())) .map(toPredicate()) .collect(Collectors.toList()); final Predicate<MethodTree> matchingCalls = Prelude.or(selfCalls); final Predicate<MutationDetails> initOnlyMethods = Prelude.or(tree.methods().stream() .filter(isPrivateStatic()) .filter(matchingCalls) .map(AnalysisFunctions.matchMutationsInMethod()) .collect(Collectors.toList()) ); this.isStaticInitCode = Prelude.or(isInStaticInitializer(), initOnlyMethods); } }
Example #3
Source File: GregorMutater.java From pitest with Apache License 2.0 | 6 votes |
@Override public Mutant getMutation(final MutationIdentifier id) { final ClassContext context = new ClassContext(); context.setTargetMutation(Optional.ofNullable(id)); final Optional<byte[]> bytes = this.byteSource.getBytes(id.getClassName() .asJavaName()); final ClassReader reader = new ClassReader(bytes.get()); final ClassWriter w = new ComputeClassWriter(this.byteSource, this.computeCache, FrameOptions.pickFlags(bytes.get())); final MutatingClassVisitor mca = new MutatingClassVisitor(w, context, filterMethods(), FCollection.filter(this.mutators, isMutatorFor(id))); reader.accept(mca, ClassReader.EXPAND_FRAMES); final List<MutationDetails> details = context.getMutationDetails(context .getTargetMutation().get()); return new Mutant(details.get(0), w.toByteArray()); }
Example #4
Source File: FilterTester.java From pitest with Apache License 2.0 | 6 votes |
public void assertFiltersMutationsFromMutator(String id, Class<?> clazz) { final Sample s = sampleForClass(clazz); final GregorMutater mutator = mutateFromClassLoader(); final List<MutationDetails> mutations = mutator.findMutations(s.className); final Collection<MutationDetails> actual = filter(s.clazz, mutations, mutator); final SoftAssertions softly = new SoftAssertions(); checkHasNMutants(1, s, softly, mutations); final List<MutationDetails> filteredOut = FCollection.filter(mutations, notIn(actual)); softly.assertThat(filteredOut).describedAs("No mutants filtered").isNotEmpty(); softly.assertThat(filteredOut).have(mutatedBy(id)); softly.assertAll(); }
Example #5
Source File: InlinedFinallyBlockFilter.java From pitest with Apache License 2.0 | 6 votes |
@Override public Collection<MutationDetails> intercept( Collection<MutationDetails> mutations, Mutater m) { final List<MutationDetails> combined = new ArrayList<>( mutations.size()); final Map<LineMutatorPair, Collection<MutationDetails>> mutatorLinebuckets = bucket( mutations, toLineMutatorPair()); for (final Entry<LineMutatorPair, Collection<MutationDetails>> each : mutatorLinebuckets .entrySet()) { if (each.getValue().size() > 1) { checkForInlinedCode(combined, each); } else { combined.addAll(each.getValue()); } } /* FIXME tests rely on order of returned mutants */ combined.sort(compareLineNumbers()); return combined; }
Example #6
Source File: IncrementalAnalyserTest.java From pitest with Apache License 2.0 | 6 votes |
@Test public void shouldStartPreviousKilledMutationsAtAStatusOfKilledWhenNeitherClassOrTestHasChanged() { final MutationDetails md = makeMutation("foo"); final String killingTest = "fooTest"; setHistoryForAllMutationsTo(DetectionStatus.KILLED, killingTest); final Collection<TestInfo> tests = Collections.singleton(new TestInfo( "TEST_CLASS", killingTest, 0, Optional.empty(), 0)); when(this.coverage.getTestsForClass(any(ClassName.class))) .thenReturn(tests); when(this.history.hasClassChanged(any(ClassName.class))).thenReturn(false); final Collection<MutationResult> actual = this.testee .analyse(singletonList(md)); assertThat(actual, hasItem(allOf(withStatus(KILLED), withKillingTest(killingTest)))); assertThat(logCatcher.logEntries, hasItems( "Incremental analysis set 1 mutations to a status of KILLED", "Incremental analysis reduced number of mutations by 1" )); }
Example #7
Source File: MutationTestWorker.java From pitest with Apache License 2.0 | 6 votes |
protected void run(final Collection<MutationDetails> range, final Reporter r, final TimeOutDecoratedTestSource testSource) throws IOException { for (final MutationDetails mutation : range) { if (DEBUG) { LOG.fine("Running mutation " + mutation); } final long t0 = System.currentTimeMillis(); processMutation(r, testSource, mutation); if (DEBUG) { LOG.fine("processed mutation in " + (System.currentTimeMillis() - t0) + " ms."); } } }
Example #8
Source File: MutatorTestBase.java From pitest with Apache License 2.0 | 6 votes |
protected void assertMutantsReturn(final Callable<String> mutee, final List<MutationDetails> details, final String... expectedResults) { final List<Mutant> mutants = this.getMutants(details); assertEquals("Should return one mutant for each request", details.size(), mutants.size()); final List<String> results = FCollection.map(mutants, mutantToStringReults(mutee)); int i = 0; for (final String actual : results) { assertEquals(expectedResults[i], actual); i++; } }
Example #9
Source File: TestGregorMutater.java From pitest with Apache License 2.0 | 6 votes |
@Test public void shouldFindNoMutationsWhenNoMutationOperatorsSupplied() throws Exception { class VeryMutable { @SuppressWarnings("unused") public int f(final int i) { switch (i) { case 0: return 1; } return 0; } } createTesteeWith(); final List<MutationDetails> actualDetails = findMutationsFor(VeryMutable.class); assertTrue(actualDetails.isEmpty()); }
Example #10
Source File: IncrementalAnalyserTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldStartNewMutationsAtAStatusOfNotStarted() { final MutationDetails md = makeMutation("foo"); when(this.history.getPreviousResult(any(MutationIdentifier.class))) .thenReturn(Optional.empty()); final Collection<MutationResult> actual = this.testee.analyse(singletonList(md)); assertThat(actual, hasItem(withStatus(NOT_STARTED))); assertThat(logCatcher.logEntries, hasItems( "Incremental analysis set 1 mutations to a status of NOT_STARTED", "Incremental analysis reduced number of mutations by 0" )); }
Example #11
Source File: DefaultGrouperTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldCreateMultipleTestUnitsWhenUnitSizeIsLessThanNumberOfMutations() { makeTesteeWithUnitSizeOf(1); final List<List<MutationDetails>> actual = this.testee.groupMutations( Arrays.asList(ClassName.fromString("foo")), Arrays.asList( createDetails("foo"), createDetails("foo"), createDetails("foo"))); assertEquals(3, actual.size()); }
Example #12
Source File: LoggingCallsFilterTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldNotFilterMutantsOnLinesOtherThanLoggingLine() { final Collection<MutationDetails> actual = analyseWithTestee(LogsAndDoesNot.class); assertThat(actual).doNotHave(mutantsIn("logs")); assertThat(actual).haveAtLeast(1, mutantsIn("noLog")); assertThat(actual).haveExactly(3, mutantsIn("both")); }
Example #13
Source File: LoggingCallsFilterTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldLeaveMutantsNotOnLoggingLinesUntouched() { final ClassName clazz = ClassName.fromClass(DoesNotLog.class); final List<MutationDetails> input = this.mutator.findMutations(clazz); final Collection<MutationDetails> actual = analyseWithTestee(DoesNotLog.class); assertThat(actual).containsExactlyElementsOf(input); }
Example #14
Source File: AvoidForLoopCounterFilter.java From pitest with Apache License 2.0 | 5 votes |
private Predicate<MutationDetails> mutatesAForLoopCounter() { return a -> { final int instruction = a.getInstructionIndex(); final MethodTree method = AvoidForLoopCounterFilter.this.currentClass.methods().stream() .filter(MethodMatchers.forLocation(a.getId().getLocation())) .findFirst().get(); final AbstractInsnNode mutatedInstruction = method.instruction(instruction); final Context<AbstractInsnNode> context = Context.start(method.instructions(), DEBUG); context.store(MUTATED_INSTRUCTION.write(), mutatedInstruction); return MUTATED_FOR_COUNTER.matches(method.instructions(), context); }; }
Example #15
Source File: CompoundMutationInterceptor.java From pitest with Apache License 2.0 | 5 votes |
@Override public Collection<MutationDetails> intercept( Collection<MutationDetails> mutations, Mutater m) { Collection<MutationDetails> modified = mutations; for (final MutationInterceptor each : this.children) { modified = each.intercept(modified, m); } return modified; }
Example #16
Source File: TestGregorMutater.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldNotMutateGroovyClosures() { createTesteeWith(new ResourceFolderByteArraySource(), i -> true, Mutator.all()); final Collection<MutationDetails> actualDetails = findMutationsFor("groovy/SomeGroovyCode$_mapToString_closure2"); assertTrue(actualDetails.isEmpty()); }
Example #17
Source File: DescartesEngineFactoryTest.java From pitest-descartes with GNU Lesser General Public License v3.0 | 5 votes |
@Test public void shouldFindMutatonsAndExclude() { DescartesEngineFactory factory = new DescartesEngineFactory(); MutationEngine engine = factory.createEngine(EngineArguments.arguments().withExcludedMethods(Arrays.asList("get*"))); Mutater mutater = engine.createMutator(ClassloaderByteArraySource.fromContext()); List<MutationDetails> mutations = mutater.findMutations(ClassName.fromString("eu.stamp_project.mutationtest.test.input.Calculator")); assertEquals(5, mutations.size()); }
Example #18
Source File: BigIntegerMutatorTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void minLambda() throws Exception { final Collection<MutationDetails> actual = findMutationsFor(MinLambda.class); final Mutant mutant = getFirstMutant(actual); assertMutantCallableReturns(new MinLambda(-25, 6), mutant, "6"); assertMutantCallableReturns(new MinLambda(25, 6), mutant, "25"); }
Example #19
Source File: IncrementsMutatorTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldRecordCorrectLineNumberForMutations() { final Collection<MutationDetails> actual = findMutationsFor(HasIncrement.class); assertEquals(1, actual.size()); final MutationDetails first = actual.iterator().next(); assertEquals(37, first.getLineNumber()); }
Example #20
Source File: StaticInitializerInterceptorTest.java From pitest with Apache License 2.0 | 5 votes |
private void assertOnlyClinitMethodsMarked(Collection<MutationDetails> actual) { for (final MutationDetails each : actual ) { if (each.isInStaticInitializer()) { if (!each.getId().getLocation().getMethodName().name().equals("<clinit>")) { fail("Expected no mutants to be marked as for static initialization but " + each + " was"); } } } }
Example #21
Source File: BigIntegerMutatorTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void min() throws Exception { final Collection<MutationDetails> actual = findMutationsFor(Min.class); final Mutant mutant = getFirstMutant(actual); assertMutantCallableReturns(new Min(-25, 6), mutant, "6"); assertMutantCallableReturns(new Min(25, 6), mutant, "25"); }
Example #22
Source File: MutationDiscoveryTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldFilterMutantsInTryCatchFinallyCompiledWithJavaC() { this.data.setDetectInlinedCode(true); final ClassName clazz = ClassName.fromString("trywithresources/TryCatchFinallyExample_javac"); final Collection<MutationDetails> actual = findMutants(clazz); assertThat(actual).hasSize(3); }
Example #23
Source File: MutationTestWorkerTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldReportWhenMutationNotDetected() throws IOException { final MutationDetails mutantOne = makeMutant("foo", 1); final Collection<MutationDetails> range = Arrays.asList(mutantOne); final TestUnit tu = makePassingTest(); when(this.testSource.translateTests(any(List.class))).thenReturn( Collections.singletonList(tu)); when( this.hotswapper.apply(any(ClassName.class), any(ClassLoader.class), any(byte[].class))).thenReturn(true); this.testee.run(range, this.reporter, this.testSource); verify(this.reporter).report(mutantOne.getId(), new MutationStatusTestPair(1, DetectionStatus.SURVIVED, new ArrayList<>(), new ArrayList<>())); }
Example #24
Source File: BigIntegerMutatorTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shiftLeft() throws Exception { final Collection<MutationDetails> actual = findMutationsFor(ShiftLeft.class); Mutant mutant = getFirstMutant(actual); assertMutantCallableReturns(new ShiftLeft(1, 1), mutant, String.valueOf(1 >> 1)); assertMutantCallableReturns(new ShiftLeft(1, 2), mutant, String.valueOf(1 >> 2)); assertMutantCallableReturns(new ShiftLeft(1 << 8, 8), mutant, String.valueOf(1)); assertMutantCallableReturns(new ShiftLeft(1 << 8, 4), mutant, String.valueOf(1 << 8 >> 4)); }
Example #25
Source File: BigIntegerMutatorTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void max() throws Exception { final Collection<MutationDetails> actual = findMutationsFor(Max.class); final Mutant mutant = getFirstMutant(actual); assertMutantCallableReturns(new Max(-25, 6), mutant, "-25"); assertMutantCallableReturns(new Max(25, 6), mutant, "6"); }
Example #26
Source File: EquivalentReturnMutationFilter.java From pitest with Apache License 2.0 | 5 votes |
private Predicate<MutationDetails> isEquivalent(Mutater m) { return a -> { if (!MUTATOR_IDS.contains(a.getMutator())) { return false; } final MethodTree method = PrimitiveEquivalentFilter.this.currentClass.methods().stream() .filter(MethodMatchers.forLocation(a.getId().getLocation())) .findFirst() .get(); return ZERO_CONSTANTS.contains(method.realInstructionBefore(a.getInstructionIndex()).getOpcode()); }; }
Example #27
Source File: TestGregorMutater.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldRecordMutationsAsInSameBlockWhenForAStraightThroughMethod() { createTesteeWith(Mutator.byName("INCREMENTS")); final List<MutationDetails> actualDetails = findMutationsFor(OneStraightThroughMethod.class); assertEquals(2, actualDetails.size()); final int firstMutationBlock = actualDetails.get(0).getBlock(); assertEquals(firstMutationBlock, actualDetails.get(1).getBlock()); }
Example #28
Source File: KotlinInterceptor.java From pitest-kotlin with Apache License 2.0 | 5 votes |
@Override public Collection<MutationDetails> intercept( Collection<MutationDetails> mutations, Mutater m) { if(!isKotlinClass) { return mutations; } return FCollection.filter(mutations, isKotlinJunkMutation(currentClass).negate()); }
Example #29
Source File: IncrementalAnalyser.java From pitest with Apache License 2.0 | 5 votes |
private MutationResult makeResult(final MutationDetails each, final DetectionStatus status, final List<String> killingTests, final List<String> succeedingTests) { updatePreanalysedTotal(status); return new MutationResult(each, new MutationStatusTestPair(0, status, killingTests, succeedingTests)); }
Example #30
Source File: InlinedFinallyBlockFilterTest.java From pitest with Apache License 2.0 | 5 votes |
@Test public void shouldNotCombineMutantsWhenOnSameLineAndDifferentBlocksButFromDifferentMutators() { final int line = 100; final int block = 1; final List<MutationDetails> mutations = Arrays.asList( makeMutant(line, block, "Foo", 0), makeMutant(line, block + 1, "NotFoo", 1)); assertEquals(mutations, this.testee.intercept(mutations, this.unused)); }