1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.plugin.diff

File DiffTest.java

 

Code metrics

0
96
14
1
213
169
14
0.15
6.86
14
1

Classes

Class Line # Actions
DiffTest 33 96 0% 14 0
1.0100%
 

Contributing tests

This file is covered by 13 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.plugin.diff;
21   
22    import com.xpn.xwiki.XWikiException;
23   
24    import java.util.List;
25   
26    import org.suigeneris.jrcs.diff.delta.Chunk;
27    import org.suigeneris.jrcs.diff.delta.Delta;
28   
29    /**
30    * Created by IntelliJ IDEA. User: ldubost Date: 1 mai 2007 Time: 15:06:14 To change this template
31    * use File | Settings | File Templates.
32    */
 
33    public class DiffTest extends org.jmock.cglib.MockObjectTestCase
34    {
35    private DiffPlugin plugin;
36   
 
37  13 toggle @Override
38    protected void setUp()
39    {
40  13 this.plugin = new DiffPlugin("diff", DiffPlugin.class.getName(), null);
41    }
42   
 
43  1 toggle public void testSimpleLineDiff() throws XWikiException
44    {
45  1 String text1 = "A";
46  1 String text2 = "A B";
47  1 List diffs = this.plugin.getDifferencesAsList(text1, text2);
48  1 assertEquals("There should be one difference", 1, diffs.size());
49  1 Delta delta = (Delta) diffs.get(0);
50  1 Chunk orig = delta.getOriginal();
51  1 Chunk revised = delta.getRevised();
52  1 assertEquals("Original should be", "A", orig.toString());
53  1 assertEquals("Revised should be", "A B", revised.toString());
54    }
55   
 
56  1 toggle public void testSimpleLineDiff2() throws XWikiException
57    {
58  1 String text1 = "A\nB\nC";
59  1 String text2 = "A\nB B\nC";
60  1 List diffs = this.plugin.getDifferencesAsList(text1, text2);
61  1 assertEquals("There should be one difference", 1, diffs.size());
62  1 Delta delta = (Delta) diffs.get(0);
63  1 Chunk orig = delta.getOriginal();
64  1 Chunk revised = delta.getRevised();
65  1 assertEquals("Original should be", "B", orig.toString());
66  1 assertEquals("Revised should be", "B B", revised.toString());
67    }
68   
 
69  1 toggle public void testSimpleWordDiff() throws XWikiException
70    {
71  1 String text1 = "I love Paris";
72  1 String text2 = "I live in Paris";
73  1 List diffs = this.plugin.getWordDifferencesAsList(text1, text2);
74  1 assertEquals("There should be two differences", 1, diffs.size());
75  1 Delta delta1 = (Delta) diffs.get(0);
76  1 Chunk orig1 = delta1.getOriginal();
77  1 Chunk revised1 = delta1.getRevised();
78  1 Delta delta2 = (Delta) diffs.get(0);
79  1 Chunk orig2 = delta2.getOriginal();
80  1 Chunk revised2 = delta2.getRevised();
81  1 assertEquals("Original 1 should be", "love", orig1.toString());
82  1 assertEquals("Revised 1 should be", "livein", revised1.toString());
83    }
84   
 
85  1 toggle public void testSimpleWordDiff2() throws XWikiException
86    {
87  1 String text1 = "I love Paris and London";
88  1 String text2 = "I live in Paris and London";
89  1 List diffs = this.plugin.getWordDifferencesAsList(text1, text2);
90  1 assertEquals("There should be two differences", 1, diffs.size());
91  1 Delta delta1 = (Delta) diffs.get(0);
92  1 Chunk orig1 = delta1.getOriginal();
93  1 Chunk revised1 = delta1.getRevised();
94   
95  1 assertEquals("Original 1 should be", "love", orig1.toString());
96  1 assertEquals("Revised 1 should be", "livein", revised1.toString());
97    }
98   
 
99  1 toggle public void testSimpleWordDiff3() throws XWikiException
100    {
101  1 String text1 = "I love Paris and London";
102  1 String text2 = "I love London and Paris";
103  1 List diffs = this.plugin.getWordDifferencesAsList(text1, text2);
104  1 assertEquals("There should be two differences", 2, diffs.size());
105  1 Delta delta1 = (Delta) diffs.get(0);
106  1 Chunk orig1 = delta1.getOriginal();
107  1 Chunk revised1 = delta1.getRevised();
108  1 Delta delta2 = (Delta) diffs.get(1);
109  1 Chunk orig2 = delta2.getOriginal();
110  1 Chunk revised2 = delta2.getRevised();
111   
112  1 assertEquals("Original 1 should be", "Parisand", orig1.toString());
113  1 assertEquals("Revised 1 should be", "", revised1.toString());
114  1 assertEquals("Original 2 should be", "", orig2.toString());
115  1 assertEquals("Revised 2 should be", "andParis", revised2.toString());
116    }
117   
 
118  1 toggle public void testSimpleWordDiff4() throws XWikiException
119    {
120  1 String text1 = "I love Paris and I like London";
121  1 String text2 = "I love London and I like Paris";
122  1 List diffs = this.plugin.getWordDifferencesAsList(text1, text2);
123  1 assertEquals("There should be two differences", 2, diffs.size());
124  1 Delta delta1 = (Delta) diffs.get(0);
125  1 Chunk orig1 = delta1.getOriginal();
126  1 Chunk revised1 = delta1.getRevised();
127  1 Delta delta2 = (Delta) diffs.get(1);
128  1 Chunk orig2 = delta2.getOriginal();
129  1 Chunk revised2 = delta2.getRevised();
130   
131  1 assertEquals("Original 1 should be", "Paris", orig1.toString());
132  1 assertEquals("Revised 1 should be", "London", revised1.toString());
133  1 assertEquals("Original 2 should be", "London", orig2.toString());
134  1 assertEquals("Revised 2 should be", "Paris", revised2.toString());
135    }
136   
 
137  1 toggle public void testSimpleWordDiffAsHTML() throws XWikiException
138    {
139  1 String text1 = "A";
140  1 String text2 = "A B";
141  1 String html = this.plugin.getWordDifferencesAsHTML(text1, text2);
142  1 assertEquals(
143    "Diff is incorrect",
144    "<div class=\"diffmodifiedline\"><span class=\"diffremoveword\">A</span><span class=\"diffaddword\">A B</span></div>",
145    html);
146    }
147   
 
148  1 toggle public void testSimpleWordDiffAsHTML2() throws XWikiException
149    {
150  1 String text1 = "A C";
151  1 String text2 = "A B";
152  1 String html = this.plugin.getWordDifferencesAsHTML(text1, text2);
153  1 assertEquals(
154    "Diff is incorrect",
155    "<div class=\"diffmodifiedline\">A <span class=\"diffremoveword\">C</span><span class=\"diffaddword\">B</span></div>",
156    html);
157    }
158   
 
159  1 toggle public void testSimpleWordDiffAsHTML3() throws XWikiException
160    {
161  1 String text1 = "A B C D E F";
162  1 String text2 = "A C B D E G";
163  1 String html = this.plugin.getWordDifferencesAsHTML(text1, text2);
164  1 assertEquals(
165    "Diff is incorrect",
166    "<div class=\"diffmodifiedline\">A <span class=\"diffremoveword\">B</span> C <span class=\"diffaddword\">B</span> D E <span class=\"diffremoveword\">F</span><span class=\"diffaddword\">G</span></div>",
167    html);
168    }
169   
 
170  1 toggle public void testSimpleLineDiffAsHTML2() throws XWikiException
171    {
172  1 String text1 = "A C";
173  1 String text2 = "A B";
174  1 String html = this.plugin.getDifferencesAsHTML(text1, text2);
175  1 assertEquals(
176    "Diff is incorrect",
177    "<div class=\"diff\"><div class=\"diffmodifiedline\">A <span class=\"diffremoveword\">C</span><span class=\"diffaddword\">B</span></div></div>",
178    html);
179    }
180   
 
181  1 toggle public void testSimpleLineDiffAsHTML3() throws XWikiException
182    {
183  1 String text1 = "A B C D E F";
184  1 String text2 = "A C B D E G";
185  1 String html = this.plugin.getDifferencesAsHTML(text1, text2);
186  1 assertEquals(
187    "Diff is incorrect",
188    "<div class=\"diff\"><div class=\"diffmodifiedline\">A <span class=\"diffremoveword\">B</span> C <span class=\"diffaddword\">B</span> D E <span class=\"diffremoveword\">F</span><span class=\"diffaddword\">G</span></div></div>",
189    html);
190    }
191   
 
192  1 toggle public void testSimpleLineDiffAsHTML4() throws XWikiException
193    {
194  1 String text1 = "A B C\nD E F\nG H I\nJ K L\n";
195  1 String text2 = "A B C\nG H I\nD E F\nJ K L\n";
196  1 String html = this.plugin.getDifferencesAsHTML(text1, text2);
197  1 assertEquals(
198    "Diff is incorrect",
199    "<div class=\"diff\"><div class=\"diffunmodifiedline\">A B C</div><div class=\"diffmodifiedline\"><span class=\"diffremoveword\">D E F</span></div><div class=\"diffunmodifiedline\">G H I</div><div class=\"diffmodifiedline\"><span class=\"diffaddword\">D E F</span></div><div class=\"diffunmodifiedline\">J K L</div></div>",
200    html);
201    }
202   
 
203  1 toggle public void testMultiLineDiffAsHTML() throws XWikiException
204    {
205  1 String text1 = "A\n";
206  1 String text2 = "AA\nAB\n";
207  1 String html = this.plugin.getDifferencesAsHTML(text1, text2);
208  1 assertEquals(
209    "Diff is incorrect",
210    "<div class=\"diff\"><div class=\"diffmodifiedline\"><span class=\"diffremoveword\">A</span><span class=\"diffaddword\">AA</span></div><div class=\"diffmodifiedline\"><span class=\"diffaddword\">AB</span></div></div>",
211    html);
212    }
213    }