use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.
the class PropertyChangeGuesser method getGuesses.
public Set<String> getGuesses(final PeassFolders folders, final Entry<ChangedEntity, ClazzChangeData> changedEntity) throws FileNotFoundException {
final Set<String> guessedTypes = new HashSet<>();
// TODO Here, a real config should be passed; since this is rarely used, we go with the default folders
ClazzFileFinder finder = new ClazzFileFinder(new ExecutionConfig());
final File file = finder.getSourceFile(folders.getProjectFolder(), changedEntity.getKey());
final File fileOld = finder.getSourceFile(folders.getOldSources(), changedEntity.getKey());
if (file != null && fileOld != null && file.exists() && fileOld.exists()) {
final CompilationUnit clazzUnit = JavaParserProvider.parse(file);
final CompilationUnit clazzUnitOld = JavaParserProvider.parse(fileOld);
for (Map.Entry<String, Set<String>> changedClazz : changedEntity.getValue().getChangedMethods().entrySet()) {
// If only method change..
if (changedClazz.getValue() != null) {
for (String method : changedClazz.getValue()) {
final String source = FileComparisonUtil.getMethodSource(changedEntity.getKey(), method, clazzUnit);
final String sourceOld = FileComparisonUtil.getMethodSource(changedEntity.getKey(), method, clazzUnitOld);
final Patch<String> changedLinesMethod = DiffUtils.diff(Arrays.asList(sourceOld.split("\n")), Arrays.asList(source.split("\n")));
for (final Delta<String> delta : changedLinesMethod.getDeltas()) {
getDeltaGuess(guessedTypes, (delta.getOriginal().getLines()));
getDeltaGuess(guessedTypes, (delta.getRevised().getLines()));
}
}
}
}
}
return guessedTypes;
}
use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.
the class TestClazzFileFinder method testClasses.
@Test
public void testClasses() {
ExecutionConfig config = new ExecutionConfig();
config.getClazzFolders().add("src/main/java");
config.getClazzFolders().add("src/java");
List<String> clazzes = new ClazzFileFinder(config).getClasses(SOURCE);
System.out.println(clazzes);
MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe1"));
MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe2"));
MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.Second"));
MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe2$Inner"));
MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe2$Inner$InnerInner"));
MatcherAssert.assertThat(clazzes, Matchers.hasItem("de.TestMe2$InnerEnum"));
}
use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.
the class JUnitTestTransformer method findModuleTests.
private TestSet findModuleTests(final ModuleClassMapping mapping, final List<String> includedModules, final File module) {
final TestSet moduleTests = new TestSet();
ClazzFileFinder finder = new ClazzFileFinder(config.getExecutionConfig());
for (final String clazz : finder.getTestClazzes(module)) {
final String currentModule = mapping.getModuleOfClass(clazz);
final List<TestCase> testMethodNames = getTestMethodNames(module, new TestCase(clazz, null, currentModule));
for (TestCase test : testMethodNames) {
if (includedModules == null || includedModules.contains(test.getModule())) {
addTestIfIncluded(moduleTests, test);
}
}
}
return moduleTests;
}
use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.
the class JUnitTestTransformer method getTestMethodNames.
@Override
public List<TestCase> getTestMethodNames(final File module, final TestCase clazzname) {
final List<TestCase> methods = new LinkedList<>();
ClazzFileFinder finder = new ClazzFileFinder(config.getExecutionConfig());
final File clazzFile = finder.getClazzFile(module, clazzname);
final CompilationUnit unit = loadedFiles.get(clazzFile);
if (unit != null) {
final Integer junit = junitVersions.get(clazzFile);
if (junit != null) {
final ClassOrInterfaceDeclaration clazz = ParseUtil.getClass(unit);
if (junit == 3) {
for (final MethodDeclaration method : clazz.getMethods()) {
if (method.getNameAsString().toLowerCase().contains("test")) {
methods.add(new TestCase(clazzname.getClazz(), method.getNameAsString(), clazzname.getModule()));
}
}
} else if (junit == 4) {
for (String junit4method : getAnnotatedMethods(clazz, 4)) {
TestCase test = new TestCase(clazzname.getClazz(), junit4method, clazzname.getModule());
methods.add(test);
}
} else if (junit == 5) {
for (String junit5method : getAnnotatedMethods(clazz, 5)) {
TestCase test = new TestCase(clazzname.getClazz(), junit5method, clazzname.getModule());
methods.add(test);
}
}
} else {
LOG.warn("Clazz {} has no JUnit version", clazzFile);
}
} else {
/**
* By default, the dependency selection adds all changed clazzes as tests (since a class not containing a test may contain a new test), so this is mostly not a real error
*/
LOG.error("Did not find {} for {} - class not loaded (since it is not a test class?)", clazzFile, clazzname);
}
return methods;
}
use of de.dagere.peass.dependency.ClazzFileFinder in project peass by DaGeRe.
the class TestPackageFinder method testDependencyModule.
@Test
public void testDependencyModule() {
ExecutionConfig config = new ExecutionConfig();
config.getClazzFolders().add("src/main/java");
config.getClazzFolders().add("src/java");
final List<String> lowestPackage = new ClazzFileFinder(config).getClasses(new File("."));
System.out.println(lowestPackage);
MatcherAssert.assertThat(lowestPackage, IsIterableContaining.hasItem("de.dagere.peass.RegressionTestSelectionStarter"));
MatcherAssert.assertThat(lowestPackage, Matchers.not(IsIterableContaining.hasItem("de.dagere.peass.RegressionTestSelectionStarter.RegressionTestSelectionStarter")));
MatcherAssert.assertThat(lowestPackage, IsIterableContaining.hasItem("de.dagere.peass.dependency.statistics.DependencyStatisticAnalyzer"));
MatcherAssert.assertThat(lowestPackage, IsIterableContaining.hasItem("de.dagere.peass.dependency.statistics.DependencyStatistics"));
MatcherAssert.assertThat(lowestPackage, IsIterableContaining.hasItem("de.dagere.peass.TestPackageFinder"));
}
Aggregations