Skip to content

Commit

Permalink
fix(aggregate) Prevent NoSuchElementException if dependency is missing
Browse files Browse the repository at this point in the history
  • Loading branch information
aurelien-baudet committed Jul 26, 2020
1 parent 310c0a1 commit 77a5b7e
Showing 1 changed file with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;
import java.util.TreeSet;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.logging.Level;

import org.pitest.classinfo.ClassInfo;
import org.pitest.coverage.TestInfo;
import org.pitest.functional.FCollection;
import org.pitest.mutationtest.MutationResult;
import org.pitest.util.Log;

public class MutationTestSummaryData {

Expand Down Expand Up @@ -62,8 +65,16 @@ public MutationTotals getTotals() {
}

public String getPackageName() {
final String packageName = getMutatedClasses().iterator().next().getName()
.asJavaName();
Iterator<ClassInfo> iterator = getMutatedClasses().iterator();
if (!iterator.hasNext()) {
Log.getLogger().log(Level.WARNING, "Can't get package name for " + fileName + "."
+ "There is no mutated classes. It may happen if you are using report-aggregate "
+ "goal to merge reports using a dedicated maven project "
+ "and the dependency that contains the mutated code is missing");
return "default";
}
final String packageName = iterator.next().getName()
.asJavaName();
final int lastDot = packageName.lastIndexOf('.');
return lastDot > 0 ? packageName.substring(0, lastDot) : "default";
}
Expand Down

0 comments on commit 77a5b7e

Please sign in to comment.