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

File AbstractTestCache.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

0
7
3
1
103
35
3
0.43
2.33
3
1

Classes

Class Line # Actions
AbstractTestCache 35 7 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 12 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.cache.tests;
21   
22    import org.junit.Assert;
23    import org.junit.Before;
24    import org.junit.Rule;
25    import org.xwiki.cache.CacheFactory;
26    import org.xwiki.cache.CacheManager;
27    import org.xwiki.configuration.internal.MemoryConfigurationSource;
28    import org.xwiki.test.mockito.MockitoComponentManagerRule;
29   
30    /**
31    * Base class for testing cache component implementation.
32    *
33    * @version $Id: 850ab935fe2244133566e5262b7e01119ffcf795 $
34    */
 
35    public abstract class AbstractTestCache
36    {
37    /**
38    * The first key.
39    */
40    protected static final String KEY = "key";
41   
42    /**
43    * The second key.
44    */
45    protected static final String KEY2 = "key2";
46   
47    /**
48    * The value of the first key.
49    */
50    protected static final String VALUE = "value";
51   
52    /**
53    * The value of the second key.
54    */
55    protected static final int VALUE2 = 2;
56   
57    /**
58    * The Mockito tool.
59    */
60    @Rule
61    public MockitoComponentManagerRule componentManager = new MockitoComponentManagerRule();
62   
63    /**
64    * The role hint of the cache component implementation to test.
65    */
66    protected String roleHint;
67   
68    /**
69    * @param roleHint the role hint of the cache component implementation to test.
70    */
 
71  12 toggle protected AbstractTestCache(String roleHint)
72    {
73  12 this.roleHint = roleHint;
74    }
75   
76    /**
77    * Before.
78    *
79    * @throws Exception when initialization fail
80    */
 
81  12 toggle @Before
82    public void before() throws Exception
83    {
84  12 MemoryConfigurationSource configuration = this.componentManager.registerMemoryConfigurationSource();
85   
86  12 configuration.setProperty("cache.defaultCache", this.roleHint);
87    }
88   
89    /**
90    * @return a instance of the cache factory.
91    * @throws Exception error when searching for cache factory component.
92    */
 
93  13 toggle public CacheFactory getCacheFactory() throws Exception
94    {
95  13 CacheManager cacheManager = this.componentManager.getInstance(CacheManager.class);
96   
97  13 CacheFactory factory = cacheManager.getCacheFactory();
98   
99  13 Assert.assertNotNull(factory);
100   
101  13 return factory;
102    }
103    }