com.objectfab.tools.junitdoclet
Class DefaultTestingStrategy

java.lang.Object
  extended bycom.objectfab.tools.junitdoclet.DefaultConfigurableStrategy
      extended bycom.objectfab.tools.junitdoclet.DefaultTestingStrategy
All Implemented Interfaces:
ConfigurableStrategy, JUnitDocletProperties, TestingStrategy

public class DefaultTestingStrategy
extends DefaultConfigurableStrategy
implements TestingStrategy, JUnitDocletProperties


Field Summary
protected static java.lang.String[][] ACCESSOR_STARTS_WITH
           
protected static int INDEX_GET
           
protected static int INDEX_SET
           
protected static java.lang.String JUNIT_TEST_CLASS_NAME
           
static java.lang.String[] MINIMUM_MARKER_SET
           
private static java.lang.String[] requiredStrings
           
protected static java.lang.String TESTSUITE_SUITE_METHOD_NAME
           
 
Fields inherited from class com.objectfab.tools.junitdoclet.DefaultConfigurableStrategy
DEFAULT_PROPERTY_FILE_NAME
 
Fields inherited from interface com.objectfab.tools.junitdoclet.JUnitDocletProperties
ACCESSOR_GET_NAME, ACCESSOR_NAME, ACCESSOR_SET_NAME, ACCESSOR_TESTS, ACCESSOR_TYPE_NAME, ADD_IMPORT_NAME, ADD_IMPORT_TESTSUITE, ADD_TESTCASE_NAME, ADD_TESTCASE_TO_TESTSUITE, ADD_TESTSUITE_NAME, ADD_TESTSUITE_TO_TESTSUITE, CLASS_NAME, JUNIT_VERSION, LICENSE, MARKER_CLASS_BEGIN, MARKER_CLASS_END, MARKER_EXTENDS_IMPLEMENTS_BEGIN, MARKER_EXTENDS_IMPLEMENTS_END, MARKER_IMPORT_BEGIN, MARKER_IMPORT_END, MARKER_JAVADOC_CLASS_BEGIN, MARKER_JAVADOC_CLASS_END, MARKER_JAVADOC_METHOD_BEGIN, MARKER_JAVADOC_METHOD_END, MARKER_METHOD_BEGIN, MARKER_METHOD_END, METHOD_NAME, METHOD_SIGNATURE, PACKAGE_NAME, TEMPLATE_ATTRIBUTE_ACCESSOR, TEMPLATE_ATTRIBUTE_ARRAY, TEMPLATE_ATTRIBUTE_DEFAULT, TEMPLATE_NAME, TESTCASE_CLASS_NAME, TESTCASE_INSTANCE_NAME, TESTCASE_INSTANCE_TYPE, TESTCASE_METHOD_UNMATCHED, TESTCASE_PACKAGE_NAME, TESTCASE_TESTMETHODS, TESTCASE_UNMATCHED, TESTMETHOD_NAME, TESTSUITE_ADD_TESTCASES, TESTSUITE_ADD_TESTSUITES, TESTSUITE_CLASS_NAME, TESTSUITE_IMPORTS, TESTSUITE_INSTANCE_NAME, TESTSUITE_PACKAGE_NAME, VALUE_LICENSE, VALUE_MARKER_BEGIN, VALUE_MARKER_CLASS, VALUE_MARKER_CLASS_BEGIN, VALUE_MARKER_CLASS_END, VALUE_MARKER_END, VALUE_MARKER_EXTENDS_IMPLEMENTS, VALUE_MARKER_EXTENDS_IMPLEMENTS_BEGIN, VALUE_MARKER_EXTENDS_IMPLEMENTS_END, VALUE_MARKER_IMPORT, VALUE_MARKER_IMPORT_BEGIN, VALUE_MARKER_IMPORT_END, VALUE_MARKER_JAVADOC_CLASS, VALUE_MARKER_JAVADOC_CLASS_BEGIN, VALUE_MARKER_JAVADOC_CLASS_END, VALUE_MARKER_JAVADOC_METHOD, VALUE_MARKER_JAVADOC_METHOD_BEGIN, VALUE_MARKER_JAVADOC_METHOD_END, VALUE_MARKER_METHOD, VALUE_MARKER_METHOD_BEGIN, VALUE_MARKER_METHOD_END, VALUE_METHOD_UNMATCHED_NAME, VALUE_METHOD_UNMATCHED_NAME_MARKER
 
Constructor Summary
DefaultTestingStrategy()
           
 
Method Summary
 boolean codeTest(com.sun.javadoc.MethodDoc[] methodDocs, int index, com.sun.javadoc.ClassDoc classDoc, com.sun.javadoc.PackageDoc packageDoc, NamingStrategy naming, java.lang.StringBuffer newCode, java.util.Properties properties)
           
 boolean codeTestCase(com.sun.javadoc.ClassDoc classDoc, com.sun.javadoc.PackageDoc packageDoc, NamingStrategy naming, java.lang.StringBuffer newCode, java.util.Properties properties)
           
 boolean codeTestSuite(com.sun.javadoc.PackageDoc[] packageDocs, int indexPackage, NamingStrategy naming, java.lang.StringBuffer newCode, java.util.Properties properties)
           
 boolean containsCodeOrComment(java.lang.String markContent)
           
 int countTestableMethodsWithName(com.sun.javadoc.MethodDoc[] methodDocs, java.lang.String methodName)
           
 java.lang.String getAccessedPropertyName(java.lang.String accessorMethodName, int indexAccessorPair)
           
 int getAccessorPairIndex(com.sun.javadoc.MethodDoc[] methodDocs, int index)
          A method is considered an accessor if (i) method name starts with certain prefixes, (ii) prefix is followed by a property name (that is longer than the empyt string ""), (iii) there are methods with this property name for both 'get' and 'set' prefixes, (iv) number of parameters for the get method is 0 and number of parameter for the set method is 1.
 java.lang.String getAccessorTestsByType(java.util.Properties properties, java.lang.String templateAttribute, java.lang.String type)
           
 com.sun.javadoc.PackageDoc[] getDirectSubPackages(com.sun.javadoc.PackageDoc[] packageDocs, int indexCurrentPackage)
           
private static int getNumberOfParameters(com.sun.javadoc.MethodDoc methodDoc)
          Comment on DBC:
\@pre methodDoc != null
 java.util.Properties getTestAccessorProperties(com.sun.javadoc.MethodDoc[] methodDocs, int index, com.sun.javadoc.ClassDoc classDoc, com.sun.javadoc.PackageDoc packageDoc, NamingStrategy naming, java.util.Properties properties)
          Builds accessor specific properties if the method specified by 'index' is an accessor method.
 java.util.Properties getTestCaseProperties(com.sun.javadoc.ClassDoc classDoc, com.sun.javadoc.PackageDoc packageDoc, NamingStrategy naming, java.util.Properties properties)
          Comment on DBC:
\@pre (classDoc != null) && (packageDoc != null) && (naming != null) && (properties != null)
\@post return != null
private  java.lang.String getTestMethods(com.sun.javadoc.ClassDoc classDoc, com.sun.javadoc.PackageDoc packageDoc, NamingStrategy naming, java.util.Properties properties)
           
 java.util.Properties getTestProperties(com.sun.javadoc.MethodDoc[] methodDocs, int index, com.sun.javadoc.ClassDoc classDoc, com.sun.javadoc.PackageDoc packageDoc, NamingStrategy naming, java.util.Properties properties)
          Comment on DBC:
\@pre (methodDoc != null) && (classDoc != null) && (packageDoc != null) && (naming != null) && (properties != null)
 java.lang.String getTestSuiteAddTestCases(com.sun.javadoc.PackageDoc[] packageDocs, int indexPackage, NamingStrategy naming, java.util.Properties properties)
           
 java.lang.String getTestSuiteAddTestSuites(com.sun.javadoc.PackageDoc[] packageDocs, int indexPackage, NamingStrategy naming, java.util.Properties properties)
           
 java.lang.String getTestSuiteImports(com.sun.javadoc.PackageDoc[] packageDocs, int indexPackage, NamingStrategy naming, java.util.Properties properties)
           
 java.util.Properties getTestSuiteProperties(com.sun.javadoc.PackageDoc[] packageDocs, int indexPackage, NamingStrategy naming, java.util.Properties properties)
           
 boolean hasAllRequiredStrings(java.lang.String code)
           
 boolean hasSuiteMethod(com.sun.javadoc.ClassDoc doc)
           
 boolean hasUnmatchedMarkers(java.lang.String code)
           
 void init()
           
 boolean isATest(com.sun.javadoc.ClassDoc doc)
           
 boolean isFirstTestableMethodWithName(com.sun.javadoc.MethodDoc[] methodDocs, int index)
           
 boolean isInnerClass(com.sun.javadoc.ClassDoc doc)
           
 boolean isTestableClass(com.sun.javadoc.ClassDoc doc, NamingStrategy naming)
           
 boolean isTestableMethod(com.sun.javadoc.MethodDoc doc)
           
 boolean isTestablePackage(com.sun.javadoc.PackageDoc doc, NamingStrategy naming)
           
 boolean isValid(java.lang.String code)
           
 boolean isValidStructure(java.lang.String code)
           
 boolean merge(java.lang.StringBuffer inOutCode, java.lang.StringBuffer inCode, java.lang.String fullClassName)
          Merges all markers from inCode into inOutCode.
 
Methods inherited from class com.objectfab.tools.junitdoclet.DefaultConfigurableStrategy
createTemplate, getProperties, getPropertyFileName, getTemplate, loadProperties, printError, printNotice, printWarning, setDocErrorReporter, setProperties, setPropertyFileName
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.objectfab.tools.junitdoclet.ConfigurableStrategy
getProperties, getPropertyFileName, printError, printNotice, printWarning, setDocErrorReporter, setProperties, setPropertyFileName
 

Field Detail

TESTSUITE_SUITE_METHOD_NAME

protected static final java.lang.String TESTSUITE_SUITE_METHOD_NAME
See Also:
Constant Field Values

JUNIT_TEST_CLASS_NAME

protected static final java.lang.String JUNIT_TEST_CLASS_NAME
See Also:
Constant Field Values

ACCESSOR_STARTS_WITH

protected static final java.lang.String[][] ACCESSOR_STARTS_WITH

INDEX_SET

protected static int INDEX_SET

INDEX_GET

protected static int INDEX_GET

requiredStrings

private static java.lang.String[] requiredStrings

MINIMUM_MARKER_SET

public static final java.lang.String[] MINIMUM_MARKER_SET
Constructor Detail

DefaultTestingStrategy

public DefaultTestingStrategy()
Method Detail

init

public void init()
Specified by:
init in interface ConfigurableStrategy
Overrides:
init in class DefaultConfigurableStrategy

isTestablePackage

public boolean isTestablePackage(com.sun.javadoc.PackageDoc doc,
                                 NamingStrategy naming)
Specified by:
isTestablePackage in interface TestingStrategy

isTestableClass

public boolean isTestableClass(com.sun.javadoc.ClassDoc doc,
                               NamingStrategy naming)
Specified by:
isTestableClass in interface TestingStrategy

isTestableMethod

public boolean isTestableMethod(com.sun.javadoc.MethodDoc doc)

codeTestSuite

public boolean codeTestSuite(com.sun.javadoc.PackageDoc[] packageDocs,
                             int indexPackage,
                             NamingStrategy naming,
                             java.lang.StringBuffer newCode,
                             java.util.Properties properties)
Specified by:
codeTestSuite in interface TestingStrategy

codeTestCase

public boolean codeTestCase(com.sun.javadoc.ClassDoc classDoc,
                            com.sun.javadoc.PackageDoc packageDoc,
                            NamingStrategy naming,
                            java.lang.StringBuffer newCode,
                            java.util.Properties properties)
Specified by:
codeTestCase in interface TestingStrategy

codeTest

public boolean codeTest(com.sun.javadoc.MethodDoc[] methodDocs,
                        int index,
                        com.sun.javadoc.ClassDoc classDoc,
                        com.sun.javadoc.PackageDoc packageDoc,
                        NamingStrategy naming,
                        java.lang.StringBuffer newCode,
                        java.util.Properties properties)

getTestSuiteProperties

public java.util.Properties getTestSuiteProperties(com.sun.javadoc.PackageDoc[] packageDocs,
                                                   int indexPackage,
                                                   NamingStrategy naming,
                                                   java.util.Properties properties)
Specified by:
getTestSuiteProperties in interface TestingStrategy

getTestCaseProperties

public java.util.Properties getTestCaseProperties(com.sun.javadoc.ClassDoc classDoc,
                                                  com.sun.javadoc.PackageDoc packageDoc,
                                                  NamingStrategy naming,
                                                  java.util.Properties properties)
Comment on DBC:
\@pre (classDoc != null) && (packageDoc != null) && (naming != null) && (properties != null)
\@post return != null

Specified by:
getTestCaseProperties in interface TestingStrategy
Returns:
new Properties instance with all properties for parameter 'properties' and test case specific properties

getTestMethods

private java.lang.String getTestMethods(com.sun.javadoc.ClassDoc classDoc,
                                        com.sun.javadoc.PackageDoc packageDoc,
                                        NamingStrategy naming,
                                        java.util.Properties properties)

getTestProperties

public java.util.Properties getTestProperties(com.sun.javadoc.MethodDoc[] methodDocs,
                                              int index,
                                              com.sun.javadoc.ClassDoc classDoc,
                                              com.sun.javadoc.PackageDoc packageDoc,
                                              NamingStrategy naming,
                                              java.util.Properties properties)
Comment on DBC:
\@pre (methodDoc != null) && (classDoc != null) && (packageDoc != null) && (naming != null) && (properties != null)

Returns:
if the method specified by 'index' needs a test, new Properties instance with all properties for parameter 'properties' and test method specific properties; null if the method specified by 'index' needs no test

getTestSuiteAddTestSuites

public java.lang.String getTestSuiteAddTestSuites(com.sun.javadoc.PackageDoc[] packageDocs,
                                                  int indexPackage,
                                                  NamingStrategy naming,
                                                  java.util.Properties properties)

getTestSuiteAddTestCases

public java.lang.String getTestSuiteAddTestCases(com.sun.javadoc.PackageDoc[] packageDocs,
                                                 int indexPackage,
                                                 NamingStrategy naming,
                                                 java.util.Properties properties)

getTestSuiteImports

public java.lang.String getTestSuiteImports(com.sun.javadoc.PackageDoc[] packageDocs,
                                            int indexPackage,
                                            NamingStrategy naming,
                                            java.util.Properties properties)

isFirstTestableMethodWithName

public boolean isFirstTestableMethodWithName(com.sun.javadoc.MethodDoc[] methodDocs,
                                             int index)

countTestableMethodsWithName

public int countTestableMethodsWithName(com.sun.javadoc.MethodDoc[] methodDocs,
                                        java.lang.String methodName)

getTestAccessorProperties

public java.util.Properties getTestAccessorProperties(com.sun.javadoc.MethodDoc[] methodDocs,
                                                      int index,
                                                      com.sun.javadoc.ClassDoc classDoc,
                                                      com.sun.javadoc.PackageDoc packageDoc,
                                                      NamingStrategy naming,
                                                      java.util.Properties properties)
Builds accessor specific properties if the method specified by 'index' is an accessor method.

Returns:
if specfied method is an set accessor, returns properties with all properties from parameter 'properties' and accessor specific properties; if specfied method is an get accessor, return null; if specfied method is not an accessor, returns parameter 'properties' unchanged

getAccessorPairIndex

public int getAccessorPairIndex(com.sun.javadoc.MethodDoc[] methodDocs,
                                int index)
A method is considered an accessor if (i) method name starts with certain prefixes, (ii) prefix is followed by a property name (that is longer than the empyt string ""), (iii) there are methods with this property name for both 'get' and 'set' prefixes, (iv) number of parameters for the get method is 0 and number of parameter for the set method is 1.

Returns:
-1 = not both accessors found or not an accessor method, 0 or above = index of prefix in ACCESSOR_STARTS_WITH method of the method specified by 'index'

getNumberOfParameters

private static int getNumberOfParameters(com.sun.javadoc.MethodDoc methodDoc)
Comment on DBC:
\@pre methodDoc != null


getAccessedPropertyName

public java.lang.String getAccessedPropertyName(java.lang.String accessorMethodName,
                                                int indexAccessorPair)
Returns:
name of accessed property if 'accessorMethodName' starts with an accessor prefix specified by 'indexAccessorPair' (see field ACCESSOR_STARTS_WITH), null in all other cases.

getAccessorTestsByType

public java.lang.String getAccessorTestsByType(java.util.Properties properties,
                                               java.lang.String templateAttribute,
                                               java.lang.String type)

isInnerClass

public boolean isInnerClass(com.sun.javadoc.ClassDoc doc)

isATest

public boolean isATest(com.sun.javadoc.ClassDoc doc)

hasSuiteMethod

public boolean hasSuiteMethod(com.sun.javadoc.ClassDoc doc)

getDirectSubPackages

public com.sun.javadoc.PackageDoc[] getDirectSubPackages(com.sun.javadoc.PackageDoc[] packageDocs,
                                                         int indexCurrentPackage)

isValid

public boolean isValid(java.lang.String code)
Specified by:
isValid in interface TestingStrategy

hasAllRequiredStrings

public boolean hasAllRequiredStrings(java.lang.String code)

isValidStructure

public boolean isValidStructure(java.lang.String code)

merge

public boolean merge(java.lang.StringBuffer inOutCode,
                     java.lang.StringBuffer inCode,
                     java.lang.String fullClassName)
Merges all markers from inCode into inOutCode. In the end all markers from oldCode will be in newCode as well. If nessesary some new generated default content in newCode gets overwritten. If some markers are not in newCode any more, they will be moved to testVault, a special test method.

Specified by:
merge in interface TestingStrategy
Parameters:
inOutCode - points to the in-out StringBuffer with the new code
inCode - holds all markers to be merged into to newCode
fullClassName - is used only for the error message, if anything goes wrong.
Returns:
true if successfully merged, false if old code contains no JUnitDoclet markers.

containsCodeOrComment

public boolean containsCodeOrComment(java.lang.String markContent)

hasUnmatchedMarkers

public boolean hasUnmatchedMarkers(java.lang.String code)