com.github.mikesafonov.pitest.git.changes.TargetClassToCodeChangeMappingFunction Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pitest-git-changes-plugin Show documentation
Show all versions of pitest-git-changes-plugin Show documentation
Pitest plugin for mutating git changes
The newest version!
package com.github.mikesafonov.pitest.git.changes;
import com.github.mikesafonov.pitest.git.GitChange;
import lombok.RequiredArgsConstructor;
import org.apache.commons.io.FilenameUtils;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
@RequiredArgsConstructor
public class TargetClassToCodeChangeMappingFunction implements Function> {
private final Set targetClasses;
@Override
public Optional apply(GitChange change) {
String className = toClassName(change.getFileName());
return targetClasses.stream()
.filter(className::endsWith)
.map(s -> new CodeChange(s, change.getLineFrom(), change.getLineTo()))
.findFirst();
}
private static String toClassName(String filename) {
String name = FilenameUtils.removeExtension(filename);
return name.replace("/", ".");
}
}