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

File WikiDescriptorCacheTest.java

 

Code metrics

0
16
3
1
90
52
3
0.19
5.33
3
1

Classes

Class Line # Actions
WikiDescriptorCacheTest 42 16 0% 3 0
1.0100%
 

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    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    * Unit tests for {@link org.xwiki.wiki.internal.manager.DefaultWikiDescriptorCache}.
39    *
40    * @version $Id: 64b718485068b1aa07b09c89eaead555b7524320 $
41    */
 
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   
 
54  2 toggle @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   
 
64  1 toggle @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   
 
77  1 toggle @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    }