1 package jalview.io.cache;
3 import java.util.LinkedHashSet;
5 import org.junit.Assert;
6 import org.testng.annotations.BeforeClass;
7 import org.testng.annotations.Test;
9 public class JvCacheableInputBoxTest
12 private AppCache appCache;
14 private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
16 private JvCacheableInputBox<String> cacheBox = new JvCacheableInputBox<>(
19 @BeforeClass(alwaysRun = true)
20 private void setUpCache()
22 appCache = AppCache.getInstance();
25 @Test(groups = { "Functional" })
26 public void getUserInputTest()
28 String userInput = cacheBox.getUserInput();
29 Assert.assertEquals("", userInput);
31 String testInput = "TestInput";
32 cacheBox.addItem(testInput);
33 cacheBox.setSelectedItem(testInput);
34 cacheBox.updateCacheNow();
38 // // This delay is essential to prevent the
39 // // assertion below from executing before
40 // // swing thread finishes updating the combo-box
42 // } catch (InterruptedException e)
44 // e.printStackTrace();
46 userInput = cacheBox.getUserInput();
47 Assert.assertEquals(testInput, userInput);
50 @Test(groups = { "Functional" })
51 public void updateCacheTest()
53 String testInput = "TestInput";
54 cacheBox.addItem(testInput);
55 cacheBox.setSelectedItem(testInput);
56 cacheBox.updateCacheNow();
57 // synchronized (this)
62 // // This delay is to let
63 // // cacheBox.updateCache() finish updating the cache
65 // } catch (InterruptedException e)
67 // e.printStackTrace();
70 LinkedHashSet<String> foundCache = appCache
71 .getAllCachedItemsFor(TEST_CACHE_KEY);
72 Assert.assertTrue(foundCache.contains(testInput));