I think the error does not reveal the source of the problem, which in my case (most probably to any case) would be impossible to do so.
In my case I had a list of objects that contained a function which returns a predicate. So I used stream to iterate through all of them and I filtered the one of them that matched the predicate with another object as candidate. So in terms of code I had:
public List<ParkingSlot> getFreeParkingSlots(List<DepartmentParkingRule> ruleList, Employee candidate){
return
ruleList.stream().
.filter(j -> j.getPredicate().test(candidate)) // <-- here appeared the error *replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED*
.map(t -> t.getFreeParkingSlots(candidate))
.findFirst()
.orElseThrow(new NotMatchedException(candidate));
}
I expected (by analysis/design) a candidate employee to match only one department rule. I thought using .findFirst()
was a good fit. PIT denied. By mutating the result of predicate of a normally non matched case (department) to a 'mutant match', there could possibly be more than one match, not exactly one.
So I modified my code to throw an exception in case of having more than one match. After this change the mutant was KILLED. So my function is now:
public List<ParkingSlot> getFreeParkingSlots(List<DepartmentParkingRule> ruleList,
Employee candidate){
Optional<List<ParkingSlot>> parkingSlots = ruleList.stream().
.filter(j -> j.getPredicate().test(candidate))
.map(t -> t.getFreeParkingSlots(candidate))
.reduce((anElement, otherElement) ->
throw new DuplicateException());//reduce is executed when a possible false positive duplicate rule match
if (parkingSlots.isPresent() && CollectionUtils.isNotEmpty(parkingSlots.get())){
return parkingSlots.get();
}else {
throw new NotMatchedException(candidate);
}
}
Thus the error replaced return of integer sized value with (x == 0 ? 1 : 0) → SURVIVED
indicated the mutation happened and most importantly that this mutation did not cause a failure to my tests.
Next time I see this error, I will look to the impact on my tests as a whole and not to the specific boolean function.
Just to note that the above code is not real but rather useful to show how to interpret the error and actions made to modify the source code. Change to tests could possibly help killing that mutant but this depends on each case.
Hope it helps someone.