1 package com.mockobjects.sql; 2 3 import java.sql.SQLException ; 4 import java.util.Map ; 5 import java.util.Iterator ; 6 import com.mockobjects.*; 7 import com.mockobjects.util.*; 8 9 public class ExpectationSqlRow implements Verifiable { 10 private ExpectationMap values; 11 12 public ExpectationSqlRow(String name) { 13 super(); 14 values = new ExpectationMap(name); 15 values.setExpectNothing(); 16 } 17 18 public ExpectationSqlRow(String name, Object [] indexedValues) { 19 this(name); 20 addExpectedIndexedValues(indexedValues); 21 } 22 23 public ExpectationSqlRow(String name, String [] columnNames, Object [] values) { 24 this(name); 25 addExpectedNamedValues(columnNames, values); 26 } 27 28 public void addExpectedIndexedValues(Object [] indexedValues) { 29 for (int i = 0; i < indexedValues.length; ++i) { 30 values.addExpected(new Integer (i + 1), indexedValues[i]); 31 } 32 } 33 34 public void addExpectedNamedValues(Map map) { 35 Iterator columnNames = map.keySet().iterator(); 36 while (columnNames.hasNext()) { 37 Object key = columnNames.next(); 38 values.addExpected(key, map.get(key)); 39 } 40 } 41 42 public void addExpectedNamedValues(String [] columnNames, Object [] someValues) { 43 for (int i = 0; i < someValues.length; ++i) { 44 values.addExpected(columnNames[i], someValues[i]); 45 } 46 } 47 48 public Object get(int oneBasedIndex) throws SQLException { 49 return get(new Integer (oneBasedIndex)); 50 } 51 52 public Object get(Object key) throws SQLException { 53 Object result = values.get(key); 54 if (result instanceof SQLException ) { 55 throw (SQLException )result; 56 } 57 return result; 58 } 59 60 public void verify() { 61 values.verify(); 62 } 63 } 64 | Popular Tags |