7a2f8b406198f1e2e6615826d91bd062a21a07bb
[jalview.git] / test / jalview / io / cache / JvCacheableInputBoxTest.java
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<>(
17           TEST_CACHE_KEY);
18
19   @BeforeClass(alwaysRun = true)
20   private void setUpCache()
21   {
22     appCache = AppCache.getInstance();
23   }
24
25   @Test(groups = { "Functional" })
26   public void getUserInputTest()
27   {
28     String userInput = cacheBox.getUserInput();
29     Assert.assertEquals("", userInput);
30
31     String testInput = "TestInput";
32     cacheBox.addItem(testInput);
33     cacheBox.setSelectedItem(testInput);
34     cacheBox.updateCacheNow(); // synchronous update
35     userInput = cacheBox.getUserInput();
36     Assert.assertEquals(testInput, userInput);
37   }
38
39   @Test(groups = { "Functional" })
40   public void updateCacheTest()
41   {
42     String testInput = "TestInput";
43     cacheBox.addItem(testInput);
44     cacheBox.setSelectedItem(testInput);
45     cacheBox.updateCacheNow();
46     LinkedHashSet<String> foundCache = appCache
47             .getAllCachedItemsFor(TEST_CACHE_KEY);
48     Assert.assertTrue(foundCache.contains(testInput));
49   }
50 }