[Hansel-general] (no subject)
Brought to you by:
jiriki
From: peter m. <pet...@ho...> - 2003-05-23 16:30:51
|
I have been getting coverage failures when I check to see if a (database) Connection object is null. I have tests which quite clearly test for when its null and when its not. I've even confirmed this by adding System.out.prints for both branches of the if/else, and although both lines are printed to standard output, still I get a coverage complaint. The output looks like this: Tests run: 10, Failures: 1, Errors: 0, Time elapsed: 0.732 sec [junit] ------------- Standard Output --------------- [junit] in finally - con not null [junit] in finally - con null [junit] ------------- ---------------- --------------- [junit] Testcase: testGetTransaction took 0.593 sec [junit] Testcase: testGetTransactionWithSQLException took 0.005 sec [junit] Testcase: testGetAllTransactions took 0.008 sec [junit] Testcase: testGetAllTransactionsWithSQLException took 0.002 sec [junit] Testcase: testSetDatabase took 0.002 sec [junit] Testcase: unknown took 0.003 sec [junit] Testcase: unknown took 0 sec [junit] Testcase: unknown took 0.001 sec [junit] Testcase: unknown took 0.001 sec [junit] Testcase: unknown took 0.006 sec [junit] FAILED [junit] Coverage failure: Branch not completely covered. Expression 'con == null' is never true. [junit] Coverage failure: Branch not completely covered. Expression 'con == null' is never true. [junit] at com.orange.thirdparty.ocash.test.db.DBCall.getTransaction(String trxId)(DBCall.java:152) And the code looks like this: /** * Retrieve a transaction from the transaction table by transactionID * * @param trxId The ID uniquely identifying the transaction * @throws SQLException If Connection can't be closed * @return An xmlrpc response document either representing success * and containing the transaction, or representing failure and * contaibing details of that failure. */ public Hashtable getTransaction(String trxId) throws SQLException { StdXmlrpcResponse stdResponse; Hashtable respData = new Hashtable(); Connection con = null; Statement stmt = null; ResultSet rs = null; try { con = getConnection(); stmt = con.createStatement(); String query = "SELECT * FROM " + TRANSACTION_TABLE + " where TRANSACTION_ID=\"" + trxId + "\""; rs = stmt.executeQuery(query); while (rs.next()) { Hashtable transaction = new Hashtable(); transaction.put(BILLER_ID, rs.getString(BILLER_ID_COL)); transaction.put(AUTH_ID, rs.getString(AUTH_ID_COL)); transaction.put(TRANSACTION_ID, rs.getString(TRANSACTION_ID_COL)); transaction.put(ACCOUNT_ID, rs.getString(ACCOUNT_ID_COL)); transaction.put(AMOUNT, new Double( rs.getDouble(AMOUNT_COL))); transaction.put(CURRENCY, rs.getString(CURRENCY_COL)); respData.put(TRANSACTION_KEY, transaction); } stdResponse = new StdXmlrpcResponse(respData); } catch (SQLException sqle) { respData.put("sqle", sqle.getMessage()); stdResponse = new StdXmlrpcResponse(SQL_EX_REASON_CODE, SQL_EX_REASON_MESSAGE, respData); } finally { if (con != null) { System.out.println("in finally - con not null"); con.close(); } else { System.out.println("in finally - con null"); } if (stmt != null) { stmt.close(); } if (rs != null) { rs.close(); } } return stdResponse.getResponse(); } I'm using hansel 0.99 and jdk 1.4.1 Thanks, Peter Moore _________________________________________________________________ Stay in touch with absent friends - get MSN Messenger http://www.msn.co.uk/messenger |