Skip to content

Instantly share code, notes, and snippets.

@delitescere
Created May 4, 2012 12:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save delitescere/2594472 to your computer and use it in GitHub Desktop.
Save delitescere/2594472 to your computer and use it in GitHub Desktop.
lazy val defaultBrowserVersion = Play.configuration.getString("snapshot.browserVersion")
.map(extractVersion _)
.getOrElse(BrowserVersion.FIREFOX_3_6) // Firefox 3.6 makes a good default because it works on all OSes
// Do you really need to throw an exception? Why not log it as an error, and return None so you end up with the default above?
def extractVersion(browserString: String): Option[BrowserVersion] = {
allCatch opt {
Some(classOf[BrowserVersion].getField(browserString).get(null).asInstanceOf[BrowserVersion])
}
.getOrElse {
Logger.error("Browser version not defined in HTMLUnit %s" format browserString)
None
}
}
@delitescere
Copy link
Author

Of course you have unit tests, don't you James?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment