private static MutationDetails makeCombinedMutant( final Collection<MutationDetails> value) { final MutationDetails first = value.iterator().next(); final Set<Integer> indexes = new HashSet<>(); mapTo(value, mutationToIndex(), indexes); final MutationIdentifier id = new MutationIdentifier(first.getId() .getLocation(), indexes, first.getId().getMutator()); return new MutationDetails(id, first.getFilename(), first.getDescription(), first.getLineNumber(), first.getBlock()); }
@Override public boolean equals(final Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (getClass() != obj.getClass()) { return false; } final MutationDetails other = (MutationDetails) obj; if (this.id == null) { if (other.id != null) { return false; } } else if (!this.id.equals(other.id)) { return false; } return true; }
/** * Returns the class in which this mutation is located * * @return class in which mutation is located */ public ClassName getClassName() { return this.id.getClassName(); }
@Override public int compareTo(final MutationIdentifier other) { int comp = this.location.compareTo(other.getLocation()); if (comp != 0) { return comp; } comp = this.mutator.compareTo(other.getMutator()); if (comp != 0) { return comp; } return this.indexes.get(0).compareTo(other.indexes.get(0)); }
/** * Returns the method name in which this mutation is located as a string * * @return method name as string */ @Deprecated public String getLocation() { // fixme this should not be here used in string template return this.id.getLocation().describe(); }
private MutationIdentifier getNextMutationIdentifer( final MethodMutatorFactory factory, final String className) { return new MutationIdentifier(this.location, this.instructionIndex, factory.getGloballyUniqueId()); }
/** * Returns the name of the mutator that created this mutation * * @return the mutator name */ public String getMutator() { return this.id.getMutator(); }
@Test public void shouldMatchWhenIndexesOverlap() { final MutationIdentifier a = new MutationIdentifier(aLocation().build(), new HashSet<>(Arrays.asList(1, 2)), "M"); final MutationIdentifier b = new MutationIdentifier(aLocation().build(), 1, "M"); assertTrue(a.matches(b)); }
/** * Returns true if this mutation has a matching identifier * * @param id * the MutationIdentifier to match * @return true if the MutationIdentifier matches otherwise false */ public Boolean matchesId(final MutationIdentifier id) { return this.id.matches(id); }
@Test public void shouldHaveSymmetricEqulasImplementation() { final MutationIdentifier a = aMutationId().withIndex(1).withMutator("M").build(); final MutationIdentifier b = aMutationId().withIndex(1).withMutator("M").build(); assertTrue(a.equals(b)); assertTrue(b.equals(a)); assertTrue(a.hashCode() == b.hashCode()); }
/** * Returns the index to the first instruction on which this mutation occurs. * This index is specific to how ASM represents the bytecode. * * @return the zero based index to the instruction */ public int getFirstIndex() { return this.id.getFirstIndex(); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + ((this.id == null) ? 0 : this.id.hashCode()); return result; }
/** * Returns the class in which this mutation is located * * @return class in which mutation is located */ public MethodName getMethod() { return this.id.getLocation().getMethodName(); }
@Override protected MutationResult mapToData(final Map<String, Object> map) { final Location location = new Location(ClassName.fromString((String) map.get(MUTATED_CLASS)), MethodName.fromString((String) map.get(MUTATED_METHOD)), (String) map.get(METHOD_DESCRIPTION)); final MutationIdentifier id = new MutationIdentifier(location, Arrays.asList(new Integer((String) map.get(INDEX))), (String) map.get(MUTATOR)); final MutationDetails md = new MutationDetails(id, (String) map.get(SOURCE_FILE), (String) map.get(DESCRIPTION), Integer.parseInt((String) map.get(LINE_NUMBER)), Integer.parseInt((String) map.get(BLOCK))); final MutationStatusTestPair status = new MutationStatusTestPair(Integer.parseInt((String) map.get(NUMBER_OF_TESTS_RUN)), DetectionStatus.valueOf((String) map.get(STATUS)), (String) map.get(KILLING_TEST)); return new MutationResult(md, status); }
@Override public int compareTo(final MutationIdentifier other) { int comp = this.location.compareTo(other.getLocation()); if (comp != 0) { return comp; } comp = this.mutator.compareTo(other.getMutator()); if (comp != 0) { return comp; } return this.indexes.get(0).compareTo(other.indexes.get(0)); }
private static Predicate<MethodMutatorFactory> isMutatorFor( final MutationIdentifier id) { return a -> id.getMutator().equals(a.getGloballyUniqueId()); }
@Test public void shouldNotMatchWhenIndexesDoNotOverlap() { final MutationIdentifier a = new MutationIdentifier(aLocation().build(), new HashSet<Integer>(100, 200), "M"); final MutationIdentifier b = new MutationIdentifier(aLocation().build(), 1, "M"); assertFalse(a.matches(b)); }
private static Predicate<MutationIdentifier> idMatches( final MutationIdentifier newId) { return a -> a.matches(newId); }
/** * Returns true if this mutation has a matching identifier * * @param id * the MutationIdentifier to match * @return true if the MutationIdentifier matches otherwise false */ public boolean matches(final MutationIdentifier id) { return this.location.equals(id.location) && this.mutator.equals(id.mutator) && this.indexes.contains(id.getFirstIndex()); }
@Override public int hashCode() { final int prime = 31; int result = 1; result = (prime * result) + ((this.id == null) ? 0 : this.id.hashCode()); return result; }