### Question:
TrackedQueryManager { public PruneForest pruneOldQueries(CachePolicy cachePolicy) { List<TrackedQuery> prunable = getQueriesMatching(IS_QUERY_PRUNABLE_PREDICATE); long countToPrune = calculateCountToPrune(cachePolicy, prunable.size()); PruneForest forest = new PruneForest(); if (logger.logsDebug()) { logger.debug( "Pruning old queries. Prunable: " + prunable.size() + " Count to prune: " + countToPrune); } Collections.sort( prunable, new Comparator<TrackedQuery>() { @Override public int compare(TrackedQuery q1, TrackedQuery q2) { return Utilities.compareLongs(q1.lastUse, q2.lastUse); } }); for (int i = 0; i < countToPrune; i++) { TrackedQuery toPrune = prunable.get(i); forest = forest.prune(toPrune.querySpec.getPath()); removeTrackedQuery(toPrune.querySpec); } for (int i = (int) countToPrune; i < prunable.size(); i++) { TrackedQuery toKeep = prunable.get(i); forest = forest.keep(toKeep.querySpec.getPath()); } List<TrackedQuery> unprunable = getQueriesMatching(IS_QUERY_UNPRUNABLE_PREDICATE); if (logger.logsDebug()) { logger.debug("Unprunable queries: " + unprunable.size()); } for (TrackedQuery toKeep : unprunable) { forest = forest.keep(toKeep.querySpec.getPath()); } return forest; } TrackedQueryManager(
      PersistenceStorageEngine storageLayer, LogWrapper logger, Clock clock); TrackedQuery findTrackedQuery(QuerySpec query); void removeTrackedQuery(QuerySpec query); void setQueryActive(QuerySpec query); void setQueryInactive(QuerySpec query); void setQueryCompleteIfExists(QuerySpec query); void setQueriesComplete(Path path); boolean isQueryComplete(QuerySpec query); PruneForest pruneOldQueries(CachePolicy cachePolicy); Set<ChildKey> getKnownCompleteChildren(Path path); void ensureCompleteTrackedQuery(Path path); boolean hasActiveDefaultQuery(Path path); long countOfPrunableQueries();  }### Answer:
@Test public void pruneOldQueries() { TestClock clock = new TestClock(); TrackedQueryManager manager = newManager(null, clock); manager.setQueryActive(defaultQueryAt("active1")); manager.setQueryActive(defaultQueryAt("active2")); manager.setQueryActive(defaultQueryAt("inactive1")); manager.setQueryInactive(defaultQueryAt("inactive1")); clock.tick(); manager.setQueryActive(defaultQueryAt("inactive2")); manager.setQueryInactive(defaultQueryAt("inactive2")); clock.tick(); manager.setQueryActive(defaultQueryAt("inactive3")); manager.setQueryInactive(defaultQueryAt("inactive3")); clock.tick(); manager.setQueryActive(defaultQueryAt("inactive4")); manager.setQueryInactive(defaultQueryAt("inactive4")); PruneForest forest = manager.pruneOldQueries(new TestCachePolicy(0.5f, Long.MAX_VALUE)); PruneForest expected = new PruneForest() .prune(path("inactive1")) .prune(path("inactive2")) .keep(path("active1")) .keep(path("active2")) .keep(path("inactive3")) .keep(path("inactive4")); assertEquals(expected, forest); forest = manager.pruneOldQueries(new TestCachePolicy(1.0f, Long.MAX_VALUE)); expected = new PruneForest() .prune(path("inactive3")) .prune(path("inactive4")) .keep(path("active1")) .keep(path("active2")); assertEquals(expected, forest); forest = manager.pruneOldQueries(new TestCachePolicy(1.0f, Long.MAX_VALUE)); assertFalse(forest.prunesAnything()); manager.verifyCache(); }