-
-
Notifications
You must be signed in to change notification settings - Fork 2k
/
TableDifferTest.java
executable file
·79 lines (70 loc) · 3.2 KB
/
TableDifferTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
package cucumber.table;
import gherkin.formatter.PrettyFormatter;
import org.junit.Test;
import static junit.framework.Assert.assertEquals;
public class TableDifferTest {
private static final String EOL = System.getProperty("line.separator");
private Table table() {
String source =
"| Aslak | aslak@email.com | 123 |" + EOL +
"| Joe | joe@email.com | 234 |" + EOL +
"| Bryan | bryan@email.org | 456 |" + EOL +
"| Ni | ni@email.com | 654 |" + EOL;
return TableParser.parse(source);
}
private Table otherTableWithDeletedAndInserted() {
String source =
"| Aslak | aslak@email.com | 123 |" + EOL +
"| Doe | joe@email.com | 234 |" + EOL +
"| Foo | schnickens@email.net | 789 |" + EOL +
"| Bryan | bryan@email.org | 456 |" + EOL;
return TableParser.parse(source);
}
private Table otherTableWithInsertedAtEnd() {
String source =
"| Aslak | aslak@email.com | 123 |" + EOL +
"| Joe | joe@email.com | 234 |" + EOL +
"| Bryan | bryan@email.org | 456 |" + EOL +
"| Ni | ni@email.com | 654 |" + EOL +
"| Doe | joe@email.com | 234 |" + EOL +
"| Foo | schnickens@email.net | 789 |" + EOL;
return TableParser.parse(source);
}
@Test(expected = TableDiffException.class)
public void shouldFindDifferences() {
try {
new TableDiffer(table(), otherTableWithDeletedAndInserted()).calculateDiffs();
} catch (TableDiffException e) {
String expected =
" - | Joe | joe@email.com | 234 |" + EOL +
" + | Doe | joe@email.com | 234 |" + EOL +
" + | Foo | schnickens@email.net | 789 |" + EOL +
" | Joe | joe@email.com | 234 |" + EOL +
" - | Ni | ni@email.com | 654 |" + EOL;
assertEquals(expected, pretty(e.getDiffTable()));
throw e;
}
}
@Test(expected = TableDiffException.class)
public void shouldFindNewLinesAtEnd() {
try {
new TableDiffer(table(), otherTableWithInsertedAtEnd()).calculateDiffs();
} catch (TableDiffException e) {
String expected =
" | Aslak | aslak@email.com | 123 |" + EOL +
" | Joe | joe@email.com | 234 |" + EOL +
" | Bryan | bryan@email.org | 456 |" + EOL +
" + | Doe | joe@email.com | 234 |" + EOL +
" + | Foo | schnickens@email.net | 789 |" + EOL;
assertEquals(expected, pretty(e.getDiffTable()));
throw e;
}
}
private String pretty(Table table) {
StringBuilder result = new StringBuilder();
PrettyFormatter pf = new PrettyFormatter(result, true, false);
pf.table(table.getGherkinRows());
pf.eof();
return result.toString();
}
}