73aae61fc9fb01441c3f24f232c323a4f8f403b9
[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();
35
36     // try
37     // {
38     // // This delay is essential to prevent the
39     // // assertion below from executing before
40     // // swing thread finishes updating the combo-box
41     // Thread.sleep(100);
42     // } catch (InterruptedException e)
43     // {
44     // e.printStackTrace();
45     // }
46     userInput = cacheBox.getUserInput();
47     Assert.assertEquals(testInput, userInput);
48   }
49
50   @Test(groups = { "Functional" })
51   public void updateCacheTest()
52   {
53     String testInput = "TestInput";
54     cacheBox.addItem(testInput);
55     cacheBox.setSelectedItem(testInput);
56     cacheBox.updateCacheNow();
57     // synchronized (this)
58     // {
59     // try
60     // {
61     // wait(100);
62     // // This delay is to let
63     // // cacheBox.updateCache() finish updating the cache
64     // Thread.sleep(200);
65     // } catch (InterruptedException e)
66     // {
67     // e.printStackTrace();
68     // }
69     // }
70     LinkedHashSet<String> foundCache = appCache
71             .getAllCachedItemsFor(TEST_CACHE_KEY);
72     Assert.assertTrue(foundCache.contains(testInput));
73   }
74 }