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.sheet; |
21 |
|
|
22 |
|
import static org.mockito.ArgumentMatchers.*; |
23 |
|
import static org.mockito.Mockito.*; |
24 |
|
|
25 |
|
import java.util.ArrayList; |
26 |
|
import java.util.Arrays; |
27 |
|
import java.util.List; |
28 |
|
|
29 |
|
import org.junit.Assert; |
30 |
|
import org.junit.Before; |
31 |
|
import org.junit.Rule; |
32 |
|
import org.junit.Test; |
33 |
|
import org.xwiki.model.reference.DocumentReference; |
34 |
|
import org.xwiki.model.reference.DocumentReferenceResolver; |
35 |
|
import org.xwiki.query.Query; |
36 |
|
import org.xwiki.query.QueryManager; |
37 |
|
import org.xwiki.sheet.SheetBinder; |
38 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
39 |
|
|
40 |
|
|
41 |
|
@link |
42 |
|
|
43 |
|
@version |
44 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (20) |
Complexity: 2 |
Complexity Density: 0.11 |
|
45 |
|
public class ClassSheetBinderTest |
46 |
|
{ |
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
@Rule |
51 |
|
public final MockitoComponentMockingRule<SheetBinder> mocker = new MockitoComponentMockingRule<SheetBinder>( |
52 |
|
ClassSheetBinder.class); |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
private Query sheetBindingsQuery; |
58 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
59 |
1 |
@Before... |
60 |
|
public void setUp() throws Exception |
61 |
|
{ |
62 |
1 |
sheetBindingsQuery = mock(Query.class); |
63 |
1 |
QueryManager queryManager = mocker.getInstance(QueryManager.class); |
64 |
|
|
65 |
1 |
when(queryManager.createQuery(any(), any())).thenReturn(sheetBindingsQuery); |
66 |
|
} |
67 |
|
|
68 |
|
|
69 |
|
@link |
70 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
71 |
1 |
@Test... |
72 |
|
public void getDocuments() throws Exception |
73 |
|
{ |
74 |
1 |
List<Object[]> queryResult = new ArrayList<Object[]>(); |
75 |
1 |
queryResult.add(new Object[] {"Alice", "AnotherSheet"}); |
76 |
1 |
queryResult.add(new Object[] {"Bob", "Sheet"}); |
77 |
|
|
78 |
1 |
when(sheetBindingsQuery.<Object[]> execute()).thenReturn(queryResult); |
79 |
|
|
80 |
1 |
DocumentReference sheetReference = new DocumentReference("wiki", "Space", "Sheet"); |
81 |
1 |
DocumentReferenceResolver<String> documentReferenceResolver = |
82 |
|
mocker.getInstance(DocumentReferenceResolver.TYPE_STRING); |
83 |
|
|
84 |
1 |
DocumentReference aliceReference = new DocumentReference("wiki", "Users", "Alice"); |
85 |
1 |
DocumentReference anotherSheetReference = new DocumentReference("wiki", "Space", "AnotherSheet"); |
86 |
1 |
when(documentReferenceResolver.resolve("Alice", sheetReference)).thenReturn(aliceReference); |
87 |
1 |
when(documentReferenceResolver.resolve("AnotherSheet", aliceReference)).thenReturn(anotherSheetReference); |
88 |
|
|
89 |
1 |
DocumentReference bobReference = new DocumentReference("wiki", "Users", "Bob"); |
90 |
1 |
when(documentReferenceResolver.resolve("Bob", sheetReference)).thenReturn(bobReference); |
91 |
1 |
when(documentReferenceResolver.resolve("Sheet", bobReference)).thenReturn(sheetReference); |
92 |
|
|
93 |
1 |
Assert.assertEquals(Arrays.asList(bobReference), mocker.getComponentUnderTest().getDocuments(sheetReference)); |
94 |
|
|
95 |
1 |
verify(sheetBindingsQuery).setWiki(sheetReference.getWikiReference().getName()); |
96 |
|
} |
97 |
|
} |