Skip to content

Commit

Permalink
[java] More refactoring firefox executable wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
barancev committed Nov 2, 2018
1 parent 7d4cb1a commit 8a0ef8d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
40 changes: 20 additions & 20 deletions java/client/src/org/openqa/selenium/firefox/Executable.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,41 +76,41 @@ private void loadApplicationIni() {
Path applicationIni = getResource("application.ini");
if (Files.exists(applicationIni)) {
try (BufferedReader reader = Files.newBufferedReader(applicationIni)) {
reader.lines().map(String::trim).forEach(line -> {
if (line.startsWith("Version=")) {
version = line.substring("Version=".length());
}
});
version = reader.lines()
.map(String::trim)
.filter(line -> line.startsWith("Version="))
.findFirst()
.map(line -> line.substring("Version=".length()))
.orElseThrow(() -> new WebDriverException("Cannot get version info for Firefox binary " + binary));
} catch (IOException e) {
throw new WebDriverException("Cannot get version info for of Firefox binary " + binary, e);
throw new WebDriverException("Cannot get version info for Firefox binary " + binary, e);
}
return;
} else {
// Set version to something with a ridiculously high number.
version = "1000.0 unknown";
}

// Set version to something with a ridiculously high number.
version = "1000.0 unknown";
}

private void loadChannelPref() {
Path channelPrefs = getResource("defaults/pref/channel-prefs.js");

if (Files.exists(channelPrefs)) {
try (BufferedReader reader = Files.newBufferedReader(channelPrefs)) {
reader.lines().map(String::trim).forEach(line -> {
if (line.startsWith("pref(")) {
channel = FirefoxBinary.Channel.fromString(
channel = reader.lines()
.map(String::trim)
.filter(line -> line.startsWith("pref(\"app.update.channel\""))
.findFirst()
.map(line -> FirefoxBinary.Channel.fromString(
line.substring("pref(\"app.update.channel\", \"".length(),
line.length() - "\");".length()));
}
});
line.length() - "\");".length())))
.orElseThrow(() -> new WebDriverException("Cannot get channel info for Firefox binary " + binary));
} catch (IOException e) {
throw new WebDriverException("Cannot get channel info for Firefox binary " + binary, e);
}
return;
} else {
// Pick a sane default
channel = FirefoxBinary.Channel.RELEASE;
}

// Pick a sane default
channel = FirefoxBinary.Channel.RELEASE;
}

private Path getResource(String resourceName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,14 @@ public void setUp() {
@Test
public void canFindVersion() {
Executable exe = new Executable(new File(binaryPath));
assertThat(exe.getVersion()).isNotEmpty();
System.out.println(exe.getVersion());
assertThat(exe.getVersion()).isNotEmpty().isNotEqualTo("1000.0 unknown");
}

@Test
public void canFindChannel() {
Executable exe = new Executable(new File(binaryPath));
System.out.println(exe.getChannel());
assertThat(exe.getChannel()).isNotNull();
}

Expand Down

0 comments on commit 8a0ef8d

Please sign in to comment.