Skip to content

Commit 37667f7

Browse files
author
ph7
committed
Agent: Fixing unit tests on Windows
git-svn-id: https://svn.openqa.org/svn/selenium-grid/trunk@359 22590ab4-ef3b-0410-9bef-a9f5a1089f47
1 parent 5ccaf15 commit 37667f7

2 files changed

Lines changed: 23 additions & 8 deletions

File tree

agent/src/main/java/com/thoughtworks/selenium/grid/agent/JVMLauncher.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public JVMLauncher(Classpath classpath, String mainClass) {
2020

2121
public JVMHandle launchNewJVM() throws IOException, InterruptedException {
2222
return new JVMHandle(newProcessBuilder().start());
23-
}
23+
}
2424

2525
protected ProcessBuilder newProcessBuilder() {
2626
final ProcessBuilder builder;
@@ -50,8 +50,16 @@ protected List<String> command() {
5050
protected String javaLauncherPath() {
5151
File javaLauncher;
5252

53-
javaLauncher = new File(System.getProperty("java.home") + "/bin/java");
53+
javaLauncher = new File(System.getProperty("java.home") + "/bin/java" + executableSuffix());
5454
return javaLauncher.getAbsolutePath();
5555
}
56+
57+
protected String executableSuffix() {
58+
return onWindows() ? ".exe" : "";
59+
}
60+
61+
protected boolean onWindows() {
62+
return -1 != System.getProperty("os.name").indexOf("Windows");
63+
}
5664

5765
}

agent/src/test/unit/java/com/thoughtworks/selenium/grid/agent/JVMLauncherTest.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,22 @@ public void classpathIsTheOneProvidedInTheConstructor() {
2020

2121
@Test
2222
public void javaLauncherPathIsAValidFilePath() {
23-
assertTrue(new File(new JVMLauncher(new Classpath(), "").javaLauncherPath()).exists());
23+
final String javaLauncherPath;
24+
25+
javaLauncherPath = new JVMLauncher(new Classpath(), "").javaLauncherPath();
26+
assertTrue(javaLauncherPath, new File(javaLauncherPath).exists());
2427
}
2528

2629
@Test
27-
public void javaLauncherPathEndsWithJava() {
28-
final JVMLauncher launcher;
29-
30-
launcher = new JVMLauncher(new Classpath(), "");
31-
assertTrue(launcher.javaLauncherPath().endsWith(File.separator + "java"));
30+
public void javaLauncherPathEndsWithJavaExecutable() {
31+
final String launcherPath;
32+
33+
launcherPath = new JVMLauncher(new Classpath(), "").javaLauncherPath();
34+
if (-1 != System.getProperty("os.name").indexOf("Windows")) {
35+
assertTrue(launcherPath, launcherPath.endsWith(File.separator + "java.exe"));
36+
} else {
37+
assertTrue(launcherPath, launcherPath.endsWith(File.separator + "java"));
38+
}
3239
}
3340

3441
@Test

0 commit comments

Comments
 (0)