JavaVersion implements Comparable<JavaVersion> { public static JavaVersion fromString(String s) { final Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+).*"); final Matcher matcher = pattern.matcher(s); final boolean b = matcher.find(); if (b) { return new JavaVersion( Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)), Integer.parseInt(matcher.group(3))); } return new JavaVersion(100, 0, 0); } JavaVersion(int version, int major, int minor); static void main(String[] args); static JavaVersion fromString(String s); @Override int compareTo(JavaVersion o); @Override String toString(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test(dataProvider = "fromString") public void testFromString(String string, JavaVersion version) throws Exception { assertEquals(JavaVersion.fromString(string),version); }