I'm developing a tool that recognizes test classes and counts the number of lines in those classes. The tool will also count the lines of the business code and compare the both results, here is my code:
for (File f : list) {
if (f.isDirectory()) {
walk(f.getAbsolutePath());
}
if (f.getName().endsWith(".java")) {
System.out.println("File:" + f.getName());
countFiles++;
Scanner testScanner = new Scanner(f);
while (testScanner.hasNextLine()) {
String test = testScanner.nextLine();
if (test.contains("org.junit") || test.contains("org.mockito")) {
System.out.println("this is a test class");
testCounter++;
break;
}
}
Scanner sc2 = new Scanner(f);
while (sc2.hasNextLine()) {
count++;
counting the business code using (count++) is working perfectly, but counting the number of code in test classes is not working using (testCounter++) is returning the number of test classes rather than the number of lines in those classes! what can I do ?
Thanks
Assuming that you are wanting to count the number of lines that contain either
org.junit or org.mockito
then you want to do