浏览代码

use single method to initialize JavaFX

Armin Schrenk 4 月之前
父节点
当前提交
1fb987607c

+ 20 - 0
src/main/java/org/cryptomator/JavaFXUtil.java

@@ -0,0 +1,20 @@
+package org.cryptomator;
+
+import javafx.application.Platform;
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+public class JavaFXUtil {
+
+	public static boolean startPlatform() throws InterruptedException {
+		CountDownLatch latch = new CountDownLatch(1);
+		try {
+			Platform.startup(latch::countDown);
+		} catch (IllegalStateException e) {
+			//already initialized
+			latch.countDown();
+		}
+		return latch.await(5, TimeUnit.SECONDS);
+	}
+
+}

+ 3 - 9
src/test/java/org/cryptomator/common/keychain/KeychainManagerTest.java

@@ -1,6 +1,7 @@
 package org.cryptomator.common.keychain;
 
 
+import org.cryptomator.JavaFXUtil;
 import org.cryptomator.integrations.keychain.KeychainAccessException;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Assumptions;
@@ -21,15 +22,8 @@ public class KeychainManagerTest {
 
 	@BeforeAll
 	public static void startup() throws InterruptedException {
-		CountDownLatch latch = new CountDownLatch(1);
-		try {
-			Platform.startup(latch::countDown);
-		} catch (IllegalStateException e) {
-			//already initialized
-			latch.countDown();
-		}
-		var javafxStarted = latch.await(5, TimeUnit.SECONDS);
-		Assumptions.assumeTrue(javafxStarted);
+		var isRunning = JavaFXUtil.startPlatform();
+		Assumptions.assumeTrue(isRunning);
 	}
 
 	@Test

+ 3 - 4
src/test/java/org/cryptomator/ui/controls/SecurePasswordFieldTest.java

@@ -1,5 +1,6 @@
 package org.cryptomator.ui.controls;
 
+import org.cryptomator.JavaFXUtil;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Assumptions;
@@ -18,10 +19,8 @@ public class SecurePasswordFieldTest {
 
 	@BeforeAll
 	public static void initJavaFx() throws InterruptedException {
-		CountDownLatch latch = new CountDownLatch(1);
-		Platform.startup(latch::countDown);
-		var javafxStarted = latch.await(5, TimeUnit.SECONDS);
-		Assumptions.assumeTrue(javafxStarted);
+		var isRunning = JavaFXUtil.startPlatform();
+		Assumptions.assumeTrue(isRunning);
 	}
 
 	@Nested