JAL-4513 reduce wait to invoke fail
[jalview.git] / test / jalview / io / cache / JvCacheableInputBoxTest.java
index 6c79f31..3ed15ac 100644 (file)
@@ -1,3 +1,23 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ * 
+ * This file is part of Jalview.
+ * 
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License 
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *  
+ * Jalview is distributed in the hope that it will be useful, but 
+ * WITHOUT ANY WARRANTY; without even the implied warranty 
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
+ * PURPOSE.  See the GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
 package jalview.io.cache;
 
 import java.util.LinkedHashSet;
@@ -13,8 +33,8 @@ public class JvCacheableInputBoxTest
 
   private static final String TEST_CACHE_KEY = "CACHE.UNIT_TEST";
 
-  private JvCacheableInputBox<String> cacheBox = new JvCacheableInputBox<String>(
-          TEST_CACHE_KEY);
+  private JvCacheableInputBox<String> cacheBox = new JvCacheableInputBox<>(
+          TEST_CACHE_KEY, 20);
 
   @BeforeClass(alwaysRun = true)
   private void setUpCache()
@@ -32,16 +52,28 @@ public class JvCacheableInputBoxTest
     cacheBox.addItem(testInput);
     cacheBox.setSelectedItem(testInput);
 
+    /*
+    try
+    {
+      SwingUtilities.invokeAndWait(() -> {
+      */
     try
     {
       // This delay is essential to prevent the
       // assertion below from executing before
       // swing thread finishes updating the combo-box
-      Thread.sleep(100);
+      Thread.sleep(10);
     } catch (InterruptedException e)
     {
       e.printStackTrace();
     }
+    ; /*
+      });
+      } catch (InvocationTargetException | InterruptedException e)
+      {
+      e.printStackTrace();
+      }
+      */
     userInput = cacheBox.getUserInput();
     Assert.assertEquals(testInput, userInput);
   }
@@ -53,16 +85,28 @@ public class JvCacheableInputBoxTest
     cacheBox.addItem(testInput);
     cacheBox.setSelectedItem(testInput);
     cacheBox.updateCache();
+
+    /*
     try
     {
-      // This 1ms delay is essential to prevent the
-      // assertion below from executing before
-      // cacheBox.updateCache() finishes updating the cache
-      Thread.sleep(100);
+      SwingUtilities.invokeAndWait(() -> {
+       */
+    try
+    {
+      // This delay is to let
+      // cacheBox.updateCache() finish updating the cache
+      Thread.sleep(1);
     } catch (InterruptedException e)
     {
       e.printStackTrace();
     }
+    ; /*
+      });
+      } catch (InvocationTargetException | InterruptedException e)
+      {
+      e.printStackTrace();
+      }
+      */
     LinkedHashSet<String> foundCache = appCache
             .getAllCachedItemsFor(TEST_CACHE_KEY);
     Assert.assertTrue(foundCache.contains(testInput));