Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.io.cache

File JvCacheableInputBoxTest.java

 
 

Code metrics

0
20
3
1
70
53
5
0.25
6.67
3
1.67

Classes

Class Line # Actions
JvCacheableInputBoxTest 9 20 5 11
0.521739152.2%
 

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  0 toggle @Test(groups = { "Functional" })
50    public void updateCacheTest()
51    {
52  0 String testInput = "TestInput";
53  0 cacheBox.addItem(testInput);
54  0 cacheBox.setSelectedItem(testInput);
55  0 cacheBox.updateCache();
56  0 try
57    {
58    // This 1ms delay is essential to prevent the
59    // assertion below from executing before
60    // cacheBox.updateCache() finishes updating the cache
61  0 Thread.sleep(100);
62    } catch (InterruptedException e)
63    {
64  0 e.printStackTrace();
65    }
66  0 LinkedHashSet<String> foundCache = appCache
67    .getAllCachedItemsFor(TEST_CACHE_KEY);
68  0 Test failure here Assert.assertTrue(foundCache.contains(testInput));
69    }
70    }