### Question:
ApkPathUtils { public String name(final TokenMatcher.State state) { Pattern pattern = Pattern.compile("(.*)-([.0-9]+[a-zA-Z]?)(_?(alpha|beta|pre|rc|cvs|svn|git|hg|p)?([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(1); } 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 nameParseTest() throws Exception { when(state.getTokens()).thenReturn(tokens); when(tokens.get("filename")).thenReturn("a2ps-doc-4.14-r5"); String result = underTest.name(state); assertThat(result, is(equalTo("a2ps-doc"))); when(tokens.get("filename")).thenReturn("a2ps-doc-4.14.32-r51"); result = underTest.name(state); assertThat(result, is(equalTo("a2ps-doc"))); }
@Test public void nameWithDotParseTest() throws Exception { when(state.getTokens()).thenReturn(tokens); when(tokens.get("filename")).thenReturn("lua5.3-libs-5.3.5-r2"); assertThat(underTest.name(state), is(equalTo("lua5.3-libs"))); }