Clover icon

Coverage Report

  1. Project Clover database Mon Nov 11 2024 15:14:12 GMT
  2. Package jalview.io.cache

File AppCacheTest.java

 

Code metrics

2
21
4
1
80
50
5
0.24
5.25
4
1.25

Classes

Class Line # Actions
AppCacheTest 29 21 5
1.0100%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.io.cache;
22   
23    import java.util.LinkedHashSet;
24   
25    import org.testng.Assert;
26    import org.testng.annotations.BeforeClass;
27    import org.testng.annotations.Test;
28   
 
29    public class AppCacheTest
30    {
31    private AppCache appCache;
32   
33    private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
34   
35    private static final String TEST_FAKE_CACHE_KEY = "CACHE.UNIT_TEST_FAKE";
36   
 
37  1 toggle @BeforeClass(alwaysRun = true)
38    public void setUpCache()
39    {
40  1 appCache = AppCache.getInstance();
41    }
42   
 
43  1 toggle public void generateTestCacheItems()
44    {
45  1 LinkedHashSet<String> testCacheItems = new LinkedHashSet<String>();
46  11 for (int x = 0; x < 10; x++)
47    {
48  10 testCacheItems.add("TestCache" + x);
49    }
50  1 appCache.putCache(TEST_CACHE_KEY, testCacheItems);
51  1 appCache.persistCache(TEST_CACHE_KEY);
52    }
53   
 
54  1 toggle @Test(groups = { "Functional" })
55    public void appCacheTest()
56    {
57  1 LinkedHashSet<String> cacheItems = appCache
58    .getAllCachedItemsFor(TEST_FAKE_CACHE_KEY);
59  1 Assert.assertEquals(cacheItems.size(), 0);
60  1 generateTestCacheItems();
61  1 cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY);
62  1 Assert.assertEquals(cacheItems.size(), 10);
63  1 appCache.deleteCacheItems(TEST_CACHE_KEY);
64  1 cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY);
65  1 Assert.assertEquals(cacheItems.size(), 0);
66    }
67   
 
68  1 toggle @Test(groups = { "Functional" })
69    public void appCacheLimitTest()
70    {
71  1 String limit = appCache.getCacheLimit(TEST_CACHE_KEY);
72  1 Assert.assertEquals(limit, "99");
73  1 limit = String.valueOf(appCache.updateCacheLimit(TEST_CACHE_KEY, 20));
74  1 Assert.assertEquals(limit, "20");
75  1 limit = appCache.getCacheLimit(TEST_CACHE_KEY);
76  1 Assert.assertEquals(limit, "20");
77  1 appCache.updateCacheLimit(TEST_CACHE_KEY, 99);
78    }
79   
80    }