1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.blame.internal

File DefaultBlameManagerTest.java

 

Code metrics

0
42
5
2
146
98
5
0.12
8.4
2.5
1

Classes

Class Line # Actions
DefaultBlameManagerTest 40 40 0% 3 0
1.0100%
DefaultBlameManagerTest.Revision 45 2 0% 2 2
0.550%
 

Contributing tests

This file is covered by 2 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   
21    package org.xwiki.blame.internal;
22   
23    import java.util.Arrays;
24    import java.util.Collections;
25    import java.util.Iterator;
26   
27    import org.junit.Before;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.xwiki.blame.AnnotatedContent;
31    import org.xwiki.blame.AnnotatedElement;
32    import org.xwiki.blame.BlameManager;
33    import org.xwiki.test.mockito.MockitoComponentMockingRule;
34   
35    import static org.hamcrest.CoreMatchers.is;
36    import static org.hamcrest.CoreMatchers.nullValue;
37    import static org.jmock.Expectations.same;
38    import static org.junit.Assert.assertThat;
39   
 
40    public class DefaultBlameManagerTest
41    {
42    /**
43    * Small class simulating revision metadata;
44    */
 
45    class Revision {
46    private final String rev;
 
47  3 toggle Revision(String rev)
48    {
49  3 this.rev = rev;
50    }
 
51  0 toggle public String toString()
52    {
53  0 return rev;
54    }
55    }
56   
57   
58    @Rule
59    public final MockitoComponentMockingRule<BlameManager> mocker = new MockitoComponentMockingRule<BlameManager>(
60    DefaultBlameManager.class);
61   
62    BlameManager blameManager;
63   
 
64  2 toggle @Before
65    public void configure() throws Exception
66    {
67  2 blameManager = this.mocker.getComponentUnderTest();
68    }
69   
 
70  1 toggle @Test
71    public void testBlameNullRevision() throws Exception
72    {
73  1 assertThat(blameManager.blame(null, null, null), nullValue());
74  1 assertThat(blameManager.blame(null, null, Collections.<String>emptyList()), nullValue());
75  1 assertThat(blameManager.blame(null, new Object(), null), nullValue());
76    }
77   
 
78  1 toggle @Test
79    public void testBlame() throws Exception
80    {
81  1 Revision rev1 = new Revision("rev1");
82  1 Revision rev2 = new Revision("rev2");
83  1 Revision rev3 = new Revision("rev3");
84   
85  1 AnnotatedContent<Revision, String> annotatedContent = blameManager.blame(null, rev3, Arrays.asList(
86    "Jackdaws love my big sphinx of quartz.",
87    "Cozy lummox gives smart squid who asks for job pen.",
88    "The quick red fox",
89    "jumps over",
90    "the lazy dog"));
91   
92  1 assertThat(annotatedContent.isEntirelyAnnotated(), is(false));
93  1 assertThat(annotatedContent.getOldestRevision(), same(rev3));
94   
95  1 annotatedContent = blameManager.blame(annotatedContent,
96    rev2, Arrays.asList(
97    "Cozy lummox gives smart squid who asks for job pen.",
98    "The quick red fox",
99    "jumps over the lazy dog"));
100   
101  1 assertThat(annotatedContent.isEntirelyAnnotated(), is(false));
102  1 assertThat(annotatedContent.getOldestRevision(), same(rev2));
103   
104  1 annotatedContent = blameManager.blame(annotatedContent,
105    rev1, Arrays.asList(
106    "Cozy lummox gives smart squid who asks for job pen.",
107    "The quick brown fox",
108    "jumps over the lazy dog."));
109   
110  1 assertThat(annotatedContent.isEntirelyAnnotated(), is(false));
111  1 assertThat(annotatedContent.getOldestRevision(), same(rev1));
112   
113  1 annotatedContent = blameManager.blame(annotatedContent, null, null);
114   
115  1 assertThat(annotatedContent.isEntirelyAnnotated(), is(true));
116  1 assertThat(annotatedContent.getOldestRevision(), nullValue());
117   
118  1 Iterator<AnnotatedElement<Revision, String>> iter = annotatedContent.iterator();
119   
120  1 assertThat(iter.hasNext(), is(true));
121  1 AnnotatedElement<Revision, String> annotatedElement = iter.next();
122  1 assertThat(annotatedElement.getElement(), is("Jackdaws love my big sphinx of quartz."));
123  1 assertThat(annotatedElement.getRevision(), same(rev3));
124   
125  1 assertThat(iter.hasNext(), is(true));
126  1 annotatedElement = iter.next();
127  1 assertThat(annotatedElement.getElement(), is("Cozy lummox gives smart squid who asks for job pen."));
128  1 assertThat(annotatedElement.getRevision(), same(rev1));
129   
130  1 assertThat(iter.hasNext(), is(true));
131  1 annotatedElement = iter.next();
132  1 assertThat(annotatedElement.getElement(), is("The quick red fox"));
133  1 assertThat(annotatedElement.getRevision(), same(rev2));
134   
135  1 assertThat(iter.hasNext(), is(true));
136  1 annotatedElement = iter.next();
137  1 assertThat(annotatedElement.getElement(), is("jumps over"));
138  1 assertThat(annotatedElement.getRevision(), same(rev3));
139   
140  1 assertThat(iter.hasNext(), is(true));
141  1 annotatedElement = iter.next();
142  1 assertThat(annotatedElement.getElement(), is("the lazy dog"));
143  1 assertThat(annotatedElement.getRevision(), same(rev3));
144    }
145   
146    }