modules/graphics/src/test/java/test/javafx/concurrent/TestServiceFactory.java
Print this page
rev 9250 : 8134762: Refactor Javafx graphics module tests for clear separation of tests
Reviewed-by:
*** 21,31 ****
* 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;
/**
* The Task and Service tests need to do a little trickery due to threading.
* Although in practice they run on different threads (ie: the UI and
* background threads), while testing I want to be able to run predictably
--- 21,35 ----
* 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 test.javafx.concurrent;
!
! import javafx.concurrent.Service;
! import javafx.concurrent.ServiceShim;
! import javafx.concurrent.Task;
/**
* The Task and Service tests need to do a little trickery due to threading.
* Although in practice they run on different threads (ie: the UI and
* background threads), while testing I want to be able to run predictably
*** 35,61 ****
* sure the checkThread does nothing.
*/
public abstract class TestServiceFactory {
public final Thread appThread = Thread.currentThread();
public ServiceTestBase test;
! protected AbstractTask currentTask;
! protected abstract AbstractTask createTestTask();
! protected Service<String> createService() {
! return new Service<String>() {
@Override protected Task<String> createTask() {
currentTask = createTestTask();
! currentTask.test = test;
currentTask.appThread = appThread;
return currentTask;
}
! @Override boolean isFxApplicationThread() {
return Thread.currentThread() == appThread;
}
! @Override void runLater(Runnable r) {
if (test != null) {
test.eventQueue.add(r);
} else {
r.run();
}
--- 39,65 ----
* sure the checkThread does nothing.
*/
public abstract class TestServiceFactory {
public final Thread appThread = Thread.currentThread();
public ServiceTestBase test;
! public AbstractTask currentTask;
! public abstract AbstractTask createTestTask();
! public Service<String> createService() {
! return new ServiceShim<String>() {
@Override protected Task<String> createTask() {
currentTask = createTestTask();
! currentTask.set_test(test);
currentTask.appThread = appThread;
return currentTask;
}
! @Override public boolean isFxApplicationThread() {
return Thread.currentThread() == appThread;
}
! @Override public void runLater(Runnable r) {
if (test != null) {
test.eventQueue.add(r);
} else {
r.run();
}