1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.diff.display.internal; |
21 |
|
|
22 |
|
import java.io.BufferedReader; |
23 |
|
import java.io.IOException; |
24 |
|
import java.io.InputStream; |
25 |
|
import java.io.InputStreamReader; |
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.Arrays; |
28 |
|
import java.util.Collection; |
29 |
|
import java.util.Collections; |
30 |
|
import java.util.List; |
31 |
|
|
32 |
|
import org.apache.commons.io.IOUtils; |
33 |
|
import org.junit.Assert; |
34 |
|
import org.junit.Rule; |
35 |
|
import org.junit.Test; |
36 |
|
import org.junit.runner.RunWith; |
37 |
|
import org.junit.runners.Parameterized; |
38 |
|
import org.junit.runners.Parameterized.Parameters; |
39 |
|
import org.xwiki.diff.DiffManager; |
40 |
|
import org.xwiki.diff.display.UnifiedDiffBlock; |
41 |
|
import org.xwiki.diff.display.UnifiedDiffDisplayer; |
42 |
|
import org.xwiki.diff.internal.DefaultDiffManager; |
43 |
|
import org.xwiki.test.ComponentManagerRule; |
44 |
|
import org.xwiki.test.annotation.ComponentList; |
45 |
|
|
46 |
|
|
47 |
|
@link |
48 |
|
|
49 |
|
@version |
50 |
|
@since |
51 |
|
|
52 |
|
@ComponentList({ |
53 |
|
DefaultDiffManager.class, |
54 |
|
DefaultUnifiedDiffDisplayer.class, |
55 |
|
DefaultInlineDiffDisplayer.class |
56 |
|
}) |
57 |
|
@RunWith(Parameterized.class) |
|
|
| 100% |
Uncovered Elements: 0 (35) |
Complexity: 5 |
Complexity Density: 0.17 |
|
58 |
|
public class DefaultUnifiedDiffDisplayerTest |
59 |
|
{ |
60 |
|
@Rule |
61 |
|
public final ComponentManagerRule componentManager = new ComponentManagerRule(); |
62 |
|
|
63 |
|
|
64 |
|
|
65 |
|
|
66 |
|
private final List<String> previous; |
67 |
|
|
68 |
|
|
69 |
|
|
70 |
|
|
71 |
|
private final List<String> next; |
72 |
|
|
73 |
|
|
74 |
|
|
75 |
|
|
76 |
|
private final String expected; |
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
@param |
82 |
|
@param |
83 |
|
@param |
84 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
85 |
9 |
public DefaultUnifiedDiffDisplayerTest(List<String> previous, List<String> next, String expected)... |
86 |
|
{ |
87 |
9 |
this.previous = previous; |
88 |
9 |
this.next = next; |
89 |
9 |
this.expected = expected; |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
1PASS
|
|
95 |
9 |
@Test... |
96 |
|
public void execute() throws Exception |
97 |
|
{ |
98 |
9 |
DiffManager diffManager = this.componentManager.getInstance(DiffManager.class); |
99 |
9 |
UnifiedDiffDisplayer unifiedDiffDisplayer = this.componentManager.getInstance(UnifiedDiffDisplayer.class); |
100 |
9 |
List<UnifiedDiffBlock<String, Object>> blocks = |
101 |
|
unifiedDiffDisplayer.display(diffManager.diff(this.previous, this.next, null)); |
102 |
|
|
103 |
9 |
StringBuilder actual = new StringBuilder(); |
104 |
9 |
for (UnifiedDiffBlock<String, ?> block : blocks) { |
105 |
8 |
actual.append(block); |
106 |
|
} |
107 |
9 |
Assert.assertEquals(this.expected, actual.toString()); |
108 |
|
} |
109 |
|
|
110 |
|
|
111 |
|
@return |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
|
113 |
1 |
@Parameters... |
114 |
|
public static Collection<Object[]> data() throws IOException |
115 |
|
{ |
116 |
1 |
Collection<Object[]> data = new ArrayList<Object[]>(); |
117 |
|
|
118 |
|
|
119 |
|
|
120 |
|
|
121 |
|
|
122 |
|
|
123 |
1 |
data.add(new Object[] { Collections.<String>emptyList(), Collections.<String>emptyList(), "" }); |
124 |
|
|
125 |
|
|
126 |
1 |
List<String> lines = Arrays.asList("one", "two", "three"); |
127 |
1 |
data.add(new Object[] { lines, lines, "" }); |
128 |
|
|
129 |
|
|
130 |
1 |
data.add(new Object[] { Collections.<String>emptyList(), lines, "@@ -1,0 +1,3 @@\n+one\n+two\n+three\n" }); |
131 |
|
|
132 |
|
|
133 |
1 |
data.add(new Object[] { lines, Collections.<String>emptyList(), "@@ -1,3 +1,0 @@\n-one\n-two\n-three\n" }); |
134 |
|
|
135 |
|
|
136 |
1 |
data.add(new Object[] { lines, Arrays.asList(lines.get(0), lines.get(2)), |
137 |
|
"@@ -1,3 +1,2 @@\n one\n-two\n three\n" }); |
138 |
|
|
139 |
|
|
140 |
1 |
data.add(new Object[] { lines, Arrays.asList(lines.get(0), lines.get(1), "between", lines.get(2)), |
141 |
|
"@@ -1,3 +1,4 @@\n one\n two\n+between\n three\n" }); |
142 |
|
|
143 |
|
|
144 |
1 |
data.add(new Object[] { lines, Arrays.asList(lines.get(0), "Two", lines.get(2)), |
145 |
|
"@@ -1,3 +1,3 @@\n one\n-two\n+Two\n three\n" }); |
146 |
|
|
147 |
|
|
148 |
|
|
149 |
|
|
150 |
|
|
151 |
1 |
List<String> previous = readLines("previous.txt"); |
152 |
1 |
String[] testNames = new String[] { "twoContexts", "sharedContext" }; |
153 |
1 |
for (String testName : testNames) { |
154 |
2 |
data.add(new Object[] { previous, readLines(testName + ".txt"), readContent(testName + ".diff") }); |
155 |
|
} |
156 |
|
|
157 |
1 |
return data; |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
|
162 |
|
|
163 |
|
@param |
164 |
|
@return |
165 |
|
@throws |
166 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
167 |
3 |
private static List<String> readLines(String fileName) throws IOException... |
168 |
|
{ |
169 |
3 |
InputStream stream = DefaultUnifiedDiffDisplayerTest.class.getResourceAsStream('/' + fileName); |
170 |
3 |
BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); |
171 |
3 |
return IOUtils.readLines(reader); |
172 |
|
} |
173 |
|
|
174 |
|
|
175 |
|
|
176 |
|
|
177 |
|
@param |
178 |
|
@return |
179 |
|
@throws |
180 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
181 |
2 |
private static String readContent(String fileName) throws IOException... |
182 |
|
{ |
183 |
2 |
InputStream stream = DefaultUnifiedDiffDisplayerTest.class.getResourceAsStream('/' + fileName); |
184 |
2 |
BufferedReader reader = new BufferedReader(new InputStreamReader(stream)); |
185 |
2 |
return IOUtils.toString(reader); |
186 |
|
} |
187 |
|
} |