Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Support for multiple reports with different granularity (file, class, method) #9

Open
wants to merge 42 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
29d6a9b
AbstractSmell became interface, getHasSmell and getHasProductionFile …
victorgveloso Aug 26, 2020
b33956d
Moved Util members to AbstractSmell (making it abstract class again),…
victorgveloso Aug 26, 2020
287a2fb
Pulled smellyElement member up to AbstractSmell, Moved with delegatio…
victorgveloso Aug 26, 2020
9ba345a
Refactored Main.java, renamed some methods (TestSmellDetector.addSmel…
victorgveloso Aug 26, 2020
3497f82
Implemented MethodValidator and TestSmellDetector unit tests, added '…
victorgveloso Aug 26, 2020
b67eed0
Removed writeOutput aliases on ResultsWriter, renamed writeOutput to …
victorgveloso Aug 27, 2020
0a8a036
Extracted super class SmellsContainer from TestFile (use it on Result…
victorgveloso Aug 27, 2020
3e7eb48
A relative file path without separator is equal to the filename, a fi…
victorgveloso Aug 27, 2020
4821c62
On TestFile constructor, file without extension and path without sepa…
victorgveloso Aug 27, 2020
aa1fe2d
SmellsContainer became an interface with default methods and it's sup…
victorgveloso Aug 28, 2020
e2e6bd3
New class extracted from Main. It will handle report granularity-leve…
victorgveloso Aug 28, 2020
1825641
ExportingGranularityController renamed to ReportController, report gr…
victorgveloso Aug 28, 2020
c750a85
IntegrationTest implemented for TestSmellDetector.detectSmells (tagge…
victorgveloso Aug 28, 2020
1ee8b41
Renamed TestSmellDetectorIT.testSmellDetector to 'testSmellsFreeProje…
victorgveloso Aug 30, 2020
871a284
Optimized AbstractSmell.hasSmell, made prodFile optional, merging sam…
victorgveloso Sep 18, 2020
81b1eaa
Breaking change: no null should be added as testFile's smells on Test…
victorgveloso Sep 18, 2020
ff64c7d
Tests implemented for each TestSmell (production file specified only …
victorgveloso Sep 18, 2020
d24a6eb
ReportController new constructor receive granularities list, relative…
victorgveloso Sep 25, 2020
4f1e412
Implemented merge of smells with same name on report
victorgveloso Sep 26, 2020
8df9dc7
Reimplemented merging, fixing repeated entry and wrong smellPresence
victorgveloso Sep 26, 2020
f0d1c34
Extracted Report formatting from ReportController and refactored code
victorgveloso Sep 26, 2020
833911e
Adapted tests to ignore outputted Smells order (this is still WIP)
victorgveloso Sep 26, 2020
f5b3178
Fixed some warnings
victorgveloso Sep 26, 2020
d36797b
CSV header generated after smell detection + method compatibility
victorgveloso Sep 27, 2020
ea58040
Removed ResultsWriter dependency TestSmellDetector
victorgveloso Sep 27, 2020
2a357fd
TestMethod full name (package.class.method) retrieved for uniqueness
victorgveloso Sep 27, 2020
7e8e887
full class name (package.class) retrieved too; made methods more generic
victorgveloso Sep 27, 2020
57c0335
Implemented simultaneous multiple output granularities
victorgveloso Sep 27, 2020
3723487
fixed ConstructorInitializationIntegrationTest, added class granulari…
victorgveloso Sep 28, 2020
f17e982
ReportControllerIntegrationTests better organized (split in 3 classes…
victorgveloso Sep 28, 2020
daecf80
Enhanced ReportControllerIntegrationTests organization even more!
victorgveloso Sep 28, 2020
c2a994c
Make all granularities enabled by default and updated project version.
victorgveloso Sep 28, 2020
d972bd3
Fixed outputting header repeatedly for each inputted TestFile; Optimi…
victorgveloso Oct 25, 2020
15d7a5d
Fixed multi-file repeated report entries:
victorgveloso Oct 25, 2020
3073395
Implemented failing tests for class granularity report and fixed Depe…
victorgveloso Oct 26, 2020
9d11c39
Fixed ConstructorInitialization omission on failure
victorgveloso Oct 27, 2020
d3d27a7
Fixed DefaultTest and IgnoredTest omission/null on failure; added sup…
victorgveloso Oct 27, 2020
beeae67
Updated maven project version
victorgveloso Oct 27, 2020
233f1c1
Added Anonymous class handling at AbstractSmell.getFullMethodName
victorgveloso Oct 27, 2020
397e840
Maven patch version increased
victorgveloso Oct 27, 2020
264f657
Renamed AssertCount to BadAssertCount and added TotalAssertCount
victorgveloso Jun 25, 2021
d30bc86
Added final modifier to TestSmellDetector class
victorgveloso Jun 25, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Tests implemented for each TestSmell (production file specified only …
…when required). IgnoredTest results in false positive; ConstructorInitialization and GeneralFixture are not detected.
victorgveloso committed Sep 18, 2020
commit ff64c7df5c2ad6d8de9e466a18b61f8c2ed05fa1
15 changes: 11 additions & 4 deletions src/main/java/edu/rit/se/testsmells/testsmell/AbstractSmell.java
Original file line number Diff line number Diff line change
@@ -4,20 +4,27 @@
import com.github.javaparser.ast.body.MethodDeclaration;

import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;

public abstract class AbstractSmell {
private final MethodValidator methodValidator;
private final List<SmellyElement> smellyElementList;

public abstract String getSmellName();

public abstract void runAnalysis(CompilationUnit testFileCompilationUnit, CompilationUnit productionFileCompilationUnit, String testFileName, String productionFileName) throws FileNotFoundException;

public AbstractSmell() {
methodValidator = new MethodValidator(); //TODO: dependency should be injected (or, at least, be a singleton)
smellyElementList = new ArrayList<>();
smellyElementList = new CopyOnWriteArrayList<>();
}

public abstract void runAnalysis(CompilationUnit testFileCompilationUnit, CompilationUnit productionFileCompilationUnit, String testFileName, String productionFileName) throws FileNotFoundException;

public void clear() {
for (SmellyElement smellyElement : smellyElementList) {
smellyElement.clear();
}
smellyElementList.clear();
}

/**
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package edu.rit.se.testsmells.testsmell;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.CopyOnWriteArrayList;

public interface SmellsContainer {
List<AbstractSmell> testSmells = new ArrayList<>();
List<AbstractSmell> testSmells = new CopyOnWriteArrayList<>();

Map<String, String> getTestDescriptionEntries();

Original file line number Diff line number Diff line change
@@ -13,6 +13,10 @@ public SmellyElement(String name) {
this.name = name;
}

public void clear() {
data.clear();
}

public void setHasSmell(boolean hasSmell) {
this.hasSmell = hasSmell;
}
Original file line number Diff line number Diff line change
@@ -10,23 +10,40 @@
import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

public class TestSmellDetector {

private List<InputStream> inputStreams;
private List<AbstractSmell> testSmells;

/**
* Instantiates the various test smell analyzer classes and loads the objects into an List
*/
public TestSmellDetector() {
testSmells = new ArrayList<>();
inputStreams = new ArrayList<>();
}

public void addDetectableSmell(AbstractSmell smell) {
testSmells.add(smell);
}

public void clear() {
for (InputStream inputStream : inputStreams) {
try {
inputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
for (AbstractSmell smell : testSmells) {
smell.clear();
}
testSmells.clear();
}

/**
* Factory method that provides a new instance of the TestSmellDetector
*
@@ -48,7 +65,7 @@ public List<String> getTestSmellNames() {
/**
* Loads the java source code file into an AST and then analyzes it for the existence of the different types of test smells
*/
public void detectSmells(TestFile testFile) {
public void detectSmells(TestFile testFile) throws IOException {
CompilationUnit testFileCompilationUnit = parseIntoCompilationUnit(testFile.getTestFilePath());

CompilationUnit productionFileCompilationUnit = parseIntoCompilationUnit(testFile.getProductionFilePath());
@@ -58,7 +75,7 @@ public void detectSmells(TestFile testFile) {
smell.runAnalysis(testFileCompilationUnit, productionFileCompilationUnit, testFile.getTestFileNameWithoutExtension(), testFile.getProductionFileNameWithoutExtension());
} catch (FileNotFoundException ignored) {
}

testFile.addDetectedSmell(smell);
for (SmellsContainer element : smell.getSmellyElements()) {
element.addDetectedSmell(smell);
@@ -71,12 +88,15 @@ private CompilationUnit parseIntoCompilationUnit(String filePath) {
if (StringUtils.isEmpty(filePath)) {
return null;
}
InputStream testFileInputStream;
InputStream testFileInputStream = null;
try {
testFileInputStream = new FileInputStream(filePath);
} catch (IOException e) {
testFileInputStream = getClass().getResourceAsStream(filePath);
} finally {
inputStreams.add(testFileInputStream);
}
assert Objects.nonNull(testFileInputStream);
return JavaParser.parse(testFileInputStream);
}
}
Loading