RemoveTrailingCharactersVersionTransformer { public String transform(String version) throws NumberFormatException { final String originalVersion = version; if (version == null) throw new NullPointerException("Version was null."); String[] parts = version.split("\\."); List<String> result = new ArrayList<String>(); int length = (limit == -1 ? parts.length : Math.min(parts.length, limit)); for (int i = 0; i < length; i++) { String part = removeTrailingNonNumbers(parts[i]); if (part.trim().isEmpty()) part = "0"; if (Long.parseLong(part) < 0) { throw new NumberFormatException("Invalid version found: '" + originalVersion + "'. Negativ version part found: " + parts[i] + "."); } result.add(part); if (!parts[i].matches("\\d+")) break; } while (result.size() < limit) result.add("0"); return StringUtils.join(result, '.'); } RemoveTrailingCharactersVersionTransformer();   RemoveTrailingCharactersVersionTransformer(final int limit); String transform(String version);  }
@Test public void testCFBundleShortVersionStringThreeDotVersion() throws Exception { assertEquals("1.2.3", cfBundleShortVersionStringTransformer.transform("1.2.3")); }
@Test public void testCFBundleShortVersionStringEmptyVersion() { assertEquals("0.0.0", cfBundleShortVersionStringTransformer.transform("")); }
@Test(expected = NullPointerException.class) public void tesCFBundleShortVersionStringNullVersion() { cfBundleShortVersionStringTransformer.transform(null); }
@Test public void testCFBundleShortVersionStringVersionEndsWithDot() { assertEquals("1.0.0", cfBundleShortVersionStringTransformer.transform("1.")); }
@Test public void testCFBundleShortVersionStringVersionWithAlpha() { assertEquals("1.0.0", cfBundleShortVersionStringTransformer.transform("1.alpha-1.2")); }
@Test public void testCFBundleShortVersionStringVersionWithAlphaAppendix() { assertEquals("1.1.0", cfBundleShortVersionStringTransformer.transform("1.1-alpha-1.2")); }
@Test public void testCFBundleVersionDoNotTruncateVersion() { assertEquals("1.2.3.4", cfBundleVersionTransformer.transform("1.2.3.4")); }
@Test public void testCFBundleShortVersionStringVersionWithLeadingZero() throws Exception { assertEquals("1.02.3", cfBundleShortVersionStringTransformer.transform("1.02.3")); }
@Test(expected = NumberFormatException.class) public void testCFBundleShortVersionStringVersionWithNegativeVersionPart() throws Exception { cfBundleShortVersionStringTransformer.transform("1.-2.3"); }
@Test public void testCFBundleShortVersionStringLongVersion() throws Exception { long part = System.currentTimeMillis(); assertEquals("1.2." + part, cfBundleShortVersionStringTransformer.transform("1.2." + part)); }
@Test public void testCFBundleShortVersionStringTwoDotSnapshotVersion() { assertEquals("1.2.0", cfBundleShortVersionStringTransformer.transform("1.2-SNAPSHOT")); }
@Test public void testCFBundleShortVersionStringThreeDotSnapshotVersion() { assertEquals("1.2.3", cfBundleShortVersionStringTransformer.transform("1.2.3-SNAPSHOT")); }
@Test public void testCFBundleShortVersionStringTruncateVersion() { assertEquals("1.2.3", cfBundleShortVersionStringTransformer.transform("1.2.3.4")); }
@Test public void testCFBundleShortVersionStringTruncateSnapshotVersion() { assertEquals("1.2.3", cfBundleShortVersionStringTransformer.transform("1.2.3.4-SNAPSHOT")); }
@Test public void testCFBundleShortVersionStringShortVersion() { assertEquals("1.2.0", cfBundleShortVersionStringTransformer.transform("1.2")); }
@Test public void testCFBundleShortVersionStringVersionWithoutDot() { assertEquals("1.0.0", cfBundleShortVersionStringTransformer.transform("1")); }