in testing/testutils/src/main/java/org/apache/axiom/testutils/stax/XMLStreamReaderComparator.java [88:145]
private <T> InvocationResults<T> invoke(
Class<T> returnType, String methodName, Class<?>[] paramTypes, Object[] args)
throws Exception {
Method method = XMLStreamReader.class.getMethod(methodName, paramTypes);
T expectedResult;
Throwable expectedException;
try {
expectedResult = returnType.cast(method.invoke(expected, args));
expectedException = null;
} catch (InvocationTargetException ex) {
expectedResult = null;
expectedException = ex.getCause();
}
T actualResult;
Throwable actualException;
try {
actualResult = returnType.cast(method.invoke(actual, args));
actualException = null;
} catch (InvocationTargetException ex) {
actualResult = null;
actualException = ex.getCause();
}
if (expectedException == null) {
if (actualException != null) {
actualException.printStackTrace(System.out);
fail(
"Method "
+ methodName
+ " threw unexpected exception "
+ actualException.getClass().getName()
+ " ("
+ getLocation()
+ ")");
} else {
return new InvocationResults<>(expectedResult, actualResult);
}
} else {
if (actualException == null) {
fail(
"Expected "
+ methodName
+ " to throw "
+ expectedException.getClass().getName()
+ ", but the method returned normally ("
+ getLocation()
+ ")");
} else {
assertEquals(
"Unexpected exception thrown by " + methodName,
expectedException.getClass(),
actualException.getClass());
}
}
return null;
}