1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (43) |
Complexity: 3 |
Complexity Density: 0.08 |
|
40 |
|
public class DefaultBlameManagerTest |
41 |
|
{ |
42 |
|
|
43 |
|
|
44 |
|
|
|
|
| 50% |
Uncovered Elements: 2 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
45 |
|
class Revision { |
46 |
|
private final String rev; |
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
47 |
3 |
Revision(String rev)... |
48 |
|
{ |
49 |
3 |
this.rev = rev; |
50 |
|
} |
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
51 |
0 |
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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
64 |
2 |
@Before... |
65 |
|
public void configure() throws Exception |
66 |
|
{ |
67 |
2 |
blameManager = this.mocker.getComponentUnderTest(); |
68 |
|
} |
69 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
1PASS
|
|
70 |
1 |
@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 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (36) |
Complexity: 1 |
Complexity Density: 0.03 |
1PASS
|
|
78 |
1 |
@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 |
|
} |