CodeTestCase is a JUnit extension that will let you compare two sources
(typically one we keep as test data and a generated one) on the API level or
on the abstract syntax tree (AST) level. This is a lot more powerful than
comparing on a character by character basis, because it's only "what matters"
that is compared.
assertApiEquals
public static void assertApiEquals(File expected,
File actual)
Asserts (tests) that the APIs of two sources are equal. Does not go into the
method bodies to see if the implementation is equal, and is therefore more
relaxed than assertAstEquals.
expected
- the expected sourceactual
- the actual source
assertApiEquals
public static void assertApiEquals(Reader expected,
Reader actual)
assertAstEquals
public static void assertAstEquals(File expected,
File actual)
Asserts (tests) that the ASTs of two sources are equal. Does not compare the
contents (tokens) of the nodes, and is forgiving with respect to those.
expected
- the expected sourceactual
- the actual source
assertAstEquals
public static void assertAstEquals(Reader expected,
Reader actual)
assertAstEqualsDir
public static void assertAstEqualsDir(File expectedDir,
File actualDir)
assertConstructorsEqual
private static void assertConstructorsEqual(XClass expected,
XClass actual)
assertEquals
public static void assertEquals(File expected,
File actual)
Compares both API and AST. Equivalent to calling assertAstEquals
and assertApiEquals
.
expected
- the expected sourceactual
- the actual source
assertEquals
public static void assertEquals(Reader expected,
Reader actual)
assertFieldEquals
private static void assertFieldEquals(XField expected,
XField actual)
assertFieldsEqual
private static void assertFieldsEqual(XClass expected,
XClass actual)
assertMethodEquals
private static void assertMethodEquals(XMethod expected,
XMethod actual)
assertMethodsEqual
private static void assertMethodsEqual(XClass expected,
XClass actual)
assertNameEquals
private static void assertNameEquals(String msg,
Named expected,
Named actual)
assertParameterEquals
private static void assertParameterEquals(XParameter expected,
XParameter actual)
assertTypeEquals
private static void assertTypeEquals(String msg,
Type expected,
Type actual)
checkNotDir
private static void checkNotDir(File expected,
File actual)
getActualChild
private static File getActualChild(File actualDir,
File expectedChild)
getDir
protected File getDir()
Returns the directory where this class is located, provided that it's not in
a jar. This is very useful for accessing the files you want to compare.
- the directory where this class is located.
getRootDir
protected File getRootDir()
Returns the root directory of the package hierarchy where this class is
located, provided that it's not in a jar. This is very useful for accessing
the files you want to compare.
- the root directory.
getXJavaDoc
protected XJavaDoc getXJavaDoc()