Skip to content

Commit 5a6650e

Browse files
committed
Removed redundant columns from the ouput file. Updated the instructions in README.md
1 parent 2598f2c commit 5a6650e

File tree

4 files changed

+54
-78
lines changed

4 files changed

+54
-78
lines changed

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,15 @@
1-
The purpose of this tool is to detect java files that contain unit test methods. The results of the tools execution will saved in a CSV file for further processing (by other tools) or to imported into a database.
1+
The purpose of this tool is to detect java files that contain unit test methods. The results of the tools execution will
2+
saved in a CSV file for further processing (by other tools) or to imported into a database.
3+
4+
## Usage
5+
6+
To run the jar file, pass the project directory. The tool will iterate through all subdirectories to detect JUnit-based
7+
test files
8+
9+
`C:\Projects\TestFileDetector>java -jar TestFileDetector.jar C:\MyProject`
10+
11+
## Output
12+
13+
The output csv file will be saved in the same directory as the jar. The file will start with the name 'Output_Class_'.
14+
This file will contain details such as the number of test methods in the file and the use of JUnit specific import
15+
statements.

src/main/java/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
public class Main {
1010
public static void main(String[] args) throws IOException {
11-
if (args == null) {
11+
if (args == null || args.length == 0) {
1212
System.out.println("Please provide the path to the project directory");
1313
return;
1414
}

src/main/java/ResultsWriter.java

Lines changed: 38 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@ private ResultsWriter() throws IOException {
3333
private void createDebtFile() throws IOException {
3434
List<String[]> fileLines = new ArrayList<String[]>();
3535
String[] columnNames = {
36-
"App",
37-
"Tag",
3836
"FilePath",
39-
"RelativeFilePath",
4037
"FileName",
4138
"ClassName",
4239
"Comment"
@@ -50,10 +47,7 @@ private void createDebtFile() throws IOException {
5047
private void createClassFile() throws IOException {
5148
List<String[]> fileLines = new ArrayList<String[]>();
5249
String[] columnNames = {
53-
"App",
54-
"Tag",
5550
"FilePath",
56-
"RelativeFilePath",
5751
"FileName",
5852
"ClassName",
5953
"TotalImports",
@@ -82,10 +76,7 @@ private void createClassFile() throws IOException {
8276
private void createMethodFile() throws IOException {
8377
List<String[]> fileLines = new ArrayList<String[]>();
8478
String[] columnNames = {
85-
"App",
86-
"Tag",
8779
"FilePath",
88-
"RelativeFilePath",
8980
"FileName",
9081
"ClassName",
9182
"MethodName",
@@ -115,14 +106,11 @@ private void outputDebtDetails(ClassEntity classEntity) throws IOException {
115106
String[] dataLine;
116107
for (String comment : classEntity.getTechnicalDebtComments()) {
117108

118-
dataLine = new String[7];
119-
dataLine[0] = classEntity.getAppName();
120-
dataLine[1] = classEntity.getTagName();
121-
dataLine[2] = classEntity.getFilePath();
122-
dataLine[3] = classEntity.getRelativeFilePath();
123-
dataLine[4] = classEntity.getFileName();
124-
dataLine[5] = classEntity.getClassName();
125-
dataLine[6] = "\""+comment.replace('"',' ')+"\"";
109+
dataLine = new String[4];
110+
dataLine[0] = classEntity.getFilePath();
111+
dataLine[1] = classEntity.getFileName();
112+
dataLine[2] = classEntity.getClassName();
113+
dataLine[3] = "\""+comment.replace('"',' ')+"\"";
126114

127115
fileLines.add(dataLine);
128116
}
@@ -141,22 +129,19 @@ private void outputMethodDetails(ClassEntity classEntity) throws IOException {
141129
String[] dataLine;
142130
for (MethodEntity methodEntity : classEntity.getMethods()) {
143131

144-
dataLine = new String[15];
145-
dataLine[0] = classEntity.getAppName();
146-
dataLine[1] = classEntity.getTagName();
147-
dataLine[2] = classEntity.getFilePath();
148-
dataLine[3] = classEntity.getRelativeFilePath();
149-
dataLine[4] = classEntity.getFileName();
150-
dataLine[5] = classEntity.getClassName();
151-
dataLine[6] = methodEntity.getMethodName();
152-
dataLine[7] = String.valueOf(methodEntity.getTotalStatements());
153-
dataLine[8] = String.valueOf(methodEntity.getParameterCount());
154-
dataLine[9] = methodEntity.getReturnType();
155-
dataLine[10] = methodEntity.getAccessModifier();
156-
dataLine[11] = String.valueOf(methodEntity.isHasAnnotation());
157-
dataLine[12] = String.valueOf(methodEntity.isHasTestInName());
158-
dataLine[13] = String.valueOf(classEntity.isHasTestInFileName());
159-
dataLine[14] = String.valueOf(classEntity.isHasTestInClassName());
132+
dataLine = new String[12];
133+
dataLine[0] = classEntity.getFilePath();
134+
dataLine[1] = classEntity.getFileName();
135+
dataLine[2] = classEntity.getClassName();
136+
dataLine[3] = methodEntity.getMethodName();
137+
dataLine[4] = String.valueOf(methodEntity.getTotalStatements());
138+
dataLine[5] = String.valueOf(methodEntity.getParameterCount());
139+
dataLine[6] = methodEntity.getReturnType();
140+
dataLine[7] = methodEntity.getAccessModifier();
141+
dataLine[8] = String.valueOf(methodEntity.isHasAnnotation());
142+
dataLine[9] = String.valueOf(methodEntity.isHasTestInName());
143+
dataLine[10] = String.valueOf(classEntity.isHasTestInFileName());
144+
dataLine[11] = String.valueOf(classEntity.isHasTestInClassName());
160145

161146
fileLines.add(dataLine);
162147
}
@@ -168,29 +153,26 @@ private void outputClassDetails(ClassEntity classEntity) throws IOException {
168153
List<String[]> fileLines = new ArrayList<String[]>();
169154
String[] dataLine;
170155

171-
dataLine = new String[22];
172-
dataLine[0] = classEntity.getAppName();
173-
dataLine[1] = classEntity.getTagName();
174-
dataLine[2] = classEntity.getFilePath();
175-
dataLine[3] = classEntity.getRelativeFilePath();
176-
dataLine[4] = classEntity.getFileName();
177-
dataLine[5] = classEntity.getClassName();
178-
dataLine[6] = String.valueOf(classEntity.getTotalImports());
179-
dataLine[7] = String.valueOf(classEntity.getTotalMethods());
180-
dataLine[8] = String.valueOf(classEntity.getTotalMethodStatement());
181-
dataLine[9] = String.valueOf(classEntity.getTotalTestMethods());
182-
dataLine[10] = String.valueOf(classEntity.getTestAnnotationCount());
183-
dataLine[11] = String.valueOf(classEntity.getTestMethodWithoutAnnotationCount());
184-
dataLine[12] = String.valueOf(classEntity.isHasTestInFileName());
185-
dataLine[13] = String.valueOf(classEntity.isHasTestInClassName());
186-
dataLine[14] = String.valueOf(classEntity.getHas_junitframeworkTest());
187-
dataLine[15] = String.valueOf(classEntity.getHas_junitframeworkTestCase());
188-
dataLine[16] = String.valueOf(classEntity.getHas_orgjunitTest());
189-
dataLine[17] = String.valueOf(classEntity.getHas_androidtestAndroidTestCase());
190-
dataLine[18] = String.valueOf(classEntity.getHas_androidtestInstrumentationTestCase());
191-
dataLine[19] = String.valueOf(classEntity.getHas_orgjunitAssert());
192-
dataLine[20] = String.valueOf(classEntity.getHas_androidtestActivityInstrumentationTestCase2());
193-
dataLine[21] = String.valueOf(classEntity.getHasTechnicalDebtComments());
156+
dataLine = new String[19];
157+
dataLine[0] = classEntity.getFilePath();
158+
dataLine[1] = classEntity.getFileName();
159+
dataLine[2] = classEntity.getClassName();
160+
dataLine[3] = String.valueOf(classEntity.getTotalImports());
161+
dataLine[4] = String.valueOf(classEntity.getTotalMethods());
162+
dataLine[5] = String.valueOf(classEntity.getTotalMethodStatement());
163+
dataLine[6] = String.valueOf(classEntity.getTotalTestMethods());
164+
dataLine[7] = String.valueOf(classEntity.getTestAnnotationCount());
165+
dataLine[8] = String.valueOf(classEntity.getTestMethodWithoutAnnotationCount());
166+
dataLine[9] = String.valueOf(classEntity.isHasTestInFileName());
167+
dataLine[10] = String.valueOf(classEntity.isHasTestInClassName());
168+
dataLine[11] = String.valueOf(classEntity.getHas_junitframeworkTest());
169+
dataLine[12] = String.valueOf(classEntity.getHas_junitframeworkTestCase());
170+
dataLine[13] = String.valueOf(classEntity.getHas_orgjunitTest());
171+
dataLine[14] = String.valueOf(classEntity.getHas_androidtestAndroidTestCase());
172+
dataLine[15] = String.valueOf(classEntity.getHas_androidtestInstrumentationTestCase());
173+
dataLine[16] = String.valueOf(classEntity.getHas_orgjunitAssert());
174+
dataLine[17] = String.valueOf(classEntity.getHas_androidtestActivityInstrumentationTestCase2());
175+
dataLine[18] = String.valueOf(classEntity.getHasTechnicalDebtComments());
194176

195177
fileLines.add(dataLine);
196178

src/main/java/entity/ClassEntity.java

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -115,26 +115,6 @@ public boolean getHas_orgjunitAssert() {
115115
return imports.stream().anyMatch(i -> i.equals("org.junit.Assert"));
116116
}
117117

118-
public String getRelativeFilePath() {
119-
String filePath = path.toAbsolutePath().toString();
120-
String[] splitString = filePath.split("\\\\");
121-
StringBuilder stringBuilder = new StringBuilder();
122-
for (int i = 0; i < 5; i++) {
123-
stringBuilder.append(splitString[i] + "\\");
124-
}
125-
return filePath.substring(stringBuilder.toString().length()).replace("\\", "/");
126-
}
127-
128-
public String getAppName() {
129-
String filePath = path.toAbsolutePath().toString();
130-
return filePath.split("\\\\")[3];
131-
}
132-
133-
public String getTagName() {
134-
String filePath = path.toAbsolutePath().toString();
135-
return filePath.split("\\\\")[4];
136-
}
137-
138118
public ArrayList<String> getTechnicalDebtComments() {
139119
return technicalDebtComments;
140120
}

0 commit comments

Comments
 (0)