Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Use raw() instead of rows(). Added a couple of TODOs for Tables.

  • Loading branch information...
commit d4b6eec3ee14d873d20dd1769a38fe9a1a190b25 1 parent 971d6c0
Aslak Hellesøy aslakhellesoy authored DFUK committed
22 core/src/main/java/cucumber/table/Table.java
@@ -8,12 +8,13 @@
8 8 public class Table {
9 9
10 10 private final List<List<String>> raw;
11   - private List<String> headers;
12 11 private final Map<String, Transformer<?>> columnTransformersByHeader = new HashMap<String, Transformer<?>>();
13 12 private Map<Integer, Transformer<?>> columnTransformers;
14 13 private TableHeaderMapper headerMapper;
15 14 private final Locale locale;
16   - private List<Row> gherkinRows;
  15 + private final List<Row> gherkinRows;
  16 +
  17 + private List<String> headers;
17 18
18 19 public Table(List<Row> gherkinRows, Locale locale) {
19 20 this.gherkinRows = gherkinRows;
@@ -54,6 +55,7 @@ public Table(List<Row> gherkinRows, Locale locale) {
54 55 }
55 56
56 57 /**
  58 + * TODO: Not sure how valuable this method is. See asList() and automatic table conversion.
57 59 * @return a List of Row, with each each cell value transformed
58 60 */
59 61 public List<List<Object>> rows() {
@@ -72,6 +74,10 @@ public Table(List<Row> gherkinRows, Locale locale) {
72 74 return this.raw.subList(1, this.raw.size());
73 75 }
74 76
  77 + public <T> List<T> asList(T type) {
  78 + throw new UnsupportedOperationException("TODO: i9mplement this method and get rid of the hashes() method");
  79 + }
  80 +
75 81 public List<Map<String, Object>> hashes() {
76 82 List<Map<String, Object>> hashes = new ArrayList<Map<String, Object>>();
77 83 List<List<Object>> rows = rows();
@@ -89,7 +95,7 @@ private Object transformCellValue(int colPos, String cellValue) {
89 95 Object hashValue;
90 96 Transformer<?> transformer = getColumnTransformer(colPos);
91 97 if (transformer != null) {
92   - hashValue = transformer.transform(this.locale, cellValue);
  98 + hashValue = transformer.transform(locale, cellValue);
93 99 } else {
94 100 hashValue = cellValue;
95 101 }
@@ -157,20 +163,18 @@ public Locale getLocale() {
157 163
158 164 List<DiffableRow> diffableRows() {
159 165 List<DiffableRow> result = new ArrayList<DiffableRow>();
160   - List<List<Object>> convertedRows = rows();
  166 + List<List<String>> convertedRows = raw();
161 167 for (int i = 0; i < convertedRows.size(); i++) {
162   - result.add(new DiffableRow(getGherkinRows().get(i + 1), convertedRows.get(i)));
  168 + result.add(new DiffableRow(getGherkinRows().get(i), convertedRows.get(i)));
163 169 }
164 170 return result;
165 171 }
166 172
167   - // TODO: Get rid of this class if we base the diffing on simple List<List<String>
168   - // from the List<Row> list passed to the ctor.
169 173 class DiffableRow {
170 174 public final Row row;
171   - public final List<Object> convertedRow;
  175 + public final List<String> convertedRow;
172 176
173   - public DiffableRow(Row row, List<Object> convertedRow) {
  177 + public DiffableRow(Row row, List<String> convertedRow) {
174 178 this.row = row;
175 179 this.convertedRow = convertedRow;
176 180 }
8 core/src/main/java/cucumber/table/TableDiffer.java
@@ -12,8 +12,8 @@
12 12
13 13 public class TableDiffer {
14 14
15   - private Table orig;
16   - private Table other;
  15 + private final Table orig;
  16 + private final Table other;
17 17
18 18 public TableDiffer(Table origTable, Table otherTable) {
19 19 this.orig = origTable;
@@ -21,7 +21,7 @@ public TableDiffer(Table origTable, Table otherTable) {
21 21 }
22 22
23 23 public void calculateDiffs() {
24   - Patch patch = DiffUtils.diff(this.orig.diffableRows(), this.other.diffableRows());
  24 + Patch patch = DiffUtils.diff(orig.diffableRows(), other.diffableRows());
25 25 List<Delta> deltas = patch.getDeltas();
26 26 if (!deltas.isEmpty()) {
27 27 Map<Integer, Delta> deltasByLine = createDeltasByLine(deltas);
@@ -31,7 +31,7 @@ public void calculateDiffs() {
31 31
32 32 private Table createTableDiff(Map<Integer, Delta> deltasByLine) {
33 33 List<Row> diffTableRows = new ArrayList<Row>();
34   - List<List<Object>> rows = orig.rows();
  34 + List<List<String>> rows = orig.raw();
35 35 for (int i = 0; i < rows.size(); i++) {
36 36 Delta delta = deltasByLine.get(i);
37 37 if (delta == null) {
20 core/src/test/java/cucumber/table/TableDifferTest.java
@@ -19,10 +19,10 @@ private Table table() {
19 19
20 20 private Table otherTableWithDeletedAndInserted() {
21 21 String source =
22   - "| Aslak | aslak@email.com | 123 |" + EOL +
23   - "| Doe | joe@email.com | 234 |" + EOL +
24   - "| Foo | schnickens@email.net | 789 |" + EOL +
25   - "| Bryan | bryan@email.org | 456 |" + EOL;
  22 + "| Aslak | aslak@email.com | 123 |" + EOL +
  23 + "| Doe | joe@email.com | 234 |" + EOL +
  24 + "| Foo | schnickens@email.net | 789 |" + EOL +
  25 + "| Bryan | bryan@email.org | 456 |" + EOL;
26 26 return TableParser.parse(source);
27 27 }
28 28
@@ -43,11 +43,12 @@ public void shouldFindDifferences() {
43 43 new TableDiffer(table(), otherTableWithDeletedAndInserted()).calculateDiffs();
44 44 } catch (TableDiffException e) {
45 45 String expected =
46   - " - | Joe | joe@email.com | 234 |" + EOL +
47   - " + | Doe | joe@email.com | 234 |" + EOL +
48   - " + | Foo | schnickens@email.net | 789 |" + EOL +
49   - " | Joe | joe@email.com | 234 |" + EOL +
50   - " - | Ni | ni@email.com | 654 |" + EOL;
  46 + " | Aslak | aslak@email.com | 123 |" + EOL +
  47 + " - | Joe | joe@email.com | 234 |" + EOL +
  48 + " + | Doe | joe@email.com | 234 |" + EOL +
  49 + " + | Foo | schnickens@email.net | 789 |" + EOL +
  50 + " | Bryan | bryan@email.org | 456 |" + EOL +
  51 + " - | Ni | ni@email.com | 654 |" + EOL;
51 52 assertEquals(expected, pretty(e.getDiffTable()));
52 53 throw e;
53 54 }
@@ -62,6 +63,7 @@ public void shouldFindNewLinesAtEnd() {
62 63 " | Aslak | aslak@email.com | 123 |" + EOL +
63 64 " | Joe | joe@email.com | 234 |" + EOL +
64 65 " | Bryan | bryan@email.org | 456 |" + EOL +
  66 + " | Ni | ni@email.com | 654 |" + EOL +
65 67 " + | Doe | joe@email.com | 234 |" + EOL +
66 68 " + | Foo | schnickens@email.net | 789 |" + EOL;
67 69 assertEquals(expected, pretty(e.getDiffTable()));

0 comments on commit d4b6eec

Please sign in to comment.
Something went wrong with that request. Please try again.