此代码将从数据库中检索数据,并将从中检索数据的列名称与注释字段名称相匹配。如何使用 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;
}
}