1 21 package org.dbunit.dataset; 22 23 28 public abstract class AbstractTableIteratorTest extends AbstractTest 29 { 30 public AbstractTableIteratorTest(String s) 31 { 32 super(s); 33 } 34 35 protected abstract ITableIterator getIterator() throws Exception ; 36 37 protected abstract ITableIterator getEmptyIterator() throws Exception ; 38 39 public void testNext() throws Exception 40 { 41 int count = 0; 42 String [] names = getExpectedNames(); 43 ITableIterator iterator = getIterator(); 44 while(iterator.next()) 45 { 46 count++; 47 } 48 49 assertEquals("count", names.length, count); 50 } 51 52 public void testNextAndEmpty() throws Exception 53 { 54 int count = 0; 55 ITableIterator iterator = getEmptyIterator(); 56 while(iterator.next()) 57 { 58 count++; 59 } 60 61 assertEquals("count", 0, count); 62 } 63 64 public void testGetTableMetaData() throws Exception 65 { 66 int i = 0; 67 String [] names = getExpectedNames(); 68 ITableIterator iterator = getIterator(); 69 while(iterator.next()) 70 { 71 assertEquals("name " + i, names[i], 72 iterator.getTableMetaData().getTableName()); 73 i++; 74 } 75 76 assertEquals("count", names.length, i); 77 } 78 79 public void testGetTableMetaDataBeforeNext() throws Exception 80 { 81 ITableIterator iterator = getIterator(); 82 try 83 { 84 iterator.getTableMetaData(); 85 fail("Should have throw a ???Exception"); 86 } 87 catch (IndexOutOfBoundsException e) 88 { 89 90 } 91 92 int i = 0; 93 String [] names = getExpectedNames(); 94 while(iterator.next()) 95 { 96 assertEquals("name " + i, names[i], 97 iterator.getTableMetaData().getTableName()); 98 i++; 99 } 100 101 assertEquals("count", names.length, i); 102 } 103 104 public void testGetTableMetaDataAfterLastNext() throws Exception 105 { 106 int count = 0; 107 String [] names = getExpectedNames(); 108 ITableIterator iterator = getIterator(); 109 while(iterator.next()) 110 { 111 count++; 112 } 113 114 assertEquals("count", names.length, count); 115 116 try 117 { 118 iterator.getTableMetaData(); 119 fail("Should have throw a ???Exception"); 120 } 121 catch (IndexOutOfBoundsException e) 122 { 123 } 124 } 125 126 public void testGetTable() throws Exception 127 { 128 int i = 0; 129 String [] names = getExpectedNames(); 130 ITableIterator iterator = getIterator(); 131 while(iterator.next()) 132 { 133 assertEquals("name " + i, names[i], 134 iterator.getTable().getTableMetaData().getTableName()); 135 i++; 136 } 137 138 assertEquals("count", names.length, i); 139 } 140 } 141 | Popular Tags |