From 8a0ef8d205cedbce7c0f11db0d5c6b933d66e586 Mon Sep 17 00:00:00 2001 From: Alexei Barantsev Date: Thu, 1 Nov 2018 23:57:52 +0300 Subject: [PATCH] [java] More refactoring firefox executable wrapper --- .../openqa/selenium/firefox/Executable.java | 40 +++++++++---------- .../selenium/firefox/ExecutableTest.java | 4 +- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/java/client/src/org/openqa/selenium/firefox/Executable.java b/java/client/src/org/openqa/selenium/firefox/Executable.java index 05d736fb2c1b1..406b6d900a94e 100644 --- a/java/client/src/org/openqa/selenium/firefox/Executable.java +++ b/java/client/src/org/openqa/selenium/firefox/Executable.java @@ -76,19 +76,19 @@ 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() { @@ -96,21 +96,21 @@ private void loadChannelPref() { 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) { diff --git a/java/client/test/org/openqa/selenium/firefox/ExecutableTest.java b/java/client/test/org/openqa/selenium/firefox/ExecutableTest.java index d692249d31a65..1bc027b9474c7 100644 --- a/java/client/test/org/openqa/selenium/firefox/ExecutableTest.java +++ b/java/client/test/org/openqa/selenium/firefox/ExecutableTest.java @@ -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(); }