1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.internal.merge; |
21 |
|
|
22 |
|
import static org.junit.Assert.assertEquals; |
23 |
|
import static org.junit.Assert.assertFalse; |
24 |
|
import static org.junit.Assert.assertTrue; |
25 |
|
|
26 |
|
import java.util.ArrayList; |
27 |
|
import java.util.Arrays; |
28 |
|
import java.util.List; |
29 |
|
|
30 |
|
import org.junit.Before; |
31 |
|
import org.junit.Rule; |
32 |
|
import org.junit.Test; |
33 |
|
import org.xwiki.diff.internal.DefaultDiffManager; |
34 |
|
import org.xwiki.logging.LogLevel; |
35 |
|
import org.xwiki.test.ComponentManagerRule; |
36 |
|
import org.xwiki.test.annotation.ComponentList; |
37 |
|
|
38 |
|
import com.xpn.xwiki.doc.merge.MergeResult; |
39 |
|
import com.xpn.xwiki.web.Utils; |
40 |
|
|
41 |
|
|
42 |
|
@link |
43 |
|
|
44 |
|
@since |
45 |
|
@since |
46 |
|
@since |
47 |
|
|
48 |
|
@ComponentList({ |
49 |
|
DefaultDiffManager.class |
50 |
|
}) |
|
|
| 100% |
Uncovered Elements: 0 (47) |
Complexity: 10 |
Complexity Density: 0.27 |
|
51 |
|
public class MergeUtilsTest |
52 |
|
{ |
53 |
|
@Rule |
54 |
|
public ComponentManagerRule componentManager = new ComponentManagerRule(); |
55 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
56 |
9 |
@Before... |
57 |
|
public void setUp() |
58 |
|
{ |
59 |
9 |
Utils.setComponentManager(this.componentManager); |
60 |
|
} |
61 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
62 |
1 |
@Test... |
63 |
|
public void mergeWhenDifferences() |
64 |
|
{ |
65 |
1 |
MergeResult result = new MergeResult(); |
66 |
1 |
assertEquals("content\n", MergeUtils.mergeLines("content", "content\n", "content", result)); |
67 |
1 |
assertTrue(result.isModified()); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
70 |
1 |
@Test... |
71 |
|
public void mergeWhenCurrentStringDoesntEndWithNewLine() |
72 |
|
{ |
73 |
1 |
MergeResult result = new MergeResult(); |
74 |
1 |
assertEquals("content", MergeUtils.mergeLines("content", "content", "content", result)); |
75 |
1 |
assertFalse(result.isModified()); |
76 |
|
} |
77 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
78 |
1 |
@Test... |
79 |
|
public void mergeWhenCurrentStringEndsWithNewLine() |
80 |
|
{ |
81 |
1 |
MergeResult result = new MergeResult(); |
82 |
1 |
assertEquals("content\n", MergeUtils.mergeLines("content\n", "content\n", "content\n", result)); |
83 |
1 |
assertFalse(result.isModified()); |
84 |
|
} |
85 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
86 |
1 |
@Test... |
87 |
|
public void mergeObjectSimple() |
88 |
|
{ |
89 |
1 |
MergeResult result = new MergeResult(); |
90 |
1 |
assertEquals("new", MergeUtils.mergeOject("old", "new", "old", result)); |
91 |
1 |
assertTrue(result.isModified()); |
92 |
|
} |
93 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
94 |
1 |
@Test... |
95 |
|
public void mergeObjectAlreadyDone() |
96 |
|
{ |
97 |
1 |
MergeResult result = new MergeResult(); |
98 |
1 |
assertEquals("new", MergeUtils.mergeOject("old", "new", "new", result)); |
99 |
1 |
assertFalse(result.isModified()); |
100 |
|
} |
101 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
102 |
1 |
@Test... |
103 |
|
public void mergeObjectWhileModified() |
104 |
|
{ |
105 |
1 |
MergeResult result = new MergeResult(); |
106 |
1 |
assertEquals("old modified", MergeUtils.mergeOject("old", "new", "old modified", result)); |
107 |
1 |
assertFalse(result.isModified()); |
108 |
|
|
109 |
1 |
assertFalse(result.getLog().getLogs(LogLevel.ERROR).isEmpty()); |
110 |
|
} |
111 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (5) |
Complexity: 1 |
Complexity Density: 0.2 |
1PASS
|
|
112 |
1 |
@Test... |
113 |
|
public void mergeListSimple() |
114 |
|
{ |
115 |
1 |
MergeResult result = new MergeResult(); |
116 |
1 |
List<String> current = new ArrayList<String>(Arrays.asList("old1", "old2")); |
117 |
1 |
MergeUtils.mergeList(Arrays.asList("old1", "old2"), Arrays.asList("new1", "new2"), current, result); |
118 |
1 |
assertEquals(Arrays.asList("new1", "new2"), current); |
119 |
1 |
assertTrue(result.isModified()); |
120 |
|
} |
121 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
122 |
1 |
@Test... |
123 |
|
public void mergeListAlreadyDone() |
124 |
|
{ |
125 |
1 |
MergeResult result = new MergeResult(); |
126 |
1 |
List<String> current = new ArrayList<String>(Arrays.asList("new1", "new2")); |
127 |
1 |
MergeUtils.mergeList(Arrays.asList("old1", "old2"), Arrays.asList("new1", "new2"), current, result); |
128 |
1 |
assertEquals(Arrays.asList("new1", "new2"), current); |
129 |
1 |
assertEquals(Arrays.asList("new1", "new2"), current); |
130 |
1 |
assertFalse(result.isModified()); |
131 |
|
} |
132 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
133 |
1 |
@Test... |
134 |
|
public void mergeListWhileModified() |
135 |
|
{ |
136 |
1 |
MergeResult result = new MergeResult(); |
137 |
1 |
List<String> current = new ArrayList<String>(Arrays.asList("old modified1", "old modified2")); |
138 |
1 |
MergeUtils.mergeList(Arrays.asList("old1", "old2"), Arrays.asList("new1", "new2"), current, result); |
139 |
1 |
assertEquals(Arrays.asList("old modified1", "old modified2"), current); |
140 |
1 |
assertFalse(result.isModified()); |
141 |
|
|
142 |
1 |
assertFalse(result.getLog().getLogs(LogLevel.ERROR).isEmpty()); |
143 |
|
} |
144 |
|
} |