내 코드베이스의 클래스 중 하나에 내 junit 테스트를 사용할 수 없다는 메서드가 있습니다. 오래된 연결이 반환되는 경우 나는 데이터베이스 연결을 요청할 때 기본적으로이 클래스를 호출, 새 연결이 여기 Java - 코드 커버리지
(이 목적 아래로 손질) 내 수업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;
}}
의 mthod의 조각입니다 설립
내 junit 테스트에서 if 문을 어떻게 실행할 수 있는지 생각해보십시오. 나는 현재 EasyMock에와 Powermock를 사용하고 있지만, 한 Statment는 당신이 당신의 클래스를 리팩토링해야 데미안