1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.wiki.internal.manager; |
21 |
|
|
22 |
|
import static org.mockito.ArgumentMatchers.any; |
23 |
|
import static org.mockito.Mockito.mock; |
24 |
|
import static org.mockito.Mockito.verify; |
25 |
|
import static org.mockito.Mockito.when; |
26 |
|
|
27 |
|
import org.junit.Before; |
28 |
|
import org.junit.Rule; |
29 |
|
import org.junit.Test; |
30 |
|
import org.xwiki.cache.Cache; |
31 |
|
import org.xwiki.cache.CacheManager; |
32 |
|
import org.xwiki.cache.config.CacheConfiguration; |
33 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
34 |
|
import org.xwiki.wiki.descriptor.WikiDescriptor; |
35 |
|
import org.xwiki.wiki.internal.descriptor.DefaultWikiDescriptor; |
36 |
|
|
37 |
|
|
38 |
|
@link |
39 |
|
|
40 |
|
@version |
41 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 3 |
Complexity Density: 0.19 |
|
42 |
|
public class WikiDescriptorCacheTest |
43 |
|
{ |
44 |
|
@Rule |
45 |
|
public MockitoComponentMockingRule<WikiDescriptorCache> mocker = |
46 |
|
new MockitoComponentMockingRule<WikiDescriptorCache>(WikiDescriptorCache.class); |
47 |
|
|
48 |
|
private Cache<WikiDescriptor> wikiAliasCache; |
49 |
|
|
50 |
|
private Cache<WikiDescriptor> wikiIdCache; |
51 |
|
|
52 |
|
private CacheManager cacheManager; |
53 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
|
54 |
2 |
@Before... |
55 |
|
public void setUp() throws Exception |
56 |
|
{ |
57 |
2 |
wikiAliasCache = mock(Cache.class); |
58 |
2 |
wikiIdCache = mock(Cache.class); |
59 |
2 |
cacheManager = this.mocker.getInstance(CacheManager.class); |
60 |
2 |
when(cacheManager.<WikiDescriptor> createNewCache(any(CacheConfiguration.class))).thenReturn(wikiAliasCache, |
61 |
|
wikiIdCache); |
62 |
|
} |
63 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
64 |
1 |
@Test... |
65 |
|
public void add() throws Exception |
66 |
|
{ |
67 |
1 |
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid", "wikialias"); |
68 |
1 |
descriptor.addAlias("alias2"); |
69 |
|
|
70 |
1 |
this.mocker.getComponentUnderTest().add(descriptor); |
71 |
|
|
72 |
1 |
verify(wikiIdCache).set("wikiid", descriptor); |
73 |
1 |
verify(wikiAliasCache).set("wikialias", descriptor); |
74 |
1 |
verify(wikiAliasCache).set("alias2", descriptor); |
75 |
|
} |
76 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
77 |
1 |
@Test... |
78 |
|
public void remove() throws Exception |
79 |
|
{ |
80 |
1 |
DefaultWikiDescriptor descriptor = new DefaultWikiDescriptor("wikiid", "wikialias"); |
81 |
1 |
descriptor.addAlias("alias2"); |
82 |
|
|
83 |
1 |
this.mocker.getComponentUnderTest().remove(descriptor); |
84 |
|
|
85 |
1 |
verify(wikiIdCache).remove("wikiid"); |
86 |
1 |
verify(wikiAliasCache).remove("wikialias"); |
87 |
1 |
verify(wikiAliasCache).remove("alias2"); |
88 |
|
} |
89 |
|
|
90 |
|
} |