1 19 20 package org.netbeans.modules.junit.output.antutils; 21 22 import org.apache.tools.ant.module.spi.AntEvent; 23 import org.apache.tools.ant.module.spi.TaskStructure; 24 import org.netbeans.modules.junit.output.JUnitAntLogger; 25 26 31 public final class TestCounter { 32 33 34 36 37 45 public static int getTestClassCount(AntEvent event) { 46 TestCounter counter = new TestCounter(event); 47 return counter.countTestClasses(); 48 } 49 50 51 53 54 58 private final AntEvent event; 59 60 66 private TestCounter(AntEvent event) { 67 this.event = event; 68 } 69 70 76 private int countTestClasses() { 77 final String taskName = event.getTaskName(); 78 79 if (taskName.equals(JUnitAntLogger.TASK_JUNIT)) { 80 return countTestClassesInJUnitTask(); 81 } else if (taskName.equals(JUnitAntLogger.TASK_JAVA)) { 82 return countTestClassesInJavaTask(); 83 } 84 85 assert false : "Unhandled task name"; return -1; 87 } 88 89 97 private int countTestClassesInJUnitTask() { 98 int count = 0; 99 100 TaskStructure taskStruct = event.getTaskStructure(); 101 for (TaskStructure child : taskStruct.getChildren()) { 102 String childName = child.getName(); 103 if (childName.equals("test")) { if (conditionsMet(child)) { 105 count++; 106 } 107 continue; 108 } 109 if (childName.equals("batchtest")) { if (conditionsMet(child)) { 111 AntProject project = new AntProject(event); 112 BatchTest batchTest = new BatchTest(project); 113 batchTest.handleChildrenAndAttrs(child); 114 int n = batchTest.countTestClasses(); 115 if (n > 0) { 116 count += n; 117 } 118 } 119 continue; 120 } 121 } 122 return count; 123 } 124 125 134 private boolean conditionsMet(TaskStructure struct) { 135 String ifPropName = struct.getAttribute("if"); String unlessPropName = struct.getAttribute("unless"); 138 if ((ifPropName != null) 139 && (event.getProperty(ifPropName) == null)) { 140 return false; 141 } 142 if ((unlessPropName != null) 143 && (event.getProperty(unlessPropName) != null)) { 144 return false; 145 } 146 return true; 147 } 148 149 157 private int countTestClassesInJavaTask() { 158 return 1; 159 } 160 161 } 162 | Popular Tags |