### Question:
ApkPathUtils { public String version(final TokenMatcher.State state) { Pattern pattern = Pattern.compile("([0-9]+)(\\.[0-9]+)(\\.[0-9]+)?(-[r][0-9]+)"); String filename = match(state, "filename"); Matcher matcher = pattern.matcher(filename); if (matcher.find()) { MatchResult matchResult = matcher.toMatchResult(); return matchResult.group(0); } return ""; } ApkPathUtils(); String path(final TokenMatcher.State state); String buildIndexPath(final String path); String version(final TokenMatcher.State state); String path(final String path, final String filename); String name(final TokenMatcher.State state); String filename(final TokenMatcher.State state); String archivePath(final String path, final String filename, final String version); TokenMatcher.State matcherState(final Context context);  }### Answer:
@Test public void versionParseTest() throws Exception { when(state.getTokens()).thenReturn(tokens); when(tokens.get("filename")).thenReturn("a2ps-doc-4.14-r5"); String result = underTest.version(state); assertThat(result, is(equalTo("4.14-r5"))); when(tokens.get("filename")).thenReturn("a2ps-doc-4.14.32-r51"); result = underTest.version(state); assertThat(result, is(equalTo("4.14.32-r51"))); }
@Test public void versionWithDotParseTest() throws Exception { when(state.getTokens()).thenReturn(tokens); when(tokens.get("filename")).thenReturn("lua5.3-libs-5.3.5-r2"); assertThat(underTest.version(state), is(equalTo("5.3.5-r2"))); }