/** * Verifies the number of parameters 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 number the expected number of parameters * @throws VerifyFailedException if verification fails */ public void verifySQLStatementParameterNumber(String sql, int indexOfParameterSet, int number) { MockParameterMap actualParameterMap = verifyAndGetParametersForSQL(sql, indexOfParameterSet); if(actualParameterMap.size() != number) { throw new VerifyFailedException("Expected " + number + " parameter, actual " + actualParameterMap.size() + " parameter"); } }
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; } }
verifySQLStatementParameterNumber(sql, indexOfParameterSet, parameterMap.size()); MockParameterMap actualParameterMap = verifyAndGetParametersForSQL(sql, indexOfParameterSet);