1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
|
package <XDtPackage:packageName/>;
import junit.framework.*;
import xjavadoc.*;
import xjavadoc.filesystem.*;
import java.io.File;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;
/**
* Automatically generated JUnit test for xjavadoc
*
* @author xjavadoc/xdoclet
* @created 8. januar 2002
* @todo-javadoc Write javadocs
*/
public class <XDtClass:className/>__GENERATED__Test extends TestCase {
private XClass _testedClass;
private final XJavaDoc _xJavaDoc = new XJavaDoc();
private static final String tokenizeAndTrim( final String s ) {
StringBuffer sb = new StringBuffer();
StringTokenizer st = new StringTokenizer(s);
while( st.hasMoreTokens() ) {
sb.append( st.nextToken() ).append(" ");
}
return sb.toString().trim();
}
public <XDtClass:className/>__GENERATED__Test( String name ) {
super( name );
}
public void setUp() throws Exception {
// hardcoded to xjavadoc's own sources
File dir = new File(System.getProperty("basedir"),"src");
_xJavaDoc.reset(true);
_xJavaDoc.addSourceSet(new FileSourceSet(dir, null));
_testedClass = _xJavaDoc.getXClass( "<XDtClass:fullClassName/>" );
}
public void tearDown() {
}
public void testPackage() {
assertEquals( "<XDtPackage:packageName/>", _testedClass.getContainingPackage().getName() );
}
public void testSuperclass() {
XClass superclass = _testedClass.getSuperclass();
String superclassName;
if( superclass == null ) {
superclassName = "java.lang.Object";
} else {
superclassName = superclass.getQualifiedName();
}
assertEquals( "<XDtClass:fullSuperclassName/>", superclassName );
}
public void testInterfaces() {
// not implemented in xdoclet yet
}
public void testFields() {
// Sort the fields
Collection fields = _testedClass.getFields();
ArrayList sortedFields = new ArrayList();
sortedFields.addAll(fields);
Collections.sort(sortedFields);
Iterator fieldIterator = sortedFields.iterator();
XField field = null;
<XDtField:forAllFields superclasses="false" sort="true">
// test if field type is the same
field = (XField) fieldIterator.next();
assertEquals( "<XDtField:fieldType/>", field.getType().getQualifiedName() + field.getDimensionAsString());
// test if field name is the same
assertEquals( "<XDtField:fieldName/>", field.getName() );
</XDtField:forAllFields>
}
public void testMethods() {
// Sort the methods
Collection methods = _testedClass.getMethods();
ArrayList sortedMethods = new ArrayList();
sortedMethods.addAll(methods);
Collections.sort(sortedMethods);
Iterator methodIterator = sortedMethods.iterator();
XMethod method = null;
Iterator parameters = null;
XParameter parameter = null;
Iterator paramTags = null;
XTag paramTag = null;
<XDtMethod:forAllMethods superclasses="false" sort="true">
method = (XMethod) methodIterator.next();
// test if return type is the same
assertEquals( "<XDtMethod:methodType/>", method.getReturnType().getType().getQualifiedName() + method.getReturnType().getDimensionAsString());
// test if method name is the same
assertEquals( "<XDtMethod:methodName/>", method.getName() );
// test if parameters are the same
parameters = method.getParameters().iterator();
<XDtParameter:forAllMethodParams>
parameter = (XParameter) parameters.next();
assertEquals( "<XDtParameter:methodParamName/>", parameter.getName() );
assertEquals( "<XDtParameter:methodParamType/>", parameter.getType().getQualifiedName() + parameter.getDimensionAsString());
</XDtParameter:forAllMethodParams>
// test if doc is the same
paramTags = method.getDoc().getTags("param",true).iterator();
<XDtMethod:forAllMethodTags tagName="param">
paramTag = (XTag) paramTags.next();
assertEquals( tokenizeAndTrim("<XDtMethod:methodTagValue tagName="param"/>"), paramTag.getValue() );
</XDtMethod:forAllMethodTags>
</XDtMethod:forAllMethods>
}
}
|