I have a method in one of the classes in my code base that for life I can’t enter in my unit tests. Basically this class is called when I request a connection to the database, if an obsolete connection is returned, a new connection is established.
Here is the mthod fragment in my class (cropped for this purpose)
public class TCSOracleDataSourceWrapper extends OracleDataSource {
private static final int STALE_CONNECTION_EX_CODE = 17143;
private OracleConnectionCacheManager cacheManager;
private String cacheName;
private final Log logger = LogFactory.getLog(getClass());
public TCSOracleDataSourceWrapper() throws SQLException {
super();
}
private static final long serialVersionUID = 1L;
@Override
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.");
cacheManager.refreshCache(cacheName, OracleConnectionCacheManager.REFRESH_INVALID_CONNECTIONS);
connection = super.getConnection();
}
else
{
throw e;
}
}
return connection;
}}
Any idea how I can ensure that my junit tests execute an if statement? I am currently using EasyMock and Powermock, but I cannot find a way to get into this if statment using these tools
All help is appreciated
Thank. Damien
source
share