KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > mockobjects > sql > ExpectationSqlRow


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