From cdc45593d3a88815b578481f711cadad6ccfe262 Mon Sep 17 00:00:00 2001 From: tcofoegbu Date: Mon, 24 Apr 2017 11:30:03 +0100 Subject: [PATCH] JAL-1648 added unit test for AppCache --- src/jalview/io/cache/AppCache.java | 2 +- src/jalview/io/cache/JvCacheableInputBox.java | 3 +- test/jalview/io/cache/AppCacheTest.java | 73 +++++++++++++++++++++++++ 3 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 test/jalview/io/cache/AppCacheTest.java 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); + } + +} -- 1.7.10.2