Skip to content

Commit 855a9c3

Browse files
2018SANER2018SANER
authored andcommitted
updated logic to check for 'test' in file name
1 parent da34dcc commit 855a9c3

1 file changed

Lines changed: 28 additions & 21 deletions

File tree

src/main/java/entity/FileEntity.java

Lines changed: 28 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package entity;
1+
package entity;
22

33
import java.nio.file.Path;
44
import java.util.List;
@@ -36,75 +36,82 @@ public void setTotalLines(int totalLines) {
3636
}
3737

3838
public long getTestMethodWithoutAnnotationCount() {
39-
return methods.parallelStream().filter((p)->p.isHasAnnotation()==false && p.isHasTestInName()==true).count();
39+
return methods.parallelStream().filter((p) -> p.isHasAnnotation() == false && p.isHasTestInName() == true).count();
4040
}
4141

4242
public String getFilePath() {
4343
return path.toAbsolutePath().toString();
4444
}
4545

4646
public long getTestAnnotationCount() {
47-
return methods.parallelStream().filter((p)->p.isHasAnnotation()).count();
47+
return methods.parallelStream().filter((p) -> p.isHasAnnotation()).count();
4848
}
4949

50-
public boolean isHasTestInFileName(){
51-
return path.getFileName().toString().toLowerCase().contains("test");
50+
public boolean isHasTestInFileName() {
51+
String fileName = getFileNameWithoutExtension().toLowerCase();
52+
if (fileName.startsWith("test") || fileName.startsWith("tests") || fileName.endsWith("test") || fileName.endsWith("tests"))
53+
return true;
54+
else
55+
return false;
5256
}
5357

54-
public String getFileName(){
58+
public String getFileName() {
5559
return path.getFileName().toString();
5660
}
5761

62+
public String getFileNameWithoutExtension() {
63+
String fileName = path.getFileName().toString().substring(0,path.getFileName().toString().toLowerCase().lastIndexOf(".java"));
64+
return fileName;
65+
}
66+
5867
public long getTotalTestMethods() {
5968
return (getTestMethodWithoutAnnotationCount() + getTestAnnotationCount());
6069
}
6170

62-
public boolean getHas_junitframeworkTest(){
71+
public boolean getHas_junitframeworkTest() {
6372
return imports.get("junit.framework.Test");
6473
}
6574

66-
public boolean getHas_junitframeworkTestCase(){
75+
public boolean getHas_junitframeworkTestCase() {
6776
return imports.get("junit.framework.TestCase");
6877
}
6978

70-
public boolean getHas_orgjunitTest(){
79+
public boolean getHas_orgjunitTest() {
7180
return imports.get("org.junit.Test");
7281
}
7382

74-
public boolean getHas_androidtestAndroidTestCase(){
83+
public boolean getHas_androidtestAndroidTestCase() {
7584
return imports.get("android.test.AndroidTestCase");
7685
}
7786

78-
public boolean getHas_androidtestInstrumentationTestCase()
79-
{
80-
return imports.get("android.test.InstrumentationTestCase");
87+
public boolean getHas_androidtestInstrumentationTestCase() {
88+
return imports.get("android.test.InstrumentationTestCase");
8189
}
8290

83-
public boolean getHas_androidtestActivityInstrumentationTestCase2()
84-
{
85-
return imports.get("android.test.ActivityInstrumentationTestCase2");
91+
public boolean getHas_androidtestActivityInstrumentationTestCase2() {
92+
return imports.get("android.test.ActivityInstrumentationTestCase2");
8693
}
8794

88-
public boolean getHas_orgjunitAssert(){
95+
public boolean getHas_orgjunitAssert() {
8996
return imports.get("org.junit.Assert");
9097
}
9198

92-
public String getRelativeFilePath(){
99+
public String getRelativeFilePath() {
93100
String filePath = path.toAbsolutePath().toString();
94101
String[] splitString = filePath.split("\\\\");
95102
StringBuilder stringBuilder = new StringBuilder();
96103
for (int i = 0; i < 5; i++) {
97104
stringBuilder.append(splitString[i] + "\\");
98105
}
99-
return filePath.substring(stringBuilder.toString().length()).replace("\\","/");
106+
return filePath.substring(stringBuilder.toString().length()).replace("\\", "/");
100107
}
101108

102-
public String getAppName(){
109+
public String getAppName() {
103110
String filePath = path.toAbsolutePath().toString();
104111
return filePath.split("\\\\")[3];
105112
}
106113

107-
public String getTagName(){
114+
public String getTagName() {
108115
String filePath = path.toAbsolutePath().toString();
109116
return filePath.split("\\\\")[4];
110117
}

0 commit comments

Comments
 (0)