### Question:
PathExpression implements Serializable { protected String removeUnusedPredicates( String expression ) { assert expression != null; java.util.regex.Matcher matcher = UNUSABLE_PREDICATE_PATTERN.matcher(expression); StringBuffer sb = new StringBuffer(); if (matcher.find()) { do { String predicateStr = matcher.group(0); String unusablePredicateStr = matcher.group(1); if (unusablePredicateStr != null) { predicateStr = ""; } matcher.appendReplacement(sb, predicateStr); } while (matcher.find()); matcher.appendTail(sb); expression = sb.toString(); } return expression; } PathExpression( String expression ); static final PathExpression compile( String expression ); String getExpression(); String getSelectExpression(); @Override int hashCode(); @Override boolean equals( Object obj ); @Override String toString(); Matcher matcher( String absolutePath ); boolean matchesAnything(); static PathExpression all(); static RepositoryPath parseRepositoryPath( String path );  }### Answer:
@Test public void shouldNotRemoveUsedPredicates() { assertThat(expr.removeUnusedPredicates("/a/b/c"), is("/a/b/c")); assertThat(expr.removeUnusedPredicates("/a/b[0]/c"), is("/a/b[0]/c")); assertThat(expr.removeUnusedPredicates("/a/b[1]/c"), is("/a/b[1]/c")); assertThat(expr.removeUnusedPredicates("/a/b[10]/c"), is("/a/b[10]/c")); assertThat(expr.removeUnusedPredicates("/a/b[100]/c"), is("/a/b[100]/c")); assertThat(expr.removeUnusedPredicates("/a/b[1000]/c"), is("/a/b[1000]/c")); assertThat(expr.removeUnusedPredicates("/a/b[]/c"), is("/a/b[]/c")); assertThat(expr.removeUnusedPredicates("/a/b[*]/c"), is("/a/b[*]/c")); assertThat(expr.removeUnusedPredicates("/a/b[1,2]/c"), is("/a/b[1,2]/c")); assertThat(expr.removeUnusedPredicates("/a/b[1,2,3,4,5]/c"), is("/a/b[1,2,3,4,5]/c")); assertThat(expr.removeUnusedPredicates("/a/b/c[@title]"), is("/a/b/c[@title]")); assertThat(expr.removeUnusedPredicates("/a/b/c[d/e/@title]"), is("/a/b/c[d/e/@title]")); assertThat(expr.removeUnusedPredicates("/a/(b/c)[(d|e)/(f|g)/@something]"), is("/a/(b/c)[(d|e)/(f|g)/@something]")); assertThat(expr.removeUnusedPredicates("/*"), is("/*")); assertThat(expr.removeUnusedPredicates("/*[]"), is("/*[]")); assertThat(expr.removeUnusedPredicates("/*[3]"), is("/*[3]")); assertThat(expr.removeUnusedPredicates("/a/b[1][2][3]/c"), is("/a/b[1][2][3]/c")); }
@Test public void shouldRemoveUnusedPredicates() { assertThat(expr.removeUnusedPredicates("/a/b[-1]/c"), is("/a/b/c")); assertThat(expr.removeUnusedPredicates("/a/b[@name='wacky']/c"), is("/a/b/c")); assertThat(expr.removeUnusedPredicates("/a/b[3][@name='wacky']/c"), is("/a/b[3]/c")); assertThat(expr.removeUnusedPredicates("/a/b[3][@name]/c"), is("/a/b[3]/c")); assertThat(expr.removeUnusedPredicates("/a/b[length(@name)=3]/c"), is("/a/b/c")); }