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<String>(
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);
37 // This 1ms delay is essential to prevent the
38 // assertion below from executing before
39 // swing thread finishes updating the combo-box
41 } catch (InterruptedException e)
45 userInput = cacheBox.getUserInput();
46 Assert.assertEquals(testInput, userInput);
49 @Test(groups = { "Functional" })
50 public void updateCacheTest()
52 String testInput = "TestInput";
53 cacheBox.addItem(testInput);
54 cacheBox.setSelectedItem(testInput);
55 cacheBox.updateCache();
58 // This 1ms delay is essential to prevent the
59 // assertion below from executing before
60 // cacheBox.updateCache() finishes updating the cache
62 } catch (InterruptedException e)
66 LinkedHashSet<String> foundCache = appCache
67 .getAllCachedItemsFor(TEST_CACHE_KEY);
68 Assert.assertTrue(foundCache.contains(testInput));