public Object getObject(String parameterName) throws SQLException { wasNull = false; Object returnValue = null; if(null != lastOutParameters) { returnValue = lastOutParameters.get(parameterName); } if(null == returnValue) wasNull = true; return returnValue; }
public Object getObject(int parameterIndex) throws SQLException { wasNull = false; Object returnValue = null; if(null != lastOutParameters) { returnValue = lastOutParameters.get(parameterIndex); } if(null == returnValue) wasNull = true; return returnValue; }
public Object getParameter(String name) { return paramObjects.get(name); }
public Object getParameter(int index) { return paramObjects.get(index); }
public Object get(String name){ return get(new ParameterName(name)); }
public Object get(int index){ return get(new ParameterIndex(index)); }
private MockParameterMap filterNotRegisteredParameters(MockParameterMap outParameter) { MockParameterMap filteredMap = new MockParameterMap(); for (ParameterReference nextKey : outParameter.keySet()) { if (registeredOutParameterSetIndexed.contains(nextKey) || registeredOutParameterSetNamed.contains (nextKey)) { filteredMap.put(nextKey, outParameter.get(nextKey)); } } return new MockUnmodifiableParameterMap(filteredMap); }
public boolean doParameterMatch(MockParameterMap actualParameters, boolean exactMatchParameter) { if(exactMatchParameter) { if(actualParameters.size() != this.size()) return false; for(ParameterReference currentKey : actualParameters.keySet()){ Object expectedObject = this.get(currentKey); if(!ParameterUtil.compareParameter(actualParameters.get(currentKey), expectedObject)) { return false; } } return true; } else { for(ParameterReference currentKey : this.keySet()){ Object actualObject = actualParameters.get(currentKey); if(!ParameterUtil.compareParameter(actualObject, this.get(currentKey))) { return false; } } return true; } }
private MockParameterMap getParameterMapCopy(MockParameterMap actualParameters) { MockParameterMap copyParameters = new MockParameterMap(); for (ParameterReference key : actualParameters.keySet()) { Object actualParameter = actualParameters.get(key); Object copyParameter = ParameterUtil.copyParameter(actualParameter); copyParameters.put(key, copyParameter); } return copyParameters; } }
public MockParameterMap getIndexedParameterMap() { MockParameterMap indexedParameters = new MockParameterMap(); for(ParameterReference parameterReference : paramObjects.keySet()){ if(parameterReference instanceof ParameterIndex){ indexedParameters.put(parameterReference, paramObjects.get(parameterReference)); } } return new MockUnmodifiableParameterMap(indexedParameters); }
public MockParameterMap getNamedParameterMap() { MockParameterMap namedParameters = new MockParameterMap(); for(ParameterReference parameterReference : paramObjects.keySet()){ if(parameterReference instanceof ParameterName){ namedParameters.put(parameterReference, paramObjects.get(parameterReference)); } } return new MockUnmodifiableParameterMap(namedParameters); }
/** * Verifies the parameter for the specified SQL statement. * If more than one SQL statement is found, this method uses the * first one. * You can specify the index of the parameter set. If * if a <code>PreparedStatement</code> or <code>CallableStatement</code> * is executed N times, it has N parameter sets. Each parameter set * can contain any number of parameters (possibly 0 parameters). * Ordinary statements do not have parameter sets, of course. If * the specified SQL has been executed by an ordinary statements, * a <code>VerifyFailedException</code> is thrown stating the reason. * @param sql the SQL string * @param indexOfParameterSet the number of the parameter set * @param indexOfParameter the index of the parameter * @param expectedParameter the expected parameter * @throws VerifyFailedException if verification fails */ public void verifySQLStatementParameter(String sql, int indexOfParameterSet, int indexOfParameter, Object expectedParameter) { MockParameterMap actualParameterMap = verifyAndGetParametersForSQL(sql, indexOfParameterSet); Object actualParameter = actualParameterMap.get(indexOfParameter); if(!ParameterUtil.compareParameter(expectedParameter, actualParameter)) { throw new VerifyFailedException("Expected " + expectedParameter + " for parameter " + indexOfParameter + ", but was " + actualParameter); } }
/** * Verifies the parameter for the specified SQL statement. * If more than one SQL statement is found, this method uses the * first one. * You can specify the index of the parameter set. If * if a <code>PreparedStatement</code> or <code>CallableStatement</code> * is executed N times, it has N parameter sets. Each parameter set * can contain any number of parameters (possibly 0 parameters). * Ordinary statements do not have parameter sets, of course. If * the specified SQL has been executed by an ordinary statements, * a <code>VerifyFailedException</code> is thrown stating the reason. * @param sql the SQL string * @param indexOfParameterSet the number of the parameter set * @param nameOfParameter the name of the parameter * @param expectedParameter the expected parameter * @throws VerifyFailedException if verification fails */ public void verifySQLStatementParameter(String sql, int indexOfParameterSet, String nameOfParameter, Object expectedParameter) { MockParameterMap actualParameterMap = verifyAndGetParametersForSQL(sql, indexOfParameterSet); Object actualParameter = actualParameterMap.get(nameOfParameter); if(!ParameterUtil.compareParameter(expectedParameter, actualParameter)) { throw new VerifyFailedException("Expected " + expectedParameter + " for parameter " + nameOfParameter + ", but was " + actualParameter); } }