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
On TestFile constructor, file without extension and path without sepa…
…rator aren't treated as special cases, they throw an IllegalArgumentException instead
victorgveloso authored and BuildTools committed Aug 27, 2020
commit 4821c6297eafe9ccf18c54a39a8e0144ecef56a1
31 changes: 23 additions & 8 deletions src/main/java/edu/rit/se/testsmells/testsmell/TestFile.java
Original file line number Diff line number Diff line change
@@ -11,11 +11,26 @@ public class TestFile extends SmellsContainer {

public TestFile(String app, String testFilePath, String productionFilePath) {
super();
checkValidity(testFilePath, productionFilePath, app);
this.app = app;
this.testFilePath = testFilePath;
this.productionFilePath = productionFilePath;
}

protected void checkValidity(String testPath, String prodPath, String app) {
if (!haveExtension(testPath, prodPath) || !haveFileSeparator(testPath, prodPath) || app.isEmpty()) {
throw new IllegalArgumentException("Both testFilePath and productionFilePath should include extensions and file separator. App cannot be empty!");
}
}

private boolean haveFileSeparator(String testPath, String prodPath) {
return testPath.lastIndexOf(File.separator) != -1 && prodPath.lastIndexOf(File.separator) != -1;
}

private boolean haveExtension(String testPath, String prodPath) {
return testPath.lastIndexOf('.') != -1 && prodPath.lastIndexOf('.') != -1;
}

public Map<String, String> getTestDescriptionEntries() {
Map<String, String> descriptions = new HashMap<>();

@@ -76,11 +91,7 @@ public String getProductionFileName() {
* @return the relative test file path
*/
public String getRelativeTestFilePath() {
if (!StringUtils.isEmpty(testFilePath)) {
int projectNameIndex = testFilePath.lastIndexOf(app);
if (projectNameIndex == -1) return "";
return testFilePath.substring(projectNameIndex + app.length() + File.separator.length());
} else return "";
return extractRelativePathFrom(testFilePath);
}

/**
@@ -90,10 +101,14 @@ public String getRelativeTestFilePath() {
* @return the relative production file path
*/
public String getRelativeProductionFilePath() {
if (!StringUtils.isEmpty(productionFilePath)) {
int projectNameIndex = productionFilePath.lastIndexOf(app);
return extractRelativePathFrom(productionFilePath);
}

private String extractRelativePathFrom(String path) {
if (!StringUtils.isEmpty(path)) {
int projectNameIndex = path.lastIndexOf(app);
if (projectNameIndex == -1) return "";
return productionFilePath.substring(projectNameIndex + app.length() + File.separator.length());
return path.substring(projectNameIndex + app.length() + File.separator.length());
} else return "";
}
}
147 changes: 47 additions & 100 deletions src/test/java/edu/rit/se/testsmells/testsmell/TestFileTest.java
Original file line number Diff line number Diff line change
@@ -8,71 +8,77 @@
import java.io.File;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertThrows;

class TestFileTest {

@EnabledOnOs({OS.LINUX, OS.MAC})
class UnixTestFileTest {
private String fileTest = "commons-lang," +
"/Users/grano/projects/commons-lang/src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java," +
"/Users/grano/projects/commons-lang/src/main/java/org/apache/commons/lang3/RandomStringUtils.java";
private String fileTestWindows = "myCoolApp," +
"F:\\Apps\\myCoolApp\\code\\test\\GraphTest.java," +
"F:\\Apps\\myCoolApp\\code\\src\\Graph.java";
private TestFile testFileUnix;
private TestFile testFileWindows;

@BeforeEach
void setUp() {
String[] splits = fileTest.split(",");
testFileUnix = new TestFile(splits[0], splits[1], splits[2]);
String[] splitW = fileTestWindows.split(",");
testFileWindows = new TestFile(splitW[0], splitW[1], splitW[2]);
}

@Test
@EnabledOnOs({OS.WINDOWS})
public void testGetFileNameWindows() {
String oracle = "GraphTest.java";
String output = testFileWindows.getTestFileName();
public void testGetProductionFileNameUnix() {
String oracle = "RandomStringUtils.java";
String output = testFileUnix.getProductionFileName();
assertEquals(oracle, output);
}

@Test
@EnabledOnOs({OS.LINUX, OS.MAC})
public void testGetFileNameUnix() {
String oracle = "RandomStringUtilsTest.java";
String output = testFileUnix.getTestFileName();
assertEquals(oracle, output);
}

@Test
@EnabledOnOs({OS.WINDOWS})
public void testProductionFileNameWindows() {
String oracle = "Graph.java";
String output = testFileWindows.getProductionFileName();
public void testGetRelativeProductionFilePathUnix() {
String oracle = "src/main/java/org/apache/commons/lang3/RandomStringUtils.java";
String output = testFileUnix.getRelativeProductionFilePath();
assertEquals(oracle, output);
}

@Test
@EnabledOnOs({OS.LINUX, OS.MAC})
public void testGetProductionFileNameUnix() {
String oracle = "RandomStringUtils.java";
String output = testFileUnix.getProductionFileName();
public void testGetRelativeTestFilePathUnix() {
String oracle = "src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java";
String output = testFileUnix.getRelativeTestFilePath();
assertEquals(oracle, output);
}
}

@EnabledOnOs({OS.WINDOWS})
class WindowsTestFileTest {

private String fileTestWindows = "myCoolApp," +
"F:\\Apps\\myCoolApp\\code\\test\\GraphTest.java," +
"F:\\Apps\\myCoolApp\\code\\src\\Graph.java";
private TestFile testFileWindows;

@BeforeEach
void setUp() {
String[] split = fileTestWindows.split(",");
testFileWindows = new TestFile(split[0], split[1], split[2]);
}

@Test
@EnabledOnOs({OS.LINUX, OS.MAC})
public void testGetRelativeProductionFilePathUnix() {
String oracle = "src/main/java/org/apache/commons/lang3/RandomStringUtils.java";
String output = testFileUnix.getRelativeProductionFilePath();
@EnabledOnOs({OS.WINDOWS})
public void testProductionFileNameWindows() {
String oracle = "Graph.java";
String output = testFileWindows.getProductionFileName();
assertEquals(oracle, output);
}

@Test
@EnabledOnOs({OS.LINUX, OS.MAC})
public void testGetRelativeTestFilePathUnix() {
String oracle = "src/test/java/org/apache/commons/lang3/RandomStringUtilsTest.java";
String output = testFileUnix.getRelativeTestFilePath();
@EnabledOnOs({OS.WINDOWS})
public void testGetFileNameWindows() {
String oracle = "GraphTest.java";
String output = testFileWindows.getTestFileName();
assertEquals(oracle, output);
}

@@ -93,89 +99,30 @@ public void testGetRelativeTestFilePathWindows() {
}
}

class FilePathWithoutSeparatorTest {
class TestFileSpecialCasesTest {
String path;
TestFile sut;
String app;

@BeforeEach
public void setUp() {
path = "file.extension";
sut = new TestFile("", path, path);
}

@Test
public void testTestFilePath() {
assertEquals(sut.getTestFilePath(), path);
app = "project";
}

@Test
public void testTestFileName() {
assertEquals(sut.getTestFileName(), path);
}

@Test
public void testProductionFilePath() {
assertEquals(sut.getProductionFilePath(), path);
}

@Test
public void testProductionFileName() {
assertEquals(sut.getProductionFileName(), path);
}
}

class FileWithoutExtension {
String filename;
String relativePath;
String path;
TestFile sut;

@BeforeEach
public void setUp() {
String app = "folder";
filename = "fileWithoutExtension";
relativePath = "to" + File.separator + filename;
path = app + File.separator + relativePath;
sut = new TestFile(app, path, path);
}

@Test
public void testTestFilePath() {
assertEquals(sut.getTestFilePath(), path);
}

@Test
public void testRelativeTestFilePath() {
assertEquals(sut.getRelativeTestFilePath(), relativePath);
}

@Test
public void testTestFileName() {
assertEquals(sut.getTestFileName(), filename);
}

@Test
public void testTestFileNameWithoutExtension() {
assertEquals(sut.getTestFileNameWithoutExtension(), filename);
}

@Test
public void testProductionFilePath() {
assertEquals(sut.getProductionFilePath(), path);
}

@Test
public void testRelativeProductionFilePath() {
assertEquals(sut.getRelativeProductionFilePath(), relativePath);
public void testFilePathWithoutSeparatorTest() {
path = "file.extension";
assertThrows(IllegalArgumentException.class, () -> new TestFile(app, path, path));
}

@Test
public void testProductionFileName() {
assertEquals(sut.getProductionFileName(), filename);
public void testFileWithoutExtension() {
path = app + File.separator + "to" + File.separator + "fileWithoutExtension";
assertThrows(IllegalArgumentException.class, () -> new TestFile(app, path, path));
}

@Test
public void testProductionFileNameWithoutExtension() {
assertEquals(sut.getProductionFileNameWithoutExtension(), filename);
public void testEmptyAppName() {
path = "to" + File.separator + "fileWithoutExtension";
assertThrows(IllegalArgumentException.class, () -> new TestFile("", path, path));
}
}
Original file line number Diff line number Diff line change
@@ -54,6 +54,10 @@ public TestFileStub(String app, String testFilePath, String productionFilePath)
super(app, testFilePath, productionFilePath);
}

@Override
protected void checkValidity(String testPath, String prodPath, String app) {
}

@Override
public String getTestFileNameWithoutExtension() {
return "";