package org.adligo.tests;

import java.util.HashMap;
import java.util.Map;

import org.adligo.i.log.shared.Log;
import org.adligo.i.log.shared.LogFactory;

import com.sun.org.apache.xerces.internal.impl.dv.dtd.NMTOKENDatatypeValidator;

/**
 * This is just a helper class to log assertions at the test level
 * outside of the test log, so that the number of assertions can be tracked
 * to improve test quality.  To use 
 * extend ATest and instantiate a number of classes which extend AAssertions
 * then call this in a method with the @AfterClass annotation
 * 
 * @author scott
 *
 */
public class AssertionStats {
	private static final Log log = LogFactory.getLog(AssertionStats.class);
	private static final Map<String, Integer> packageAsserts = new HashMap<String, Integer>();
	
	public static synchronized void logAssertionStats(Class<?> testClass, String packageName, int numAssertions) {
		if (log.isInfoEnabled()) {
			log.info("Test class " + testClass + " had " + numAssertions + " assertions.");
		}
		Integer currentCount = packageAsserts.get(packageName);
		if (currentCount == null) {
			currentCount = numAssertions;
			packageAsserts.put(packageName, numAssertions);
		} else {
			currentCount = currentCount + numAssertions;
			packageAsserts.put(packageName, currentCount);
		}
		log.warn("The package " + packageName + " now has " + currentCount + " assertions.");
	}
	
	public static synchronized void logAssertionStats(Class<?> testClass, AAssertions asserts) {
		logAssertionStats(testClass, asserts.getPackage(), asserts.getAssertionCount());
	}
}

@@ -611,16 +611,168 @@
 Stats %7B%0A
+%09private static final String ALL_OF_THE_PACKAGES_MUST_MATCH_FOR_A_ARRAY_OF_A_ASSERTIONS = %22All of the packages must match for a array of AAssertions.%22;%0A
 %09private
@@ -1618,16 +1618,20 @@
 sertions
+ ...
  asserts
@@ -1634,16 +1634,46 @@
 erts) %7B%0A
+%09%09if (asserts.length == 1) %7B%0A%09
 %09%09logAss
@@ -1698,24 +1698,27 @@
 ass, asserts
+%5B0%5D
 .getPackage(
@@ -1723,24 +1723,27 @@
 e(), asserts
+%5B0%5D
 .getAssertio
@@ -1753,13 +1753,459 @@
 unt());%0A
+%09%09%7D else %7B%0A%09%09%09String packageName = asserts%5B0%5D.getPackage();%0A%09%09%09int total = 0;%0A%09%09%09for (int i = 0; i %3C asserts.length; i++) %7B%0A%09%09%09%09AAssertions aas = asserts%5Bi%5D;%0A%09%09%09%09String pkg = aas.getPackage();%0A%09%09%09%09if (!packageName.equals(pkg)) %7B%0A%09%09%09%09%09throw new IllegalArgumentException(ALL_OF_THE_PACKAGES_MUST_MATCH_FOR_A_ARRAY_OF_A_ASSERTIONS);%0A%09%09%09%09%7D%0A%09%09%09%09total = total + aas.getAssertionCount();%0A%09%09%09%7D%0A%09%09%09logAssertionStats(testClass, packageName, total);%0A%09%09%7D%0A%09%09%0A
 %09%7D%0A%7D%0A

test helper method