1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.dbunit.dataset;
22
23 import static org.assertj.core.api.Assertions.assertThat;
24 import static org.junit.jupiter.api.Assertions.assertThrows;
25
26 import org.junit.jupiter.api.Test;
27
28
29
30
31
32
33 public class ForwardOnlyTableTest extends DefaultTableTest
34 {
35
36 @Override
37 protected ITable createTable() throws Exception
38 {
39 return new ForwardOnlyTable(super.createTable());
40 }
41
42 @Override
43 @Test
44 void testGetRowCount_withSixRowTable_returnsRowCount() throws Exception
45 {
46 final ITable table = createTable();
47 assertThrows(UnsupportedOperationException.class,
48 () -> table.getRowCount(),
49 "Should have throw UnsupportedOperationException");
50 }
51
52 @Override
53 @Test
54 void testGetValueRowBounds_withOutOfBoundsRow_throwsRowOutOfBoundsException() throws Exception
55 {
56 final int[] rows = new int[] {ROW_COUNT, ROW_COUNT + 1};
57 final ITable table = createTable();
58 final String columnName =
59 table.getTableMetaData().getColumns()[0].getColumnName();
60
61 for (int i = 0; i < rows.length; i++)
62 {
63 final int row = i;
64 assertThrows(RowOutOfBoundsException.class,
65 () -> table.getValue(rows[row], columnName),
66 "Should throw a RowOutOfBoundsException!");
67 }
68 }
69
70 @Test
71 void testGetValueIterateBackward_whenAccessingPreviousRow_throwsUnsupportedOperation() throws Exception
72 {
73 final ITable table = createTable();
74 for (int i = 0; i < ROW_COUNT; i++)
75 {
76 final int row = i;
77 for (int j = 0; j < COLUMN_COUNT; j++)
78 {
79 final String columnName = "COLUMN" + j;
80 final String expected = "row " + i + " col " + j;
81 final Object value = table.getValue(i, columnName);
82 assertThat(value).as("value").isEqualTo(expected);
83 }
84
85
86 for (int j = 0; j < COLUMN_COUNT; j++)
87 {
88 final String columnName = "COLUMN" + j;
89 assertThrows(UnsupportedOperationException.class,
90 () -> table.getValue(row - 1, columnName));
91 }
92 }
93 }
94
95 @Test
96 void testGetValueOnEmptyTable_withEmptyTable_throwsRowOutOfBoundsException() throws Exception
97 {
98 final MockTableMetaData metaData =
99 new MockTableMetaData("TABLE", new String[] {"C1"});
100 final ITable table = new ForwardOnlyTable(new DefaultTable(metaData));
101 assertThrows(RowOutOfBoundsException.class,
102 () -> table.getValue(0, "C1"),
103 "Should have throw RowOutOfBoundsException");
104
105 }
106
107
108
109
110 @Override
111 @Test
112 public void testGetMissingValue_withMissingCells_returnsExpectedValues() throws Exception
113 {
114 super.testGetMissingValue_withMissingCells_returnsExpectedValues();
115 }
116
117 }