Skip to content

Commit 092139f

Browse files
committed
Updated the project to remove references to "app" and "tag" in the detection/output as this is no longer required. Updated the README.md with details on how to run the tool.
1 parent 874494d commit 092139f

File tree

4 files changed

+42
-65
lines changed

4 files changed

+42
-65
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,22 @@
11
# TestFileMapping
22
This program maps the specified test file with the the production (SUT) file
3+
4+
## Prerequisites
5+
A csv file containing the path of the test file and the directory containing the source files. This file needs to be passed as input.
6+
7+
Example of the structure of this file:
8+
9+
`
10+
C:\Projects\MyProject\src\main,C:\Projects\MyProject\src\test\java\org\example\common\PluginResourceBundleTest.java
11+
C:\Projects\MyProject\src\main,C:\Projects\MyProject\src\test\java\org\example\inspection\ConditionalInspectionTest.java
12+
C:\Projects\MyProject\src\main,C:\Projects\MyProject\src\test\java\org\example\inspection\DuplicateInspectionTest.java
13+
C:\Projects\MyProject\src\main,C:\Projects\MyProject\src\test\java\org\example\inspection\GeneralInspectionTest.java
14+
`
15+
16+
## Usage
17+
Run the jar file:
18+
19+
`C:\Projects\TestFileMapping>java -jar TestFileMapping.jar C:\Work\input.csv`
20+
21+
## Output
22+
The output csv file will be saved in the same directory as the jar. The file will contain the path of the test file and the corresponding production file (if found).

src/main/java/edu/rit/se/testsmells/Main.java

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,14 @@ public class Main {
1212
static List<TestFile> testFiles;
1313

1414
public static void main(String[] args) throws IOException {
15-
if (args == null) {
15+
if (args == null || args.length == 0) {
1616
System.out.println("Please provide the file containing the paths to the collection of test files");
1717
return;
1818
}
19-
if(!args[0].isEmpty()){
19+
20+
if (!args[0].isEmpty()) {
2021
File inputFile = new File(args[0]);
21-
if(!inputFile.exists() || inputFile.isDirectory()) {
22+
if (!inputFile.exists() || inputFile.isDirectory()) {
2223
System.out.println("Please provide a valid file containing the paths to the collection of test files");
2324
return;
2425
}
@@ -35,31 +36,23 @@ public static void main(String[] args) throws IOException {
3536

3637
System.out.println("Reading input.");
3738
while ((str = in.readLine()) != null) {
38-
System.out.println("Detecting: "+str);
39+
System.out.println("Detecting: " + str);
3940
mappingDetector = new MappingDetector();
4041
testFiles.add(mappingDetector.detectMapping(str));
4142
}
4243

43-
System.out.println("Saving results. Total lines:"+ testFiles.size());
44+
System.out.println("Saving results. Total lines:" + testFiles.size());
4445
ResultsWriter resultsWriter = ResultsWriter.createResultsWriter();
4546
List<String> columnNames = new ArrayList<>();
4647
List<String> columnValues = null;
47-
columnNames.add(0,"App");
48-
columnNames.add(1,"Tag");
49-
columnNames.add(2,"TestFilePath");
50-
columnNames.add(3,"ProductionFilePath");
51-
columnNames.add(4,"RelativeTestFilePath");
52-
columnNames.add(5,"RelativeProductionFilePath");
48+
columnNames.add(0, "TestFilePath");
49+
columnNames.add(1, "ProductionFilePath");
5350
resultsWriter.writeColumnName(columnNames);
5451

5552
for (int i = 0; i < testFiles.size(); i++) {
5653
columnValues = new ArrayList<>();
57-
columnValues.add(0,testFiles.get(i).getAppName());
58-
columnValues.add(1,testFiles.get(i).getTagName());
59-
columnValues.add(2,testFiles.get(i).getFilePath());
60-
columnValues.add(3,testFiles.get(i).getProductionFilePath());
61-
columnValues.add(4,testFiles.get(i).getRelativeTestFilePath());
62-
columnValues.add(5,testFiles.get(i).getRelativeProductionFilePath());
54+
columnValues.add(0, testFiles.get(i).getTestFilePath());
55+
columnValues.add(1, testFiles.get(i).getProductionFilePath());
6356
resultsWriter.writeLine(columnValues);
6457
}
6558

src/main/java/edu/rit/se/testsmells/MappingDetector.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public MappingDetector() {
2525

2626

2727
public TestFile detectMapping(String testFilePath) throws IOException {
28-
29-
testFile = new TestFile(testFilePath);
28+
String[] data = testFilePath.split(",");
29+
testFile = new TestFile(data[0], data[1]);
3030

3131
int index = testFile.getFileName().toLowerCase().lastIndexOf("test");
3232
if (index == 0) {
Lines changed: 10 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
package edu.rit.se.testsmells;
22

3-
import org.apache.commons.lang3.StringUtils;
4-
53
public class TestFile {
6-
private String filePath, productionFilePath;
74
String[] data;
5+
private String testFilePath, productionFilePath, srcDirectory;
6+
7+
public TestFile(String srcDirectory, String testFilePath) {
8+
this.testFilePath = testFilePath;
9+
this.srcDirectory = srcDirectory;
10+
data = this.testFilePath.split("\\\\");
11+
}
812

913
public String getFileName() {
1014
return data[data.length - 1];
1115
}
1216

13-
public String getFilePath() {
14-
return filePath;
17+
public String getTestFilePath() {
18+
return testFilePath;
1519
}
1620

1721
public String getProductionFilePath() {
@@ -23,47 +27,7 @@ public void setProductionFilePath(String productionFilePath) {
2327
}
2428

2529
public String getProjectRootFolder() {
26-
StringBuilder stringBuilder = new StringBuilder();
27-
for (int i = 0; i < 5; i++) {
28-
stringBuilder.append(data[i] + "\\");
29-
}
30-
return stringBuilder.toString();
31-
}
32-
33-
public String getAppName() {
34-
return data[3];
35-
}
36-
37-
public String getTagName() {
38-
return data[4];
30+
return srcDirectory;
3931
}
4032

41-
public TestFile(String filePath) {
42-
this.filePath = filePath;
43-
data = filePath.split("\\\\");
44-
}
45-
46-
public String getRelativeTestFilePath(){
47-
String[] splitString = filePath.split("\\\\");
48-
StringBuilder stringBuilder = new StringBuilder();
49-
for (int i = 0; i < 5; i++) {
50-
stringBuilder.append(splitString[i] + "\\");
51-
}
52-
return filePath.substring(stringBuilder.toString().length()).replace("\\","/");
53-
}
54-
55-
public String getRelativeProductionFilePath(){
56-
if (!StringUtils.isEmpty(productionFilePath)){
57-
String[] splitString = productionFilePath.split("\\\\");
58-
StringBuilder stringBuilder = new StringBuilder();
59-
for (int i = 0; i < 5; i++) {
60-
stringBuilder.append(splitString[i] + "\\");
61-
}
62-
return productionFilePath.substring(stringBuilder.toString().length()).replace("\\","/");
63-
}
64-
else{
65-
return "";
66-
}
67-
68-
}
6933
}

0 commit comments

Comments
 (0)