Clover icon

Coverage Report

  1. Project Clover database Thu Aug 13 2020 12:04:21 BST
  2. Package jalview.io.cache

File JvCacheableInputBoxTest.java

 

Code metrics

0
20
3
1
69
53
5
0.25
6.67
3
1.67

Classes

Class Line # Actions
JvCacheableInputBoxTest 9 20 5
0.913043591.3%
 

Contributing tests

This file is covered by 2 tests. .

Source view

1    package jalview.io.cache;
2   
3    import java.util.LinkedHashSet;
4   
5    import org.junit.Assert;
6    import org.testng.annotations.BeforeClass;
7    import org.testng.annotations.Test;
8   
 
9    public class JvCacheableInputBoxTest
10    {
11   
12    private AppCache appCache;
13   
14    private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
15   
16    private JvCacheableInputBox<String> cacheBox = new JvCacheableInputBox<String>(
17    TEST_CACHE_KEY);
18   
 
19  1 toggle @BeforeClass(alwaysRun = true)
20    private void setUpCache()
21    {
22  1 appCache = AppCache.getInstance();
23    }
24   
 
25  1 toggle @Test(groups = { "Functional" })
26    public void getUserInputTest()
27    {
28  1 String userInput = cacheBox.getUserInput();
29  1 Assert.assertEquals("", userInput);
30   
31  1 String testInput = "TestInput";
32  1 cacheBox.addItem(testInput);
33  1 cacheBox.setSelectedItem(testInput);
34   
35  1 try
36    {
37    // This delay is essential to prevent the
38    // assertion below from executing before
39    // swing thread finishes updating the combo-box
40  1 Thread.sleep(100);
41    } catch (InterruptedException e)
42    {
43  0 e.printStackTrace();
44    }
45  1 userInput = cacheBox.getUserInput();
46  1 Assert.assertEquals(testInput, userInput);
47    }
48   
 
49  1 toggle @Test(groups = { "Functional" })
50    public void updateCacheTest()
51    {
52  1 String testInput = "TestInput";
53  1 cacheBox.addItem(testInput);
54  1 cacheBox.setSelectedItem(testInput);
55  1 cacheBox.updateCache();
56  1 try
57    {
58    // This delay is to let
59    // cacheBox.updateCache() finish updating the cache
60  1 Thread.sleep(200);
61    } catch (InterruptedException e)
62    {
63  0 e.printStackTrace();
64    }
65  1 LinkedHashSet<String> foundCache = appCache
66    .getAllCachedItemsFor(TEST_CACHE_KEY);
67  1 Assert.assertTrue(foundCache.contains(testInput));
68    }
69    }