From 837da6345aca28d72a071beda30fbb261c2ab944 Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Mon, 15 Aug 2016 13:44:03 +0300 Subject: [PATCH] Cleanup (common code) --- .../com/intellij/execution/GeneralCommandLineTest.java | 3 ++- .../execution/process/BinaryOSProcessHandlerTest.java | 6 ++---- .../intellij/openapi/vfs/local/JarFileSystemTest.java | 3 ++- .../src/com/intellij/testFramework/PlatformTestUtil.java | 9 +++++++-- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/platform/platform-tests/testSrc/com/intellij/execution/GeneralCommandLineTest.java b/platform/platform-tests/testSrc/com/intellij/execution/GeneralCommandLineTest.java index 6cc827a56dc6..e3d0892c0b3f 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/GeneralCommandLineTest.java +++ b/platform/platform-tests/testSrc/com/intellij/execution/GeneralCommandLineTest.java @@ -23,6 +23,7 @@ import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.testFramework.PlatformTestUtil; import com.intellij.util.ArrayUtil; import com.intellij.util.containers.ContainerUtil; import org.intellij.lang.annotations.MagicConstant; @@ -288,7 +289,7 @@ public class GeneralCommandLineTest { assertNotNull(url); GeneralCommandLine commandLine = createCommandLine(); - commandLine.setExePath(System.getProperty("java.home") + (SystemInfo.isWindows ? "\\bin\\java.exe" : "/bin/java")); + commandLine.setExePath(PlatformTestUtil.getJavaExe()); String encoding = System.getProperty("file.encoding"); if (encoding != null) { diff --git a/platform/platform-tests/testSrc/com/intellij/execution/process/BinaryOSProcessHandlerTest.java b/platform/platform-tests/testSrc/com/intellij/execution/process/BinaryOSProcessHandlerTest.java index 4a417082ba82..7f35321a606a 100644 --- a/platform/platform-tests/testSrc/com/intellij/execution/process/BinaryOSProcessHandlerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/execution/process/BinaryOSProcessHandlerTest.java @@ -16,8 +16,8 @@ package com.intellij.execution.process; import com.intellij.openapi.util.Key; -import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.testFramework.PlatformTestUtil; import com.intellij.util.io.BaseOutputReader; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -49,15 +49,13 @@ public class BinaryOSProcessHandlerTest { } private static Process launchTest() throws URISyntaxException, IOException { - String java = System.getProperty("java.home") + (SystemInfo.isWindows ? "\\bin\\java.exe" : "/bin/java"); - String className = Runner.class.getName(); URL url = Runner.class.getClassLoader().getResource(className.replace('.', '/') + ".class"); assertNotNull(url); File dir = new File(url.toURI()); for (int i = 0; i < StringUtil.countChars(className, '.') + 1; i++) dir = dir.getParentFile(); - String[] cmd = {java, "-cp", dir.getPath(), className}; + String[] cmd = {PlatformTestUtil.getJavaExe(), "-cp", dir.getPath(), className}; return new ProcessBuilder(cmd).redirectErrorStream(false).start(); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java index 63746a0ee38c..2a8bf039ebfa 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/vfs/local/JarFileSystemTest.java @@ -26,6 +26,7 @@ import com.intellij.openapi.vfs.newvfs.events.VFileContentChangeEvent; import com.intellij.openapi.vfs.newvfs.events.VFileEvent; import com.intellij.testFramework.PlatformTestUtil; import com.intellij.testFramework.fixtures.BareTestFixtureTestCase; +import com.intellij.util.SystemProperties; import org.jetbrains.annotations.NotNull; import org.junit.Test; @@ -140,7 +141,7 @@ public class JarFileSystemTest extends BareTestFixtureTestCase { VirtualFile entryRoot = JarFileSystem.getInstance().getJarRootForLocalFile(entryFile); assertNull(entryRoot); - VirtualFile nonJarFile = LocalFileSystem.getInstance().findFileByPath(System.getProperty("java.home") + "/lib/calendars.properties"); + VirtualFile nonJarFile = LocalFileSystem.getInstance().findFileByPath(SystemProperties.getJavaHome() + "/lib/calendars.properties"); assertNotNull(nonJarFile); VirtualFile nonJarRoot = JarFileSystem.getInstance().getJarRootForLocalFile(nonJarFile); assertNull(nonJarRoot); diff --git a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java index 355b4e601284..59c5b9c5f18c 100644 --- a/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java +++ b/platform/testFramework/src/com/intellij/testFramework/PlatformTestUtil.java @@ -319,6 +319,7 @@ public class PlatformTestUtil { public static void dispatchAllEventsInIdeEventQueue() throws InterruptedException { assert SwingUtilities.isEventDispatchThread() : Thread.currentThread(); final IdeEventQueue eventQueue = (IdeEventQueue)Toolkit.getDefaultToolkit().getSystemEventQueue(); + //noinspection StatementWithEmptyBody while (dispatchNextEventIfAny(eventQueue) != null); } @@ -506,9 +507,14 @@ public class PlatformTestUtil { Assert.assertEquals(expected, actual); } + @NotNull + public static String getJavaExe() { + return SystemProperties.getJavaHome() + (SystemInfo.isWindows ? "\\bin\\java.exe" : "/bin/java"); + } + @NotNull public static String getRtJarPath() { - String home = System.getProperty("java.home"); + String home = SystemProperties.getJavaHome(); return SystemInfo.isAppleJvm ? FileUtil.toCanonicalPath(home + "/../Classes/classes.jar") : home + "/lib/rt.jar"; } @@ -970,5 +976,4 @@ public class PlatformTestUtil { } ourProjectCleanups.clear(); } - } \ No newline at end of file