Skip to content

Commit

Permalink
Updated the project to remove references to "app" and "tag" in the de…
Browse files Browse the repository at this point in the history
…tection/output as this is no longer required. Updated the README.md with details on how to run the tool.
  • Loading branch information
shehan committed Mar 23, 2022
1 parent 874494d commit 092139f
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 65 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,22 @@
# TestFileMapping
This program maps the specified test file with the the production (SUT) file

## Prerequisites
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.

Example of the structure of this file:

`
C:\Projects\MyProject\src\main,C:\Projects\MyProject\src\test\java\org\example\common\PluginResourceBundleTest.java
C:\Projects\MyProject\src\main,C:\Projects\MyProject\src\test\java\org\example\inspection\ConditionalInspectionTest.java
C:\Projects\MyProject\src\main,C:\Projects\MyProject\src\test\java\org\example\inspection\DuplicateInspectionTest.java
C:\Projects\MyProject\src\main,C:\Projects\MyProject\src\test\java\org\example\inspection\GeneralInspectionTest.java
`

## Usage
Run the jar file:

`C:\Projects\TestFileMapping>java -jar TestFileMapping.jar C:\Work\input.csv`

## Output
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).
27 changes: 10 additions & 17 deletions src/main/java/edu/rit/se/testsmells/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@ public class Main {
static List<TestFile> testFiles;

public static void main(String[] args) throws IOException {
if (args == null) {
if (args == null || args.length == 0) {
System.out.println("Please provide the file containing the paths to the collection of test files");
return;
}
if(!args[0].isEmpty()){

if (!args[0].isEmpty()) {
File inputFile = new File(args[0]);
if(!inputFile.exists() || inputFile.isDirectory()) {
if (!inputFile.exists() || inputFile.isDirectory()) {
System.out.println("Please provide a valid file containing the paths to the collection of test files");
return;
}
Expand All @@ -35,31 +36,23 @@ public static void main(String[] args) throws IOException {

System.out.println("Reading input.");
while ((str = in.readLine()) != null) {
System.out.println("Detecting: "+str);
System.out.println("Detecting: " + str);
mappingDetector = new MappingDetector();
testFiles.add(mappingDetector.detectMapping(str));
}

System.out.println("Saving results. Total lines:"+ testFiles.size());
System.out.println("Saving results. Total lines:" + testFiles.size());
ResultsWriter resultsWriter = ResultsWriter.createResultsWriter();
List<String> columnNames = new ArrayList<>();
List<String> columnValues = null;
columnNames.add(0,"App");
columnNames.add(1,"Tag");
columnNames.add(2,"TestFilePath");
columnNames.add(3,"ProductionFilePath");
columnNames.add(4,"RelativeTestFilePath");
columnNames.add(5,"RelativeProductionFilePath");
columnNames.add(0, "TestFilePath");
columnNames.add(1, "ProductionFilePath");
resultsWriter.writeColumnName(columnNames);

for (int i = 0; i < testFiles.size(); i++) {
columnValues = new ArrayList<>();
columnValues.add(0,testFiles.get(i).getAppName());
columnValues.add(1,testFiles.get(i).getTagName());
columnValues.add(2,testFiles.get(i).getFilePath());
columnValues.add(3,testFiles.get(i).getProductionFilePath());
columnValues.add(4,testFiles.get(i).getRelativeTestFilePath());
columnValues.add(5,testFiles.get(i).getRelativeProductionFilePath());
columnValues.add(0, testFiles.get(i).getTestFilePath());
columnValues.add(1, testFiles.get(i).getProductionFilePath());
resultsWriter.writeLine(columnValues);
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/edu/rit/se/testsmells/MappingDetector.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public MappingDetector() {


public TestFile detectMapping(String testFilePath) throws IOException {

testFile = new TestFile(testFilePath);
String[] data = testFilePath.split(",");
testFile = new TestFile(data[0], data[1]);

int index = testFile.getFileName().toLowerCase().lastIndexOf("test");
if (index == 0) {
Expand Down
56 changes: 10 additions & 46 deletions src/main/java/edu/rit/se/testsmells/TestFile.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
package edu.rit.se.testsmells;

import org.apache.commons.lang3.StringUtils;

public class TestFile {
private String filePath, productionFilePath;
String[] data;
private String testFilePath, productionFilePath, srcDirectory;

public TestFile(String srcDirectory, String testFilePath) {
this.testFilePath = testFilePath;
this.srcDirectory = srcDirectory;
data = this.testFilePath.split("\\\\");
}

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

public String getFilePath() {
return filePath;
public String getTestFilePath() {
return testFilePath;
}

public String getProductionFilePath() {
Expand All @@ -23,47 +27,7 @@ public void setProductionFilePath(String productionFilePath) {
}

public String getProjectRootFolder() {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 5; i++) {
stringBuilder.append(data[i] + "\\");
}
return stringBuilder.toString();
}

public String getAppName() {
return data[3];
}

public String getTagName() {
return data[4];
return srcDirectory;
}

public TestFile(String filePath) {
this.filePath = filePath;
data = filePath.split("\\\\");
}

public String getRelativeTestFilePath(){
String[] splitString = filePath.split("\\\\");
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 5; i++) {
stringBuilder.append(splitString[i] + "\\");
}
return filePath.substring(stringBuilder.toString().length()).replace("\\","/");
}

public String getRelativeProductionFilePath(){
if (!StringUtils.isEmpty(productionFilePath)){
String[] splitString = productionFilePath.split("\\\\");
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 5; i++) {
stringBuilder.append(splitString[i] + "\\");
}
return productionFilePath.substring(stringBuilder.toString().length()).replace("\\","/");
}
else{
return "";
}

}
}

0 comments on commit 092139f

Please sign in to comment.