From: tcofoegbu Date: Mon, 24 Apr 2017 10:30:03 +0000 (+0100) Subject: JAL-1648 added unit test for AppCache X-Git-Tag: Release_2_10_2~3^2~45^2~9 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=cdc45593d3a88815b578481f711cadad6ccfe262;p=jalview.git JAL-1648 added unit test for AppCache --- diff --git a/src/jalview/io/cache/AppCache.java b/src/jalview/io/cache/AppCache.java index fc528ef..9663c98 100644 --- a/src/jalview/io/cache/AppCache.java +++ b/src/jalview/io/cache/AppCache.java @@ -173,7 +173,7 @@ public class AppCache * * @return */ - private Hashtable> getCacheItems() + Hashtable> getCacheItems() { return cacheItems; } diff --git a/src/jalview/io/cache/JvCacheableInputBox.java b/src/jalview/io/cache/JvCacheableInputBox.java index 6101bdd..3475d4f 100644 --- a/src/jalview/io/cache/JvCacheableInputBox.java +++ b/src/jalview/io/cache/JvCacheableInputBox.java @@ -65,6 +65,7 @@ public class JvCacheableInputBox extends JComboBox private void initCachePopupMenu() { pnlDefaultCache.setBackground(Color.WHITE); + // pad panel so as to align with other menu items pnlDefaultCache.setBorder(BorderFactory.createEmptyBorder(0, 19, 0, 0)); txtDefaultCacheSize.setPreferredSize(new Dimension(45, 20)); lblDefaultCacheSize.setText(MessageManager @@ -113,7 +114,7 @@ public class JvCacheableInputBox extends JComboBox * @param text * @return */ - private boolean isInteger(String text) + static boolean isInteger(String text) { try { diff --git a/test/jalview/io/cache/AppCacheTest.java b/test/jalview/io/cache/AppCacheTest.java new file mode 100644 index 0000000..ef75869 --- /dev/null +++ b/test/jalview/io/cache/AppCacheTest.java @@ -0,0 +1,73 @@ +package jalview.io.cache; + +import java.util.LinkedHashSet; + +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +public class AppCacheTest +{ + private AppCache appCache; + + private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST"; + + private static final String TEST_FAKE_CACHE_KEY = "CACHE.UNIT_TEST_FAKE"; + + @BeforeClass(alwaysRun = true) + public void setUpCache() + { + appCache = AppCache.getInstance(); + } + + public void generateTestCacheItems() + { + LinkedHashSet testCacheItems = new LinkedHashSet(); + for (int x = 0; x < 10; x++) + { + testCacheItems.add("TestCache" + x); + } + appCache.putCache(TEST_CACHE_KEY, testCacheItems); + appCache.persistCache(TEST_CACHE_KEY); + } + + @Test(groups = { "Functional" }) + public void appCacheTest() + { + LinkedHashSet cacheItems = appCache + .getAllCachedItemsFor(TEST_FAKE_CACHE_KEY); + Assert.assertEquals(cacheItems.size(), 0); + generateTestCacheItems(); + cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY); + Assert.assertEquals(cacheItems.size(), 10); + appCache.deleteCacheItems(TEST_CACHE_KEY); + cacheItems = appCache.getAllCachedItemsFor(TEST_CACHE_KEY); + Assert.assertEquals(cacheItems.size(), 0); + } + + @Test(groups = { "Functional" }) + public void appCacheLimitTest() + { + String limit = appCache.getCacheLmit(TEST_CACHE_KEY); + Assert.assertEquals(limit, "99"); + limit = String.valueOf(appCache.updateCacheLimit(TEST_CACHE_KEY, "20")); + Assert.assertEquals(limit, "20"); + limit = appCache.getCacheLmit(TEST_CACHE_KEY); + Assert.assertEquals(limit, "20"); + appCache.updateCacheLimit(TEST_CACHE_KEY, "99"); + } + + @Test(groups = { "Functional" }) + public void initCacheTest() + { + appCache.initCache(TEST_CACHE_KEY); + Assert.assertTrue(appCache.getCacheItems().containsKey(TEST_CACHE_KEY)); + generateTestCacheItems(); + // appCache. + appCache.initCache(TEST_CACHE_KEY); + // + Assert.assertTrue(appCache.getCacheItems().containsKey(TEST_CACHE_KEY)); + appCache.deleteCacheItems(TEST_CACHE_KEY); + } + +}