このコードはデータベースからデータを取得し、データの取得元の列名と注釈フィールド名を一致させます。jmock を使用した単体テストでこのコード行をカバーするにはどうすればよいですか? この問題から抜け出すのを手伝ってください。
ArrayList<String> criticalFields = getAllCriticalField("ORD", order
.getSrcSysId());
if (criticalFields != null && criticalFields.size() >= 1) {
String query = "select * from tvs.ORD where SRC_SYS_ID='"
+ order.getSrcSysId() + "' AND ORD_ID='"
+ order.getOrdId() + "'";
connection = vwsUtil.getConnection();
statement = connection.createStatement();
Field[] fields = Order.class.getDeclaredFields();
for (Field field : fields) {
field.setAccessible(true);
if (field.isAnnotationPresent(TableColumnAnnotation.class)) {
TableColumnAnnotation column = field
.getAnnotation(TableColumnAnnotation.class);
if (criticalFields.contains(column.columnName())) {
if (column.columnName().equalsIgnoreCase(
"EST_RTS_DT")
|| column.columnName().equalsIgnoreCase(
"ACT_RTS_DT")
|| column.columnName().equalsIgnoreCase(
"CMIT_SHP_DT")
|| column.columnName().equalsIgnoreCase(
"ACT_FST_SHP_DT")
|| column.columnName().equalsIgnoreCase(
"ACT_FNL_SHP_DT")
|| column.columnName().equalsIgnoreCase(
"ORD_CANC_DT")
|| column.columnName().equalsIgnoreCase(
"SHP_BEF_DT")
|| column.columnName().equalsIgnoreCase(
"SHP_AFT_DT")) {
if (field.get(order) == null
|| field.get(order).toString()
.isEmpty()) {
query = query + " AND "
+ column.columnName() + " IS NULL ";
} else {
Calendar cal = (Calendar) field.get(order);
java.util.Date dt = cal.getTime();
SimpleDateFormat fmt = new SimpleDateFormat(
"dd-MM-yy");
String sqlDate = fmt.format(dt);
/*query = query + " AND "
+ column.columnName() + "='"
+ sqlDate + "'";*/
query = query + " AND "
+ column.columnName() + "=to_date('"
+ sqlDate + "','DD-MM-YY')";
}
} else if (column.columnName().equalsIgnoreCase(
"ORD_TS")
|| column.columnName().equalsIgnoreCase(
"ACK_TS")) {
if (field.get(order) == null
|| field.get(order).toString()
.isEmpty()) {
query = query + " AND "
+ column.columnName() + " IS NULL ";
} else {
Calendar cal = (Calendar) field.get(order);
java.util.Date dt = cal.getTime();
SimpleDateFormat fmt = new SimpleDateFormat(
"dd-MM-yy HH:mm:ss.SSSSSSSSS");
String sqlDate = fmt.format(dt);
query = query + " AND "
+ column.columnName() + "='"
+ sqlDate + "'";
/*query = query + " AND "
+ column.columnName() + "=to_date('"
+ sqlDate + "','DD-MM-YY HH:mm:ss.SSSSSSSSS')";*/
}
} else if (column.columnName().equalsIgnoreCase(
"DLR_MNG_TRNSP_IND")) {
if (field.get(order) == null
|| field.get(order).toString()
.isEmpty()) {
query = query + " AND "
+ column.columnName() + " IS NULL ";
} else {
query = query + " AND "
+ column.columnName() + "="
+ field.get(order).toString();
}
} else {
if (field.get(order) == null
|| field.get(order).toString()
.isEmpty()) {
query = query + " AND "
+ column.columnName() + " IS NULL ";
} else {
query = query + " AND "
+ column.columnName() + "='"
+ field.get(order).toString() + "'";
}
}
}
}
} //System.out.println("Order Query = "+query);
resultSet = statement.executeQuery(query);
if (!resultSet.next()) {System.out.println("Flag true in Order ");
criticalFieldFlag = true;
}
}