Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorddunne2011-06-20 22:47:35 +0000
committerRyan D. Brooks2011-06-20 22:47:35 +0000
commit1bbd3685a3bd141173b0e84fed61e7a026b85338 (patch)
tree2085ff96415d03b8b9d9a6742253f95e77b264e9 /plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/UnitTestCounter.java
parent7600301ad0b762cd1298b899e805f5bd5832da59 (diff)
downloadorg.eclipse.osee-1bbd3685a3bd141173b0e84fed61e7a026b85338.tar.gz
org.eclipse.osee-1bbd3685a3bd141173b0e84fed61e7a026b85338.tar.xz
org.eclipse.osee-1bbd3685a3bd141173b0e84fed61e7a026b85338.zip
refactor: Cleanup and fix production tests
Diffstat (limited to 'plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/UnitTestCounter.java')
-rw-r--r--plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/UnitTestCounter.java63
1 files changed, 25 insertions, 38 deletions
diff --git a/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/UnitTestCounter.java b/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/UnitTestCounter.java
index db836f17793..e6fc563c541 100644
--- a/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/UnitTestCounter.java
+++ b/plugins/org.eclipse.osee.support.test.util/src/org/eclipse/osee/support/test/util/UnitTestCounter.java
@@ -12,14 +12,17 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Map.Entry;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import org.eclipse.osee.framework.jdk.core.type.CountingMap;
import org.eclipse.osee.framework.jdk.core.type.MutableInteger;
import org.eclipse.osee.framework.jdk.core.util.Lib;
import org.eclipse.osee.framework.jdk.core.util.Strings;
import org.eclipse.osee.framework.jdk.core.util.io.MatchFilter;
+/**
+ * Count all JUnit classes and sort/count by author
+ *
+ * @author Donald G. Dunne
+ */
public class UnitTestCounter {
private static int unitTestCount = 0, testPointCount = 0;
@@ -29,7 +32,8 @@ public class UnitTestCounter {
public static void main(String[] args) {
try {
- StringBuffer sb = new StringBuffer();
+ StringBuffer results = new StringBuffer();
+ StringBuffer errors = new StringBuffer();
for (String dirNam : Arrays.asList("C:\\UserData\\git\\org.eclipse.osee\\plugins\\",
"C:\\UserData\\git\\lba.osee\\plugins\\")) {
File dir1 = new File(dirNam);
@@ -39,11 +43,10 @@ public class UnitTestCounter {
}
System.out.println(String.format("Processing [%s]", filename));
File file = new File(dir1 + "\\" + filename);
- recurseAndFind(file, sb);
+ recurseAndFind(file, results, errors);
}
}
- StringBuffer results = new StringBuffer();
results.append("Test Unit Total (file with at least 1 test case), " + unitTestCount + "\n");
List<String> names = new ArrayList<String>();
@@ -68,57 +71,41 @@ public class UnitTestCounter {
}
results.append("\n\n");
- results.append(sb.toString());
+ results.append(results.toString());
+ System.err.println("\n\n" + errors);
String outputFilename = "C:\\UserData\\UnitTestCounter.csv";
System.out.println("\n\nResults written to " + outputFilename + "\n");
- Lib.writeStringToFile(results.toString(), new File(outputFilename));
+ Lib.writeStringToFile(errors.toString() + "\n\n" + results.toString(), new File(outputFilename));
} catch (Exception ex) {
System.out.println(ex.getLocalizedMessage());
}
}
- private static void recurseAndFind(File file, StringBuffer sb) throws IOException {
+ private static void recurseAndFind(File file, StringBuffer results, StringBuffer errors) throws IOException {
if (file.isDirectory()) {
for (String filename : Lib.readListFromDir(file, new MatchFilter(".*"), true)) {
File childFile = new File(file.getAbsolutePath() + "\\" + filename);
- recurseAndFind(childFile, sb);
+ recurseAndFind(childFile, results, errors);
}
}
if (file.getAbsolutePath().endsWith(".java") && !file.getName().contains("UnitTestCounter")) {
String text = Lib.fileToString(file);
- if (text.contains("@Test") || text.contains("@org.junit.Test")) {
+ if (UnitTestUtil.isUnitTest(text)) {
System.err.println("Found java test file " + file.getName());
- sb.append(file.getName() + ", ");
+ results.append(file.getName() + ", ");
unitTestCount++;
- for (String line : text.split("\n")) {
- if (line.contains("* @author")) {
- String author = line;
- System.out.println(" " + author);
- author = author.replaceAll(":", "");
- author = author.replaceAll(System.getProperty("line.separator"), "");
- author = author.replaceFirst("^.*@author *", "");
- author = author.replaceFirst(" *$", "");
- author = author.replaceAll("\\s+$", "");
- if (Strings.isValid(author)) {
-
- Matcher m = Pattern.compile("(@Test|@org.junit.Test)").matcher(text);
- int fileTestPointCount = 0;
- while (m.find()) {
- fileTestPointCount++;
- }
- if (fileTestPointCount > 0) {
- authorToFileCount.put(author);
- sb.append(author);
-
- testPointCount += fileTestPointCount;
- authorToTestPointCount.put(author, fileTestPointCount);
- }
- }
-
- }
+ List<String> authors = UnitTestUtil.getAuthors(text);
+ if (authors.isEmpty()) {
+ errors.append(String.format("File [%s] has no authors\n", file.getName()));
+ }
+ int fileTestPointCount = UnitTestUtil.getTestMethodCount(text);
+ for (String author : authors) {
+ results.append(author + "; ");
+ authorToFileCount.put(author);
+ authorToTestPointCount.put(author, fileTestPointCount);
}
- sb.append("\n");
+ results.append("\n");
} else {
System.err.println("NOT TEST FILE " + file.getName());
}

Back to the top