私はマルチモジュールプロジェクトを持っています。これには、xsdを使用してjaxbによって生成されたクラスのセットがあります。そのようなクラスの例を以下に示します。 (getterとsetterなし)execuete jacocoがエージェントを準備するときにリフレクションによるJava注釈のキャプチャが動作しない
@XmlRootElement(name = "IPPAMUser")
public class IPPAMUser {
@XmlElement(name = "UserName", required = true)
protected String userName;
@XmlElement(name = "PAMInstanceID", required = true)
protected String pamInstanceID;
@XmlElement(name = "Product", required = true)
protected String product;
@XmlElement(name = "Password", required = true)
protected String password;
@XmlElement(name = "PasswordAlogo", required = true)
protected String passwordAlogo;
@XmlElement(name = "LastUpdatedOn", required = true)
protected String lastUpdatedOn;
@XmlElement(name = "IsGenerated")
protected boolean isGenerated;
@XmlElement(name = "LastNotifiedOn", required = true)
protected String lastNotifiedOn;
}
1つのモジュールで、それらをキー値のペアとして使用する必要があります。したがって、1つのメソッドはリフレクションを使ってキー値のペアのリストに変換するように記述されています。このフィールドの名前では、キーとして使用され、その値としての値が使用されます。それは以下のように取られます。
Field[] fields = t.getClass().getDeclaredFields();
for(Field field : fields) {
Annotation anotation = field.getAnnotation(XmlElement.class);
XmlElement xmlElement = (XmlElement) anotation;
String methodName;
String parameterValue = "";
if(field.getType() == boolean.class){
methodName = "is" + xmlElement.name();
} else {
methodName = "get" + xmlElement.name();
}
try {
Method method = t.getClass().getDeclaredMethod(methodName);
if(method.invoke(t) == null){
continue;
}
parameterValue = method.invoke(t).toString();
} catch (NoSuchMethodException e) {
log.error("Method not found. Method : " + methodName, e);
log.error("Stack trace : {}", AuthUtils.getPrintableStackTrace(e));
} catch (InvocationTargetException e) {
log.error("Method invoking failed. Method : " + methodName, e);
log.error("Stack trace : {}", AuthUtils.getPrintableStackTrace(e));
} catch (IllegalAccessException e) {
log.error("Illegal access " + e);
log.error("Stack trace : {}", AuthUtils.getPrintableStackTrace(e));
}
}
この変換を使用するいくつかのテストケースがあります。彼らは正常に動作し、Mavenビルドで実行します。コードカバレッジを取るために、jacoco-maven-pluginが追加されました。実行中は、jacoco.execファイルは生成されません。これによるとpost実行目標が私のpomファイルに追加されています。その後、私のユニットテストは失敗し、ヌルポインタ例外が返されます。スタックトレースによると、 "xmlElement.name()"を実行すると発生します。これは、xmlElementがnullであることを意味します。したがって、リフレクションはこの実行目標の追加後にアノテーションを取得できません。
jacocoなどの手段を使用してこの問題を解決し、コードカバレッジレポートを取得するにはどうすればよいですか。
ありがとうございます。