VersionUtil { public static Version extract(String version) { if (version == null || !version.matches(expression)) { return new Version(0, 0); } return new Version( Integer.parseInt(version.replaceAll(expression, "$1")), Integer.parseInt(version.replaceAll(expression, "$2"))); } private  VersionUtil(); static Version extract(String version); static boolean isGreaterThenOrEqual(String greater, String then); static boolean isGreaterThenOrEqual(Version greater, Version then); static boolean isLessThenOrEqual(String less, String then); static boolean isLessThenOrEqual(Version less, Version then);  }
@Test public void shouldBeAbleToExtract() throws Exception { Version version = VersionUtil.extract("1.2"); Assert.assertEquals(1, version.getMajor()); Assert.assertEquals(2, version.getMinor()); }
@Test public void shouldBeAbleToExtractWithMultipleDigits() throws Exception { Version version = VersionUtil.extract("10.300"); Assert.assertEquals(10, version.getMajor()); Assert.assertEquals(300, version.getMinor()); }
@Test public void shouldBeAbleToExtractWithBuild() throws Exception { Version version = VersionUtil.extract("1.2.50.A"); Assert.assertEquals(1, version.getMajor()); Assert.assertEquals(2, version.getMinor()); }
@Test public void shouldReturnZeroVersionOnNull() throws Exception { Version version = VersionUtil.extract(null); Assert.assertEquals(0, version.getMajor()); Assert.assertEquals(0, version.getMinor()); }
@Test public void shouldReturnZeroVersionOnNullUnMatched() throws Exception { Version version = VersionUtil.extract("243223.A"); Assert.assertEquals(0, version.getMajor()); Assert.assertEquals(0, version.getMinor()); }