-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTestFile.java
More file actions
72 lines (56 loc) · 1.83 KB
/
TestFile.java
File metadata and controls
72 lines (56 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
package edu.rit.se.testsmells;
import org.apache.commons.lang3.StringUtils;
import java.io.File;
import java.util.regex.Pattern;
public class TestFile {
private String filePath, productionFilePath;
private String[] data;
public TestFile(String filePath) {
this.filePath = filePath;
data = splitFilepath(filePath);
}
public String getFileName() {
return data[data.length - 1];
}
public String getUnixFilePath() {
return filePath;
}
public String getProductionFilePath() {
return productionFilePath;
}
public void setProductionFilePath(String productionFilePath) {
this.productionFilePath = productionFilePath;
}
public String getProjectRootFolder() {
return get5LevelsPath(data).toString();
}
public String getAppName() {
return data[3];
}
public String getTagName() {
return data[4];
}
public String getRelativeTestFilePath() {
return getUnixFilePath(filePath);
}
public String getRelativeProductionFilePath() {
if (!StringUtils.isEmpty(productionFilePath)) {
return getUnixFilePath(productionFilePath);
}
return "";
}
private String getUnixFilePath(String filePath) {
String[] splitString = splitFilepath(filePath);
return filePath.substring(get5LevelsPath(splitString).toString().length()).replace(File.separator, "/");
}
private StringBuilder get5LevelsPath(String[] splitString) {
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < 5; i++) {
stringBuilder.append(splitString[i]).append(File.separator);
}
return stringBuilder;
}
public String[] splitFilepath(String filePath) {
return filePath.split(Pattern.quote(File.separator));
}
}