私のコードベースのクラスの1つに、私の人生の間、私のjunitテストには参加できないメソッドがあります。私は、データベース接続を要求する場合、基本的に、このクラスは古い接続が返された場合、新しい接続がここJava - コードカバレッジ
を確立している、と呼ばれ は、私のクラスでmthodの抜粋である(この目的のためにトリムダウン)
public class TCSOracleDataSourceWrapper extends OracleDataSource {
private static final int STALE_CONNECTION_EX_CODE = 17143;
private OracleConnectionCacheManager cacheManager;
private String cacheName;
/** Local log variable **/
private final Log logger = LogFactory.getLog(getClass());
/**
* Class constructor
* @throws SQLException
*/
public TCSOracleDataSourceWrapper() throws SQLException {
super();
}
private static final long serialVersionUID = 1L;
@Override
/**
* Get a connection but if the connection is stale then refresh all DB connections
*
*/
public final Connection getConnection() throws SQLException {
logger.debug("Retrieving a database connection from the pool");
Connection connection = null;
try{
connection = super.getConnection();
}
catch(SQLException e)
{
if(e.getErrorCode() == STALE_CONNECTION_EX_CODE)
{
logger.error("Stale Oracle connection found in the Connection Pool. Refreshing invalid DB connections.");
//refresh invalid connections
cacheManager.refreshCache(cacheName, OracleConnectionCacheManager.REFRESH_INVALID_CONNECTIONS);
//now try to get the connection again
connection = super.getConnection();
}
else
{
throw e;
}
}
return connection;
}}
私のjunitテストがifステートメントを確実に実行できるようにするにはどうすればよいですか? 私は現在、EasyMockとPowermockを使用していますが、なステートメント場合、私はすべてのヘルプが大幅
ありがとう ダミアン