modules/graphics/src/test/java/test/javafx/concurrent/AbstractTask.java

Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:

@@ -21,13 +21,15 @@
  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  * or visit www.oracle.com if you need additional information or have any
  * questions.
  */
 
-package javafx.concurrent;
+package test.javafx.concurrent;
 
 import java.util.concurrent.Semaphore;
+import javafx.concurrent.Task;
+import javafx.concurrent.TaskShim;
 
 /**
  * For testing purposes, we use this subclass of Task that will fake out the
  * runLater and isFxApplicationThread calls, such that we can actually run
  * and test Task in a single-threaded manner.

@@ -43,11 +45,11 @@
  * mechanism where either can happen. What we will do is use a semaphore for
  * each state. As the state is entered, we will give back a permit for that
  * state. Any code wishing to pick up at the right point can then just acquire
  * the permit to wait for the state to occur and then join.
  */
-public abstract class AbstractTask extends Task<String> {
+public abstract class AbstractTask extends TaskShim<String> {
     public final Semaphore scheduledSemaphore = new Semaphore(0);
     public final Semaphore runningSemaphore = new Semaphore(0);
     public final Semaphore succeededSemaphore = new Semaphore(0);
     public final Semaphore cancelledSemaphore = new Semaphore(0);
     public final Semaphore failedSemaphore = new Semaphore(0);

@@ -55,20 +57,20 @@
     Thread appThread;
     ServiceTestBase test;
     
     // Simulates scheduling the concurrent for execution
     public void simulateSchedule() {
-        setState(State.SCHEDULED);
+        shim_setState(State.SCHEDULED);
     }
 
     // For most tests, we want to pretend that we are on the FX app thread, always.
-    @Override boolean isFxApplicationThread() {
+    @Override public boolean isFxApplicationThread() {
         return appThread == null || Thread.currentThread() == appThread;
     }
 
     // For most tests, we want to just run this stuff immediately
-    @Override void runLater(Runnable r) {
+    @Override public void runLater(Runnable r) {
         if (test != null) {
             test.eventQueue.add(r);
         } else {
             r.run();
         }

@@ -91,6 +93,10 @@
     }
 
     @Override protected void failed() {
         failedSemaphore.release();
     }
+
+    public ServiceTestBase set_test(ServiceTestBase v) {
+        return test = v;
+    }
 }