Skip to content

Commit

Permalink
explicitly order history file entries
Browse files Browse the repository at this point in the history
  • Loading branch information
hcoles committed Aug 3, 2023
1 parent 2ebd45f commit eb38915
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Optional;
Expand Down Expand Up @@ -289,9 +290,14 @@ private MutationResultInterceptor resultInterceptor() {
}

private void recordClassPath(HistoryStore history, CoverageDatabase coverageData) {
final Set<ClassName> allClassNames = getAllClassesAndTests(coverageData);
final Collection<HierarchicalClassId> ids = FCollection.map(
this.code.getClassInfo(allClassNames), ClassInfo::getHierarchicalId);
Set<ClassName> allClassNames = getAllClassesAndTests(coverageData);

// sort by classname to ensure order consistent across machines
List<HierarchicalClassId> ids = this.code.getClassInfo(allClassNames).stream()
.map(ClassInfo::getHierarchicalId)
.sorted(Comparator.comparing(HierarchicalClassId::getName))
.collect(Collectors.toList());

history.recordClassPath(ids, coverageData);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
*/
package org.pitest.mutationtest.tooling;

import static java.util.Arrays.asList;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyCollection;
Expand Down Expand Up @@ -163,7 +164,33 @@ public void shouldRecordClassPath() {

createAndRunTestee();

verify(this.history).recordClassPath(Arrays.asList(fooId), this.coverageDb);
verify(this.history).recordClassPath(asList(fooId), this.coverageDb);
}

@Test
public void ordersHistoryEntries() {

final ClassName clazz = ClassName.fromClass(Foo.class);

final HierarchicalClassId fooId = new HierarchicalClassId(
new ClassIdentifier(0, clazz), "0");
final HierarchicalClassId barId = new HierarchicalClassId(
new ClassIdentifier(0, ClassName.fromString("Bar")), "0");
final ClassInfo foo = ClassInfoMother.make(fooId.getId());
final ClassInfo bar = ClassInfoMother.make(barId.getId());

when(this.mutater.findMutations(ClassName.fromClass(Foo.class))).thenReturn(aMutantIn(Foo.class));

when(this.code.getCodeUnderTestNames()).thenReturn(
Collections.singleton(clazz));
when(this.code.getClassInfo(anyCollection())).thenReturn(
asList(foo, bar));
when(this.coverageDb.getCodeLinesForClass(clazz)).thenReturn(new ClassLines(clazz, Collections.emptySet()));

createAndRunTestee();

// bar comes first alphabetically
verify(this.history).recordClassPath(asList(barId, fooId), this.coverageDb);
}

@Test
Expand Down

0 comments on commit eb38915

Please sign in to comment.