1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package com.xpn.xwiki.internal.merge

File MergeUtilsTest.java

 

Code metrics

0
37
10
1
144
101
10
0.27
3.7
10
1

Classes

Class Line # Actions
MergeUtilsTest 51 37 0% 10 0
1.0100%
 

Contributing tests

This file is covered by 9 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
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    * Unit tests for {@link MergeUtils}.
43    *
44    * @since 4.5.4
45    * @since 5.0.2
46    * @since 5.1M1
47    */
48    @ComponentList({
49    DefaultDiffManager.class
50    })
 
51    public class MergeUtilsTest
52    {
53    @Rule
54    public ComponentManagerRule componentManager = new ComponentManagerRule();
55   
 
56  9 toggle @Before
57    public void setUp()
58    {
59  9 Utils.setComponentManager(this.componentManager);
60    }
61   
 
62  1 toggle @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   
 
70  1 toggle @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   
 
78  1 toggle @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   
 
86  1 toggle @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   
 
94  1 toggle @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   
 
102  1 toggle @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    // conflicts are flagged as errors in the log
109  1 assertFalse(result.getLog().getLogs(LogLevel.ERROR).isEmpty());
110    }
111   
 
112  1 toggle @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   
 
122  1 toggle @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   
 
133  1 toggle @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    // conflicts are flagged as errors in the log
142  1 assertFalse(result.getLog().getLogs(LogLevel.ERROR).isEmpty());
143    }
144    }