BambooVersionExtractor { static String extractVersion(URL url) throws BambooVersionNotFoundException { InputStream stream = null; try { stream = url.openStream(); byte[] bytes = ByteStreams.toByteArray(stream); String page = new String(bytes); return extractVersion(page); } catch (IOException e) { throw new BambooVersionNotFoundException("Can't extract version from url:" + url, e); } finally { Closeables.closeQuietly(stream); } } private  BambooVersionExtractor();   }
@Test public void should_extract_version() throws Exception { String content = "Atlassian Bamboo</a> version 2.7.1 build 2101 -"; String version = BambooVersionExtractor.extractVersion(content); assertEquals("2.7.1", version); }
@Test(expected = BambooVersionNotFoundException.class) public void should_throw_exception_if_version_is_not_found() throws BambooVersionNotFoundException { BambooVersionExtractor.extractVersion(""); }