01: package com.mockrunner.test.jdbc;
02:
03: import java.sql.SQLException;
04:
05: import com.mockrunner.mock.jdbc.MockResultSetMetaData;
06:
07: import junit.framework.TestCase;
08:
09: public class MockResultSetMetaDataTest extends TestCase {
10: private MockResultSetMetaData metaData;
11:
12: protected void setUp() throws Exception {
13: metaData = new MockResultSetMetaData();
14: }
15:
16: protected void tearDown() throws Exception {
17: metaData = null;
18: }
19:
20: private void prepareMetaData() {
21: metaData.setColumnClassName(1, "ClassName");
22: metaData.setColumnCount(4);
23: metaData.setColumnTypeName(2, "TypeName");
24: metaData.setColumnDisplaySize(3, 7);
25: metaData.setSearchable(2, false);
26: metaData.setReadOnly(5, true);
27: metaData.setScale(1, 2);
28: metaData.setNullable(2, 3);
29: }
30:
31: private void verifyMetaData(MockResultSetMetaData metaData)
32: throws SQLException {
33: assertEquals("ClassName", metaData.getColumnClassName(1));
34: assertEquals(Object.class.getName(), metaData
35: .getColumnClassName(2));
36: assertEquals(4, metaData.getColumnCount());
37: assertEquals("TypeName", metaData.getColumnTypeName(2));
38: assertEquals("", metaData.getColumnTypeName(1));
39: assertEquals(7, metaData.getColumnDisplaySize(3));
40: assertEquals(4, metaData.getColumnDisplaySize(5));
41: assertFalse(metaData.isSearchable(2));
42: assertTrue(metaData.isSearchable(1));
43: assertTrue(metaData.isReadOnly(5));
44: assertFalse(metaData.isReadOnly(1));
45: assertEquals(2, metaData.getScale(1));
46: assertEquals(3, metaData.isNullable(2));
47: }
48:
49: public void testSetAndClone() throws Exception {
50: prepareMetaData();
51: verifyMetaData(metaData);
52: MockResultSetMetaData clonedMetaData = (MockResultSetMetaData) metaData
53: .clone();
54: assertNotSame(metaData, clonedMetaData);
55: verifyMetaData(clonedMetaData);
56: }
57: }
|