@Test public void testParseString() throws Exception { JsfVersionInspector enforcer = new JsfVersionInspector(""); JsfVersionInspector.Version version; version = enforcer.parseVersion("2.0.6"); Assert.assertEquals(2, version.major); Assert.assertEquals(0, version.minor); Assert.assertEquals(6, version.micro); Assert.assertEquals("", version.qualifier); version = enforcer.parseVersion("2.1.27.redhat-9"); Assert.assertEquals(2, version.major); Assert.assertEquals(1, version.minor); Assert.assertEquals(27, version.micro); Assert.assertEquals("redhat-9", version.qualifier); version = enforcer.parseVersion("2.1.4-jbossorg-1"); Assert.assertEquals(2, version.major); Assert.assertEquals(1, version.minor); Assert.assertEquals(4, version.micro); Assert.assertEquals("jbossorg-1", version.qualifier); version = enforcer.parseVersion("2.1.6-SNAPSHOT"); Assert.assertEquals(2, version.major); Assert.assertEquals(1, version.minor); Assert.assertEquals(6, version.micro); Assert.assertEquals("SNAPSHOT", version.qualifier); }
Version parseVersion(String versionString) { String qualifier; String[] numbers; if (versionString.matches("[0-9][0-9\\.]*\\-[a-zA-Z0-9\\-]*")) { String[] parts = versionString.split("-", 2); numbers = parts[0].split("\\.", 4); qualifier = parts[1]; } else { numbers = versionString.split("\\.", 5); qualifier = numbers.length > 3 ? numbers[3] : ""; } Version version; try { version = new Version(Integer.parseInt(numbers[0]), Integer.parseInt(numbers[1]), Integer.parseInt(numbers[2]), qualifier); } catch (NumberFormatException e) { throw new RuntimeException(MessageFormat.format("Error parsing detected JSF version string: {0} ", versionString), e); } return version; }
JsfVersionInspector { Version parseVersion(String versionString) { String qualifier; String[] numbers; if (versionString.matches("[0-9][0-9\\.]*\\-[a-zA-Z0-9\\-]*")) { String[] parts = versionString.split("-", 2); numbers = parts[0].split("\\.", 4); qualifier = parts[1]; } else { numbers = versionString.split("\\.", 5); qualifier = numbers.length > 3 ? numbers[3] : ""; } Version version; try { version = new Version(Integer.parseInt(numbers[0]), Integer.parseInt(numbers[1]), Integer.parseInt(numbers[2]), qualifier); } catch (NumberFormatException e) { throw new RuntimeException(MessageFormat.format("Error parsing detected JSF version string: {0} ", versionString), e); } return version; } }
JsfVersionInspector { Version parseVersion(String versionString) { String qualifier; String[] numbers; if (versionString.matches("[0-9][0-9\\.]*\\-[a-zA-Z0-9\\-]*")) { String[] parts = versionString.split("-", 2); numbers = parts[0].split("\\.", 4); qualifier = parts[1]; } else { numbers = versionString.split("\\.", 5); qualifier = numbers.length > 3 ? numbers[3] : ""; } Version version; try { version = new Version(Integer.parseInt(numbers[0]), Integer.parseInt(numbers[1]), Integer.parseInt(numbers[2]), qualifier); } catch (NumberFormatException e) { throw new RuntimeException(MessageFormat.format("Error parsing detected JSF version string: {0} ", versionString), e); } return version; } JsfVersionInspector();   JsfVersionInspector(String versionString); }
JsfVersionInspector { Version parseVersion(String versionString) { String qualifier; String[] numbers; if (versionString.matches("[0-9][0-9\\.]*\\-[a-zA-Z0-9\\-]*")) { String[] parts = versionString.split("-", 2); numbers = parts[0].split("\\.", 4); qualifier = parts[1]; } else { numbers = versionString.split("\\.", 5); qualifier = numbers.length > 3 ? numbers[3] : ""; } Version version; try { version = new Version(Integer.parseInt(numbers[0]), Integer.parseInt(numbers[1]), Integer.parseInt(numbers[2]), qualifier); } catch (NumberFormatException e) { throw new RuntimeException(MessageFormat.format("Error parsing detected JSF version string: {0} ", versionString), e); } return version; } JsfVersionInspector();   JsfVersionInspector(String versionString); boolean verifyJsfImplVersion(); String getVersionString(); }
JsfVersionInspector { Version parseVersion(String versionString) { String qualifier; String[] numbers; if (versionString.matches("[0-9][0-9\\.]*\\-[a-zA-Z0-9\\-]*")) { String[] parts = versionString.split("-", 2); numbers = parts[0].split("\\.", 4); qualifier = parts[1]; } else { numbers = versionString.split("\\.", 5); qualifier = numbers.length > 3 ? numbers[3] : ""; } Version version; try { version = new Version(Integer.parseInt(numbers[0]), Integer.parseInt(numbers[1]), Integer.parseInt(numbers[2]), qualifier); } catch (NumberFormatException e) { throw new RuntimeException(MessageFormat.format("Error parsing detected JSF version string: {0} ", versionString), e); } return version; } JsfVersionInspector();   JsfVersionInspector(String versionString); boolean verifyJsfImplVersion(); String getVersionString();  }